26

What can i put into \setmathfont{<...>.otf} for the unicode-math package to make it all work (with XeLaTeX or LuaLaTeX)?

There are several suggestions on the GitHub page of unicode-math, but the first option is commercial, and the second and the third do not work with the following example:

% !TEX TS-program = xelatex

\documentclass{article}
\usepackage{unicode-math}
\setmathfont{latinmodern-math.otf}
% \setmathfont{texgyrepagella-math.otf}
% \setmathfont{xits-math.otf}

\begin{document}
$X\setminus Y$
\end{document}

I do not get the \setminus character in the output.

The \setminus character is also missing if i do not set a math font at all (i do not know which font is used in this case). It works with xits-math, but i do not like it.

Is it expected by the way that the \setminus character is left blank without giving any warning?

9
  • 3
    You get a warning in the log file, not on the terminal. With xelatex on your document as posted I get: Missing character: There is no ⧵ in font [latinmodern-math.otf]/ICU:script=math ;language=DFLT;! Commented Oct 23, 2013 at 15:33
  • Thanks for the explanation. I am still wondering if i can find a usual-looking font with all common math characters, or if i should change back to amssymb.
    – Alexey
    Commented Oct 23, 2013 at 15:47
  • 1
    I had forgotten, but turns out I made a bug report to the font creators, about exactly one year ago, via an email to Boguslaw Jackowski with title \setminus symbol does not show in pdf (Termes, Pagella, Latin Modern). Perhaps a second attempt should be done?
    – user4686
    Commented Oct 23, 2013 at 22:00
  • At least for LuaTeX with fontspec, it seems that an Open Type font is deemed to be a "math" font if it has the ssty feature. Whether or not it has the characters you need, is another story.
    – user103221
    Commented Dec 14, 2016 at 20:17
  • Your title sounds like a duplicate of “Which OpenType Math Fonts are Available?”, but the answers are all about a separate issue you raise in your last paragraph: the missing \setminus in Latin Modern Math. Should I edit to match the very useful answers?
    – Davislor
    Commented Jan 10, 2020 at 19:24

7 Answers 7

2

The issue has now been fixed, about twelve years later: https://github.com/wspr/unicode-math/issues/181#issuecomment-1675944769

My solution to this issue is going to be exactly that -- use "2216 for \setminus, fake \smallsetminus, and anyone who needs something different can use some one-line redefinitions (such as \renewcommand\setminus{\reversesolidus} ).

With the latest unicode-math, the command \setminus works normally.

25

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}

enter image description here

A different possibility is to use \backslash made into a binary operator:

$X \mathbin{\backslash} Y$

that gives

enter image description here

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}
10
  • 3
    sorry I did make a bug report to Boguslaw Jackowski on October 27, 2012.
    – user4686
    Commented Oct 23, 2013 at 21:58
  • 1
    unicode-math offers an option to specify the slash provided by the font. For example, on page 14, the manual explains how to get slashes with Cambria even though it does not provide all of those specified by unicode. Just before that, it lists the different versions of backward slashes. Yet there seems to be no similar option for telling unicode-math what the font provides in this case. If filing bugs on the fonts is proving unproductive, maybe it would be worth a feature request to whoever maintains unicode-math?
    – cfr
    Commented Mar 25, 2014 at 0:35
  • 1
    @egreg Perhaps this is an area where unicode-math could offer (or provide an interface) to substitute one slash with another. Commented Jul 1, 2014 at 0:46
  • 2
    @Socowi \AtBeginDocument{\renewcommand{\setminus}{...}}
    – egreg
    Commented Jun 5, 2018 at 11:17
  • 1
    @Socowi I guess that five years ago this wasn't necessary; I took the occasion for improving my answer, thanks.
    – egreg
    Commented Jun 5, 2018 at 11:22
10

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;!
2
  • I have notice this, but it looks like a rather incompatible replacement for amssymb with the regular font. Is there no way to make it look like the usual font with unicode-math?
    – Alexey
    Commented Oct 23, 2013 at 16:22
  • @Alexey well in principle youjust... need to pull the amsfonts together and re-encode them into a big otf font in Unicode order, I assume that's the way latin-modern is headed but I do not know the details of any work in that area. Commented Oct 23, 2013 at 16:34
