Which Unicode math fonts support \setminus?
It's quite strange that the symbol is missing in Latin Modern Math, TeX Gyre Termes Math and TeX Gyre Pagella and it's probably worth a bug report.
You can supplement single symbols with the range
option to \setmathfont
:
\documentclass{article}
\usepackage{unicode-math}
%\setmathfont{Latin Modern Math} % default
\setmathfont[range=\setminus]{Asana Math}
\begin{document}
$X\setminus Y$
\end{document}
A different possibility is to use \backslash
made into a binary operator:
$X \mathbin{\backslash} Y$
that gives
In this case
\renewcommand{\setminus}{\mathbin{\backslash}}
would make \setminus
doing what's expected. However, the redefinition must be issued at begin document, because unicode-math
prepares its internal math symbol tables at that moment.
\documentclass{article}
\usepackage{unicode-math}
%\setmathfont{Latin Modern Math} % default
\AtBeginDocument{% to do this after unicode-math has done its work
\renewcommand{\setminus}{\mathbin{\backslash}}%
}
\begin{document}
$X\setminus Y$
\end{document}
It works with
\setmathfont{Asana-Math.otf}
or as noted in the question, with
\setmathfont{xits-math.otf}
as mentioned in comments, if it doesn't work you get a warning in the log, eg with latinmodern:
Missing character: There is no ⧵ in font [latinmodern-math.otf]/ICU:script=math ;language=DFLT;!
According to the documentation of unicode-math
, \setminus
is the character U+29F5 (⧵), the Unicode reverse solidus operator. Asana Math, STIX Two Math, XITS Math, Libertinus Math and Cambria Math all have it, at least. I believe that Latin Modern, the TeX Gyre fonts and Fira Math do not (as of 2020). Generally, XITS and STIX Two attempt to be absolutely comprehensive. ETA: New Computer Modern is a replacement for Latin Modern that does.
The very similar Unicode set minus symbol, U+2216 (∖), is much more widely supported. This is called \smallsetminus
in unicode-math
, and in some fonts has a less vertical slant than the traditional LaTeX \setminus
. As of 2020, Latin Modern and all the TeX Gyre fonts have it.
There is an an open bug report about this from 2011 on the unicode-math
tracker, which didn’t result in any consensus on how to resolve the issue. So nothing was ever done, although that doesn’t let GUST off the hook for never updating Latin Modern and the TeX Gyre fonts. The root of the problem was that Microsoft and STIX mapped the Unicode code points differently, and the developers decided not to add a package option for backward slashes like they did for forward slashes. They might also have expected GUST to fix the issue with their fonts sometime that decade.
ETA
Some other solutions no one has yet posted:
Load a math font that contains \setminus
. That is, nearly all of them other than the default! Search this document for \setminus
and you will get half a dozen font specimens.
If you still want to use Latin Modern math for everything else, you can load just this one symbol with:
\setmathfont{Latin Modern Math}
\setmathfont[range=`\setminus, Scale=MatchUppercase]{STIX Two Math}
You can use \smallsetminus
in your source, or redefine \setminus
as:
\AtBeginDocument{\renewcommand\setminus{\smallsetminus}}
The \AtBeginDocument
wrapper is necessary because unicode-math
, for compatibility with other packages, defers most of its definitions until after the preamble.
If you wanted to save the definition from a legacy package such as amssymb
, unicode-math
will overwrite its definition of setminus
even if you include the package afterward. The way to use a legacy definition of a command is to load the legacy package first, save the definition you want with letltxmacro
(in case it’s a robust macro), load unicode-math
, and then restore the saved definition with \AtBeginDocument
.
I would strongly recommend against pasting a backward slash into your source, as there are at least four different backslashes in Unicode and most editors make it impossible to tell them apart. If you do need to insert a specific Unicode codepoint in your source, I would recommend writing it out as, e.g.:
\usepackage{newunicodechar}
\newunicodechar{^^^^29f5}{\smallsetminus} % Remap U+29F5 SET MINUS in the source to U+2216.
which you might conceivably do as a workaround for a document that uses literal ⧵ characters in the source, as at least one other answer has suggested.