I'm looking for the symbol that's similar to \cdot in math mode, but instead of a small circle, it's a square. Like this:
7 Answers
There are several ways for doing this. One idea could be \centerdot
from amssymb
, but this has the defect of sitting on the baseline, despite its name.
One can fix this by observing that the apparent height of the glyph is three times the real height. So smashing the height to one third and using \vcenter
will raise the symbol up to the formula axis.
\documentclass{article}
\usepackage{amssymb}
\makeatletter
\DeclareRobustCommand{\sqcdot}{\mathbin{\mathpalette\morphic@sqcdot\relax}}
\newcommand{\morphic@sqcdot}[2]{%
\sbox\z@{$\m@th#1\centerdot$}%
\ht\z@=.33333\ht\z@
\vcenter{\box\z@}%
}
\makeatother
\begin{document}
$\bar{f} \sqcdot f\simeq c_{a\sqcdot b}$
\end{document}
Second way: import \sqbullet
from the mathabx
fonts.
\documentclass{article}
\DeclareFontFamily{U}{mathb}{}
\DeclareFontShape{U}{mathb}{m}{n}{
<-5.5> mathb5
<5.5-6.5> mathb6
<6.5-7.5> mathb7
<7.5-8.5> mathb8
<8.5-9.5> mathb9
<9.5-11.5> mathb10
<11.5-> mathb12
}{}
\DeclareSymbolFont{mathb}{U}{mathb}{m}{n}
\DeclareMathSymbol{\sqcdot}{\mathbin}{mathb}{"0D}% name to be checked
\begin{document}
$\bar{f} \sqcdot f\simeq c_{a\sqcdot b}$
\end{document}
One could avoid wasting a symbol font with the help of \text
:
\documentclass{article}
\usepackage{amsmath}
\DeclareFontFamily{U}{mathb}{}
\DeclareFontShape{U}{mathb}{m}{n}{
<-5.5> mathb5
<5.5-6.5> mathb6
<6.5-7.5> mathb7
<7.5-8.5> mathb8
<8.5-9.5> mathb9
<9.5-11.5> mathb10
<11.5-> mathbb12
}{}
\DeclareRobustCommand{\sqcdot}{%
\mathbin{\text{\usefont{U}{mathb}{m}{n}\symbol{"0D}}}%
}
\begin{document}
$\bar{f} \sqcdot f\simeq c_{a\sqcdot b}$
\end{document}
Both examples typeset the same
For using the glyph in the MnSymbol font, it is similar:
\documentclass{article}
\usepackage{amsmath}
\DeclareFontFamily{U}{MnSymbolC}{}
\DeclareFontShape{U}{MnSymbolC}{m}{n}{
<-5.5> MnSymbolC5
<5.5-6.5> MnSymbolC6
<6.5-7.5> MnSymbolC7
<7.5-8.5> MnSymbolC8
<8.5-9.5> MnSymbolC9
<9.5-11.5> MnSymbolC10
<11.5-> MnSymbolCb12
}{}
\DeclareRobustCommand{\sqcdot}{%
\mathbin{\text{\usefont{U}{MnSymbolC}{m}{n}\symbol{"69}}}%
}
\begin{document}
$\bar{f} \sqcdot f\simeq c_{a\sqcdot b}$
\end{document}
Take your pick.
-
Great answer, thanks. You may want to check the name
mathbb12
... I eventually ran into compile errors, which I resolved by changing it tomathb12
(only oneb
).– 808soundMay 3, 2017 at 2:57 -
1
-
2@egreg +1. Many compliments for your jobs. The screenshots are fantastics. May 3, 2017 at 7:21
-
@Sebastiano The screenshots should be credited to the Retina display.
;-)
– egregMay 3, 2017 at 7:23 -
Great answer! Is there a simple way to modify it for an unfilled square rather than a filled square? Simply using
\square
is not good enough, since I need the square to be the same size as\bullet
and\textopenbullet
, whereas\square
is too big.– Evan AadNov 12, 2018 at 10:38
Handcraft it.
\documentclass{scrartcl}
\newcommand*\sq{\mathbin{\vcenter{\hbox{\rule{.3ex}{.3ex}}}}}
\begin{document}
$f$ by $\bar f$ gives $\bar f \sq f \simeq c$ for $c$ the constant\dots
\end{document}
-
1Is it the case that this does not automatically handle different math styles (e.g.,
\scriptstyle
, etc.)? Oct 15, 2015 at 2:32 -
1It looks good for me in different styles, but you could, as always, develop some
\mathpalette\sqaux\relax
then\if\scriptstyle#1.2ex\else\if\scriptscriptstyle#1.15ex\else.3ex\fi\fi
(or whatever dimensions you choose) in place of the dimensions of\rule
.– ManuelOct 15, 2015 at 7:24
Here, I use a \scalerel*
to make a strutted rule scale to the size of \cdot
. scalerel
package macros work in all math styles automatically (unless disabled).
\documentclass{article}
\usepackage{scalerel}
\def\sq{\mathbin{\scalerel*{\strut\rule{1ex}{1ex}}{\cdot}}}
\begin{document}
$f$ by $\bar f$ gives $\bar f \sq f \simeq c$ for $c$ the constant\dots\par
$\scriptscriptstyle\bar f \sq f \simeq c$
\end{document}
Changing the size/vertical position of the \rule
allows any size/position of box to be made. Here, I double the size of the square dot by using \rule[-.5ex]{2ex}{2ex}
.
\documentclass{article}
\usepackage{scalerel}
\def\sq{\mathbin{\scalerel*{\strut\rule[-.5ex]{2ex}{2ex}}{\cdot}}}
\begin{document}
$f$ by $\bar f$ gives $\bar f \sq f \simeq c$ for $c$ the constant\dots\par
$\scriptscriptstyle\bar f \sq f \simeq c$
\end{document}
-
Is there a simple way to modify your answer to obtain an unfilled square rather than a filled square?– Evan AadNov 12, 2018 at 10:40
-
1@EvanAad You could adapt this answer, tex.stackexchange.com/questions/459167/…, except changing the scale from that of
\Delta
to instead the scale of\cdot
. Nov 12, 2018 at 13:13
\sqbullet
from mathabx
perhaps?
\documentclass{article}
\usepackage{mathabx}
\begin{document}
$f \sqbullet f$
\end{document}
-
3
-
1@egreg: Is
\filledsquare
fromMnSymbol
better?– user31729Oct 14, 2015 at 20:38 -
1No: while
mathabx
symbols somewhat match CM ones, those in MnSymbol are very distinct from them. There's a canonical answer about “importing a single symbol”, though.– egregOct 14, 2015 at 20:39
Use \amssymb
package and \centerdot
.
\documentclass{article}
\usepackage{amssymb}
\begin{document}
$\bar{f} \centerdot f\simeq c$
\end{document}
-
Unfortunately it sits on the baseline, rather than be vertically centered to the formula axis.– egregOct 14, 2015 at 20:48
-
@egreg,
\mathord{\raisebox{1pt}{$\centerdot$}}
is useful?– user31034Oct 14, 2015 at 20:59 -
3
You can use direct \vrule
with \mathchoice
TeX primitive.
\newcount\stylenum \newdimen\styledim
\def\varstyle#1{\mathchoice{\stylenum=0 #1}{\stylenum=1 #1}{\stylenum=2 #1}{\stylenum=3 #1}}
\def\mathaxis{\fontdimen22\ifcase\stylenum
\textfont\or\textfont\or\scriptfont\or\scriptscriptfont\fi2 }
\def\setstyledim{\styledim=\ifcase\stylenum .1em\or.1em\or.07em\or.05em\fi\relax}
\def\sqdot{\mathbin{\varstyle{\raise\mathaxis\hbox{\setstyledim
\kern\styledim
\vrule width1.2\styledim height.6\styledim depth.6\styledim
\kern\styledim}}}}
$f\sqdot g, f\cdot g, \scriptstyle f\sqdot g, f\cdot g$
\bye
Unicode-math fonts typically include the character \smblksquare
. If you have loaded such font then you can type:
$a\mathbin\smblksquare b$
or define
\def\smallsquare{\mathbin\smblksquare}
The result (when latinmodern-math.otf
is loaded) looks like this:
\sqbullet
frommathabx
using Importing a single symbol from a different font.