13

When compiling the following piece of LaTeX code, the ∖ symbol does not show up.

\documentclass{article}
\usepackage{unicode-math}
\setmainfont{Latin Modern Roman}
\setmathfont{Latin Modern Math}
\begin{document}
This will not show: $\setminus$ \\
This will show: $\smallsetminus$
\end{document}

I know why this happens: \setminus translates to unicode character 0x29F5, and this character is not part of Latin Modern Math. What I would like to do is to use Unicode character for \smallsetminus, 0x2216, instead. So what I am really looking for is a way to remap the \smallsetminus command to another Unicode value than the one defined by the unicode-math package. I know a possible way to get a value for \setminus would be to use another math font that does have Unicode character 0x29F5. Adding the line

\setmathfont[range={"29F5}]{XITS Math}

gives me a ∖ symbol, but I don’t want to use another font for this character.

David Carlisle
  • 757,742
Semafoor
  • 866
  • Any reason y9ou can't just say \def\setminus{\symbol{2216}} or renewcommand{\setminus}{\symbol{2216}}? – dgoodmaniii Nov 21 '19 at 22:36
  • The solution is in Caramdir's answer. unicode-math defines its commands only at \begin{document}, so any \def or \let statements before \begin{document} are overwritten (which is why the accepted solution is to wrap the \let in \AtBeginDocument) – Semafoor Nov 21 '19 at 23:54
  • Makes sense! Glad you found a solution. – dgoodmaniii Nov 22 '19 at 11:30

1 Answers1

12

The following makes \setminus equivalent to \smallsetminus:

\documentclass{article}  
\usepackage{unicode-math}
\setmathfont{Latin Modern Math}

\AtBeginDocument{\let\setminus\smallsetminus}

\begin{document}
  \[ A \setminus B \qquad A \smallsetminus B \]
\end{document}

The \AtBeginDocument is necessary because unicode-math defines its commands only at \begin{document}. So a simple \let\setminus\smallsetminus in the preamble would get overwritten. Alternatively, you could put \let\setminus\smallsetminus after \begin{document}, but this is a less “clean” solution as it violates the separation of content and styling.

If you want to use a completely different symbol, you can do something like

\AtBeginDocument{\def\setminus{-}}

instead.

Caramdir
  • 89,023
  • 26
  • 255
  • 291
  • Thanks! This works perfectly. I already tried \let\setminus\smallsetminus, but I didn't know that it was overwritten. – Semafoor May 10 '12 at 02:48
  • 1
    Thanks! And, it's a shame that this workaround is still needed in Nov '19 ... – am70 Nov 21 '19 at 09:01