TransWikia.com

Which Unicode math fonts support setminus?

TeX - LaTeX Asked on January 6, 2021

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}
$Xsetminus 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?

6 Answers

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}
$Xsetminus 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}
$Xsetminus Y$
end{document}

Correct answer by egreg on January 6, 2021

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;!

Answered by David Carlisle on January 6, 2021

load all traditional math stuff before unicode-math

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

begin{document}
$Xsetminus Y$
end{document}

Answered by user2478 on January 6, 2021

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}
$Xsmallsetminus Y$
end{document}

gives:

X  Y

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

AtBeginDocument{
renewcommand{setminus}{smallsetminus}
}

Answered by Clément on January 6, 2021

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.

Answered by balu on January 6, 2021

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{renewcommandsetminus{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.

Answered by Davislor on January 6, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP