I redefined the \boxplus and \boxminus commands. But for some reasons, the + sign inside the \boxplus is too large while the - sign in the \boxminus has he correct size. How should I modify the macros to have the two symbols of the right size?

Note that I am also using \boxdot in my document and the box for \boxdot is smaller than that of \boxplus.

enter image description here





$a \boxplus b$  % incorrect size

$a \boxminus b$ % correct size

  • 1
    Off topic: why don't you just use \scalebox on normal \boxplus and \boxminus? – user156344 Mar 31 '19 at 8:04
  • What's the reason for the redefinition? As far as I can see, stmaryrd's \boxplus has the same dimensions as +. – egreg Mar 31 '19 at 12:46
  • I am also using \boxdot in my document and the box for \boxdot is smaller than that of \boxplus. (The box used for \boxdot appears to be the same as \boxempty.) – user94293 Mar 31 '19 at 13:27
  • @user94293 -- you should add that reason to the question. – barbara beeton Mar 31 '19 at 14:06
  • 1
    amssymb has all three, \boxplus, \boxminus, and \boxdot, and all three should be the same size, so no scaling should be necessary. – barbara beeton May 21 at 5:00

The problem is that the plus sign overshoots the minus sign, while both have the same width, as far as TeX is concerned. The \boxempty symbol of stmaryrd has the same width as both.

You can work around the issue by using a slightly smaller plus, raised by a small amount so it still sits well with respect to the formula axis.

enter image description here

The gray line in the picture shows the formula axis (xcolor is used just for this). The final line shows the overshooting.




$a\boxplus b\boxminus c$

$\scriptstyle a\boxplus b\boxminus c$

$\scriptscriptstyle a\boxplus b\boxminus c$



On the other hand, you could more simply use the symbols provided by amssymb, which is essentially the same, but simpler, than wipet's answer.

enter image description here






$a\boxplus b\boxminus c$

| improve this answer | |

As I said in my comment, you have fallen into two bugs caused by someone else. First bug is in CM fonts, where the minus shape from cmsy10 is smaller than plus shape from cmr10. Second bug is in AMS fonts, where the symbols boxplus, boxminus from msam10 are not centered to math axis. If you use another math fonts (for example Unicode Latin Modern Math) then both bugs are corrected.

If you insist to use these fonts then you can do following:

\mathchardef\xboxplus=\numexpr \boxplus-"2000\relax
\mathchardef\xboxminus=\numexpr \boxminus-"2000\relax

test: $a + b \boxplus c \boxminus d$

I subtract "2000 from mathcode of \boxplus and \boxminus in order to get math Ord charcter (they are declared as math Bin). I need to do this conversion in order to use these characters in the context \mathop{Ord} which does centering to math axis (appendix G od TeXbook, paragraph 13). Finally, I re-define \boxplus and \boxminus as math Bin object.

The subtraction is necessary as shown from the following code and from the picture with the result.

\mathchardef\xboxplus=\numexpr \boxplus-"2000\relax

$a + b \boxplusWipet c \boxplusEgreg d$


| improve this answer | |
  • The subtraction is not necessary. – egreg May 21 at 10:44
  • @egreg Substraction is necessery as shown in my actual version of the answer. Or, I didn't understand something. – wipet May 21 at 11:58
  • Thank you @wipet! Or equivalently, \renewcommand*{\boxplus}{\mathbin{\mathop{\mathchar"0401}}} – user94293 May 21 at 12:33
  • @wipet Your error is in the braces: it should be \mathbin{\mathop\xboxplus}}, which doesn't create a subformula. See the last part of my answer. – egreg May 21 at 12:41
  • Or equivalently, \renewcommand*{\boxplus}{\mathbin{\mathop\mathchar"2401}} – user94293 May 21 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.