2

I've defined a \boxstar command as follows:

\newcommand{\boxstar}{\mathrlap{\boxplus}\boxtimes}

This looks quite nice on its own.

enter image description here

However, when I have a line of boxstars and other symbols, the boxstars stop overlapping properly.

$$\boxstar \boxstar \boxtimes \boxtimes \boxtimes \boxtimes \boxtimes $$

enter image description here

What's going on here?

(Using amssymb and mathtools.)

  • Welcome to TeX.SX! Could you show us some minimal working example (MWE), starting with \documentclass and ending with \end{document}. – Bobyandbob Aug 26 '18 at 5:44
2

Never use $$ in LaTeX

When you do \boxstar \boxstar \boxtimes \boxtimes you have the following sequence of atoms, due to the fact that your \boxstar is composed by an ordinary symbol (O) followed by a binary operation (B):

O (m) B (m) O (m) B (m) B (0) B

TeX will insert a medium space (m) where indicated, but zero space between the two last B's, because they are incompatible with binary operations, so they're treated as O.

How do you solve the issue? By stating how the new symbol should behave and using braces around \boxtimes so it effectively becomes an ordinary symbol:

\newcommand{\boxstar}{\mathbin{\mathrlap{\boxplus}{\boxtimes}}}

The braces are not really needed here, because a subformula consisting of OB will become OO (by the same rules mentioned above), but is conceptually better to have them.

This works because \boxplus and \boxtimes have the same width. In order to superimpose symbols with different widths, the simplest method is to exploit \ooalign, see https://tex.stackexchange.com/a/22375/4427 for a quick course on it.

Your example

\[
\boxstar \boxstar \boxtimes \boxtimes \boxtimes \boxtimes \boxtimes
\]

will now become

B B B B B B B

that's transformed into

O (m) B (m) O (m) B (m) O (m) B (m) O

because of incompatible BB sequences.

3

You have to group the two symbols together. Here I do this using \mathbin to indicate to TeX, that \boxstar is a binary operator. If you fail to do this, the spacing around \boxtimes is influenced by the symbol following after it which makes the \boxplus go off center.

\documentclass{article}
\usepackage{mathtools}
\usepackage{amssymb}
\newcommand{\boxstar}{\mathbin{\mathrlap{\boxplus}\boxtimes}}
\begin{document}
\[ \boxstar \boxstar \boxtimes \boxtimes \boxtimes \boxtimes \boxtimes \]
\end{document}

enter image description here

I recommend to overlay symbols using \ooalign, because this overlays them with respect to the center (\mathrlap overlay with respect to the left boundary).

\documentclass{article}
\usepackage{mathtools}
\usepackage{amssymb}
\makeatletter
\newcommand*\boxstar{\mathpalette\@boxstar\relax}
\newcommand*\@boxstar[2]{%
  \mathbin{%
    \ooalign{%
      $\m@th#1\boxplus$\cr
      \hidewidth$\m@th#1\boxtimes$\hidewidth\cr
    }%
  }%
}
\makeatother

\begin{document}
\[ \boxstar \boxstar \boxtimes \boxtimes \boxtimes \boxtimes \boxtimes \]
\end{document}
  • Thank you! This is much appreciated. But your \ooalign example is quite beyond me: could you explain briefly what the parameter is for, why you go in and out of math mode, etc? – Draconis Aug 26 '18 at 4:14
  • @Draconis I use \mathpalette to forward the surrounding mathstyle into \ooalign (that is #1), the second parameter is just \relax and therefore unused. I have to reenter math mode inside the \ooalign because it actually a text mode macro. – Henri Menke Aug 26 '18 at 4:32

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.