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?
2 Answers
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}
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.
-
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.) Jul 18, 2020 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. Jul 18, 2020 at 20:30
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.
-
The problem with
\caption
should vanish if you use\DeclareRobustCommand
instead of\newcommand
.– campaJul 16, 2020 at 14:56
amssymb
rather thanamsmath
. Is your question basically "how to get\boxdiag
in a standard CM setup"?