6

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.

9
  • This is bug in the mentioned unicode-math documentation and in unicode-math code. The symbol U+2216 has its name "Set Minus Unicode Character". This is \setminus, no small set minus. And the character U+29F5 has its name "Reverse Solidus Operator" (as you mentioned), no \setminus.
    – wipet
    Commented Jun 4, 2020 at 6:16
  • @wipet It’s a design decision that you don’t like. It’s correct, according to the official spec, and has been documented behavior for years. It is not possible to change without breaking compatibility. A better word might be “misfeature.”
    – Davislor
    Commented Jun 4, 2020 at 6:22
  • The Unicode table (which is much more official) were specified many years before unicode-math spec. This is only bug when reading Unicode table spec. And I like this design decision of unicode-math because this makes problems only to LaTeX users. If they don't use LaTeX (like me) then they don't have problem. :)
    – wipet
    Commented Jun 4, 2020 at 6:32
  • The font designers read Unicode table spec., not the unicode-math LaTeX package spec. From this point of view the unicode-math is not :official: spec.
    – wipet
    Commented Jun 4, 2020 at 6:34
  • 1
    Minority report here. \setminus is in plain.tex, Knuth's original, and reuses the backslash (space considerations). When the smaller, differently sloped form was requested, it was included in the amsfonts under the name \smallsetminus in amssymb. That is the history that unicode-math and stix followed, The Unicode assignment and name were a compromise, and that is what Microsoft/Cambria adopted. I favor keeping to the TeX tradition, but I'm biased. Commented Jun 4, 2020 at 15:31
2

A possible workaround for this issue (which still exists 6 years later) is to use \smallsetminus as a replacement.

% !TEX TS-program = xelatex

\documentclass{article}
\usepackage{unicode-math}
\setmathfont{latinmodern-math.otf}
% \setmathfont{texgyrepagella-math.otf}
% \setmathfont{xits-math.otf}

\begin{document}
$X\smallsetminus Y$
\end{document}

gives:

X \ Y

If you are lazy, you can even add at the end of your preamble:

\AtBeginDocument{
\renewcommand{\setminus}{\smallsetminus}
}
2
  • Oops, I just realized that this answer was given here as well.
    – Clément
    Commented Nov 21, 2019 at 19:41
  • Six years? There’s an open bug report from 2011. Nine years ago, as I write.
    – Davislor
    Commented Jan 11, 2020 at 0:48
2

As an alternative to the other solutions mentioned here, you could also directly use the Unicode character ∖ for "set minus" in your tex file. (Hopefully your editor uses a font that has a glyph for it like mine.) For me it works with both TeX Gyre Termes and TeX Gyre Pagella.

1

load all traditional math stuff before unicode-math

\documentclass{article}
\usepackage{amssymb}
\usepackage{unicode-math}
\setmathfont{XITSMath}

\begin{document}
$X\setminus Y$
\end{document}
6
  • I get fontspec error: "font-not-found" at \setmathfont{XITSMath}. What should i install?
    – Alexey
    Commented Oct 23, 2013 at 21:44
  • In any case, doing \usepackage{amssymb} before \usepackage{unicode-math} does not help.
    – Alexey
    Commented Oct 23, 2013 at 21:48
  • @Alexey Why should it help? In amssymb there's no mention of \setminus and unicode-math redefines it to choose U+29F5 REVERSE SOLIDUS OPERATOR.
    – egreg
    Commented Oct 23, 2013 at 21:58
  • ok, so this answer was not about getting \setminus back.
    – Alexey
    Commented Oct 23, 2013 at 22:27
  • 1
    @Alexey: no, only \smallsetminus is defined by all math otf fonts. And \setminus only by XITS, Asana, and Cambria. However, the otf math font should be loaded after the other "traditional" math stuff. That's what my example shows.
    – user2478
    Commented Oct 24, 2013 at 12:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .