# Spacing after custom symbol varies

Situation: I defined a box with a line in it via

\DeclareMathOperator{\lbox}{\text{%
\tikz[baseline=-.6ex, rounded corners=.01ex]
{\draw (-.6ex,-.6ex) rectangle (.6ex,.6ex);
\draw (0,-.6ex) -- (0,.6ex);}}\kern-.2ex}


The symbol is contained in a \text-box so that it scales appropriately to sub- and superscripts. (I do not like the solution using \scalebox for scaling because it takes too long in large files. I could of course use \mathchoice, but that's a bit of extra work again.) I put a \kern-.2ex at the end so that it has the right distance to the next symbol: as is, the distance between the box and the phi $\lbox\phi$ is the same as in $\boxempty\phi$.

Problem: When lbox is followed by something in brackets, like $\lbox(\phi \wedge \psi)$, the spacing is incorrect: there is too little space between the box and the bracket. This is not the case when using $\boxempty(\phi \wedge \psi)$.

Question: How do I fix this? How can I ensure constant spacing after my lbox?

I guess that \boxempty is from stmaryrd. This symbol is defined as a binary operation symbol, so it behaves like + and -.

In the case of $-1$, no space is added between the symbols, but you would have spaces on either side of - in $a-b$. The same happens to \boxempty.

You're instead defining $\lbox$ as a math operator, which means that in $\lbox\varphi$ a thin space will be inserted between the symbols, but no such space is inserted in case you do $\lbox($ (the same behavior as for \sin).

So the comparison between \lbox and \boxempty is not correct: they're animals with different genera, not just species.

If you want to use \lbox in the same way as \nabla, then it should be an ordinary operator, because this is the typesetting tradition. And it should have some sidebearings (see the comparison between the bounding boxes in the picture).

\documentclass{article}
\usepackage{amsmath,tikz,stmaryrd}

\newcommand{\lbox}{%
\mspace{1.5mu}%
\text{%
\begin{tikzpicture}[baseline=-.6ex, rounded corners=.01ex]
\draw (-.6ex,-.6ex) rectangle (.6ex,.6ex);
\draw (0,-.6ex) -- (0,.6ex);
\end{tikzpicture}%
}%
\mspace{1.5mu}%
}

\begin{document}

\begingroup % compare the bounding boxes
\setlength\fboxsep{0pt}
\fcolorbox{red}{white}{$\lbox$}

\fcolorbox{red}{white}{$\boxempty$}
\endgroup

$\mathord{\boxempty}\varphi$

$\lbox\varphi$

$\lbox(\varphi)$

\end{document}


• That's very interesting! Would you say it's better to use \mspace compared to \hspace or \kern? Jun 1 at 1:26
• @MathStudent020 \mspace will automatically change size in sub/superscripts Jun 1 at 7:25