4

I've got a greek keyboard and enjoy typing the greek letters directly into the mathmode using the unicode-math package. Yet, unfortunately it seems as though there is at least one symbol that does not survive the inclusion of said package, and this symbol is \setminus; it just disappears whenever said package is being included.

I'm using XeLaTeX in order to compile my document.

EDIT: As requested by the commenter:

\documentclass[10pt,a4paper]{article}

\usepackage{amssymb}

\usepackage{fontspec}
\usepackage{xunicode}
\usepackage{polyglossia}
\usepackage{xecyr}
\usepackage{unicode-math}

\setdefaultlanguage{english}

\setmainfont{GentiumPlus}

\usepackage{amsmath}
\usepackage{amsfonts}
\title{Error demonstration}



\begin{document}
\begin{equation*}
A \setminus B
\end{equation*}
\end{document}
Vincent
  • 20,157
  • 1
    look in the log for "missing character" messages. But also please always post a complete small document that shows the problem so people can debug it and test answers. – David Carlisle Jun 02 '20 at 18:48
  • 2
    a search for unicode-math and setminus gives quite a number of hits, e.g. https://tex.stackexchange.com/questions/140279/which-unicode-math-fonts-support-setminus – Ulrike Fischer Jun 02 '20 at 19:04
  • @UlrikeFischer I'll try the search next time; I'm used to Google giving me the desired results, but my proxy seems to have the habit of viewing only one result per website, whence the question. Unfortunately, the link that you provided was not displayed by the "similar questions" field when I wrote the question. It is, however, nice to see that you do have an inclination to selflessly help me. This is greatly appreciated. – AlgebraicsAnonymous Jun 03 '20 at 10:37
  • By the way, this is hardly a duplicate question, because I did not know that the mistake was with the font, as the correct answer pointed out. But I do see that I messed with the wrong people. Sorry about that. – AlgebraicsAnonymous Jun 03 '20 at 10:40

2 Answers2

3

The error you’re getting is completely unrelated to the Greek language. It’s a font issue. The default math font, Latin Modern Math, does not have a \setminus symbol. The default behavior of TeX is to silently log a warning message to the .log file.

You can at least get it to print a warning message by adding the command \tracinglostchars=2. You should seriously consider doing this all the time. That tells you what’s wrong:

 Missing character: There is no ⧵ (U+29F5) in font LatinModernMath:mode=base;script=math;language=dflt;!

There are several workarounds.

Load a Math Font that has U+29F5

\tracinglostchars=2 % Print a warning if a glyph is missing
\documentclass[10pt,a4paper]{article}

\usepackage{polyglossia}
\usepackage{unicode-math}

\setdefaultlanguage{english}

\defaultfontfeatures{Scale = MatchLowercase}
\setmainfont{GentiumPlus}[Scale = 1.0]
\setmathfont{Libertinus Math}

\begin{document}
\begin{equation*}
A \setminus B
\end{equation*}
\end{document}

Gentium+Libertinus Math sample

If you would rather use the default symbols for everything else, you can load just that one symbol with:

\setmathfont{Latin Modern Math} % Or your math font of choice.
\setmathfont[range=\setminus]{Libertinus Math}

Use a Different Symbol

Latin Modern Math does have \smallsetminus as an alias for U+2216, so you could replace \setminus with that. You could also redeclare \setminus as \smallsetminus:

\tracinglostchars=2 % Print a warning if a glyph is missing
\documentclass[10pt,a4paper]{article}

\usepackage{polyglossia}
\usepackage{unicode-math}

\setdefaultlanguage{english}

\AtBeginDocument{\renewcommand\setminus{\smallsetminus}}

\begin{document}
\begin{equation*}
A \setminus B
\end{equation*}
\end{document}

Latin Modern Math sample

You need to patch unicode-math symbol definitions \AtBeginDocument. It intentionally delays them until after it’s finished loading packages. Your MWE is a good example of why: if it did not do this, every document that loaded \amssymb after unicode-math would break.

Postscript

Although it’s totally unrelated to your issue, you’re copy-pasting several old packages into your template that are redundant or even harmful. Here is what I cleaned out:

  • The documentation for xecyr has said, “xecyr is not needed anymore,” since 2010.
  • The xunicode package is also obsolete.
  • The unicode-math package loads fontspec and amsmath for you. You only need to load either one manually if you need to change the loading order or options.
  • Legacy math packages such as amssymb and amsfonts are overridden by unicode-math.

If clearing these packages out creates any bugs, I’d like to know what you’re doing that needs them.

Why is this Happening?

Contrary to another answer, this is not a bug in unicode-math, but in the Latin Modern Math font. It’s following the reference implementation correctly. (Thanks to @egreg for the link to the discussion!)

The only reason an option to remap \setminus wasn’t added back in 2011, however, was that the designers assumed that GUST would fix their font before too long.

Davislor
  • 44,045
  • The \smallsetminus U+2572 is slightly different character BOX DRAWINGS LIGHT DIAGONAL UPPER LEFT TO LOWER RIGHT. The main problem is that LaTeX does not use U+2216 which is really math set minus. This is LaTeX bug. The character U+2216 is present in Latin Moderm Math. – wipet Jun 02 '20 at 20:21
  • The unicode-math package does define \smallsetminus as U+2216. See §5.5.7 of the manual. – Davislor Jun 02 '20 at 20:25
  • But U+2216 in not small set minus, it is normal minus declared in Unicode table. This shows the core problem. – wipet Jun 02 '20 at 20:43
  • Thank you so very much for your answers. It seems as though who is right on this issue is open to interpretation. LaTeX has a certain way of translating the command into unicode, and the font has a certain way of assigning characters to the unicode signs. Now the Latin Modern Math people would have the ability of fixing the issue by simply copying the backslash symbol onto the U+29F5 position. Similarly, the LaTeX people could fix it by translating the \setminus into the U+2216 symbol. Either way, as it is, I've just got to use a different font. @wipet – AlgebraicsAnonymous Jun 03 '20 at 10:49
  • Well, since the other maths fonts did not appeal to me, I went forward with renewing the command, ie. replacing it by the "smallsetminus" command. – AlgebraicsAnonymous Jun 03 '20 at 10:55
2

I tried to compare your LaTeX code with Unicode math. The \show\setminus says:

\setminus=\mathchar"226E.
or in math environment:
\setminus=the character ⧵.

It does not seems like Unicode math, so maybe this is a LaTeX bug. I compared the same in my OpTeX, which supports Unicode math too:

\fontfam[lmfonts]

test $A \setminus B$

\bye

The \setminus works. And the \show\setminus says:

\setminus=\Umathchar"2"01"002216.

It seems to be real Unicode math. IMHO your problem shows a LaTeX's Unicode math bug. Note that I commented out many LaTeX packages from your example: amsymbb, xunicode, xeyr, masmath, amsfonts and main font GentiumPlus. So only Latin Modern Math font is used. The LaTeX bug (non-Unicode \setminus) is still here.

Edit The problem is that unicode-math package for LaTeX declares \setminus as U+29F5 Reverse Solidus Operator Unicode Character but Latin Modern Unicode Math includes the character U+2216 Set Minus Unicode Character. The Latin Moderm Math sets the character at right position but LaTeX includes bug because it expects the character at non-math position.

wipet
  • 74,238