3

I have the following problem: I need some \boxdiag and \boxbslash symbols, but I'm still too much of a TeX n00b, so I have no idea what to do when packages clash. In this case, any package I tried that had a \boxdiag symbol in the end clashed with amsmath (?), \vec being found red-handed. Since I am a very sneaky n00b, I found a way to at least have a neat \boxbslash emulator: \mathrlap{\smallsetminus}\square. Note that \smallsetminus perfectly fits into \square. Which \diagup doesn't. So, I'm looking for \foobar with \foobar:\smallsetminus=\diagup:\diagdown. (Even tried \mathrlap{\angle}\square :-) Changing the font size of \diagup doesn't seem to work either inside \mathrlap (its a math environment). Or do you have another idea that doesn't involve mutually crosschecking 20 packages?

  • I would rather guess that font packages might have clashed with amssymb rather than amsmath. Is your question basically "how to get \boxdiag in a standard CM setup"? – campa Jun 18 at 13:40
  • a) you're probably right with the first, b) what's a CM? (me n00b, n00b ;-) - you're probably right with that too in any way) – Hauke Reddmann Jun 19 at 9:28
  • Sorry: CM stands for Computer Modern, the standard font used by (La)TeX. If you are using some other font packages you should provide a minimal working example with what you have tried so far. – campa Jun 19 at 9:40
2

Fits within the existing size of \square. Let the bowling commence!

\documentclass{article}
\usepackage{scalerel,amssymb,stackengine}
\DeclareRobustCommand\boxdiag{\boxslsh{1}}
\DeclareRobustCommand\boxbslash{\boxslsh{-1}}
\newcommand\boxslsh[1]{
\mathchoice{
  \ensurestackMath{\stackengine{0pt}{\square}
  {\stretchrel*[80]{\hstretch{#1}{/}}{\square}}{O}{c}{F}{T}{L}}
}{
  \ensurestackMath{\stackengine{0pt}{\square}
  {\stretchrel*[80]{\hstretch{#1}{/}}{\square}}{O}{c}{F}{T}{L}}
}{
  \ensurestackMath{\stackengine{0pt}{\scriptstyle\square}
  {\scriptstyle\stretchrel*[74]{\hstretch{#1}{/}}{\square}}{O}{c}{F}{T}{L}}
}{
  \ensurestackMath{\stackengine{0pt}{\scriptscriptstyle\square}
  {\scriptscriptstyle\stretchrel*[66]{\hstretch{#1}{/}}{\square}}{O}{c}{F}{T}{L}}
}}
\begin{document}
$\boxdiag\boxbslash$

$\scriptstyle\boxdiag\boxbslash$

$\scriptscriptstyle\boxdiag\boxbslash$
\end{document}

enter image description here

If your math font changes, the only tweak necessary are on those \stretchrel* optional arguments. For example, with txfonts loaded, the option should be [72] for all 4 math styles.

enter image description here

| improve this answer | |
  • Neat, although I even don't want to know what horror happens if I add those packages :-) (I "solved" the incorrect size when using as subscript by "tiny" before the symbol.) – Hauke Reddmann Jul 18 at 17:05
  • @HaukeReddmann Well, amssymb is so widely used as to be proofed against all evil. As to the other two packages, I wrote them, so if horrors happen, come blame me, and I'll see what can be done. – Steven B. Segletes Jul 18 at 20:30
3

By chance, I noticed that I already have the package graphicx loaded (without clashes), which means I can rotate a symbol. Thus the gruesome \rotatebox[origin=c]{90}{$\mathrlap{\smallsetminus}\square$} (which of course I meanwhile macro-ed with \newcommand) does the trick without any side effects, and looks nearly as perfect as the native box-with-diagonal symbols from the mentioned packages. Case closed :-)
EDIT: Or at least nearly. This hack can't be used inside a caption environment (throwing an incomplete \iffalse error, as it seems - still experimenting), and when used as index in math mode, utmost care must be taken of brackets and dollars in the right order.

| improve this answer | |
  • The problem with \caption should vanish if you use \DeclareRobustCommand instead of \newcommand. – campa Jul 16 at 14:56

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.