1

I am using unicode-math to select math fonts in XeLaTeX. From the documentation, I see there are four options for math-style:

  • ISO has all letters, Greek and Latin, italic
  • TeX has all letters italic except uppercase Greek, which are upright
  • french has all letters upright except lowercase latin, which are italic
  • upright has all letters upright

Would it be possible to set all Latin letters italic and all Greek letters upright?

The reason I need this setting is that I'm using Garamond-Math and I don't like the italic Greek letters of this font, so an alternative solution could be taking Greek letters from another font, but I haven't been able to do it. Here is my setting:

\usepackage[math-style=ISO,bold-style=ISO]{unicode-math}
\setmathfont{Garamond-Math.otf}[StylisticSet={5,7,9}]
\setmathfont{TeX Gyre Termes Math}[range=it/{Greek,greek}]
Massimo
  • 717
  • 4
  • 13
  • I can’t duplicate your bug. The \setmathfont example worked for me in LuaLaTeX on TeX Live 2020. – Davislor Feb 12 '21 at 02:57
  • A way to do it might be to load an upright font (such as Neo Euler) over range=it/{Greek,greek}, which forces you to use \mathit if you actually do want slanted Greek math letters. – Davislor Feb 12 '21 at 02:59
  • I tried this, but it didn't work. After some debugging, I realized this is because I also used the version=sansserif option for another math font, and this interacts badly with the range option. So, apparently, I cannot have both range and version in the same document. Too bad – Massimo Feb 12 '21 at 08:07
  • Unfortunately, that’s correct. There’s a warning buried in the unicode-math manual. You can, however, select a sans-serif math font without version= (Fira Math or KPMath-Sans`). – Davislor Feb 12 '21 at 08:57
  • Do you need to switch between serif and sans-serif math in the same document? In the same section of the document? – Davislor Feb 12 '21 at 08:58
  • Yes. I am preparing a book and figure/tables captions are in sans, so whenever I have a math symbol in the caption, it must be sans. I think this is quite a common situation. I haven't been able to select a second math font to be used only for sans, how can I do it? – Massimo Feb 12 '21 at 10:04
  • Use version= without range=. \setmathfont{KpMath-Regular.otf}\setmathfont[version=bold]{KpMath-Bold.otf}\setmathfont[version=sans]{KpMath-Sans.otf} – Davislor Feb 12 '21 at 19:12

3 Answers3

3

You can set the booleans mentioned by David in the document. Be aware that this are internal commands of unicode-math, so it would be good to make a feature request for an official interface:

\documentclass{article}

\usepackage{unicode-math} \ExplSyntaxOn \bool_gset_false:N \g__um_upGreek_bool %or true \bool_gset_true:N \g__um_upgreek_bool %or false \bool_gset_true:N \g__um_uplatin_bool %or false %more if needed ... \ExplSyntaxOff

\setmathfont{Garamond-Math.otf}[StylisticSet={5,7,9}]

\begin{document}

$a\alpha\Gamma$

\end{document}

enter image description here

Ulrike Fischer
  • 327,261
2

The options you mention just set boolean flags so it should be easy enough to add another option with a different combination

      {ISO} {
             \bool_gset_false:N \g__um_bfliteral_bool
             \bool_gset_false:N \g__um_bfupGreek_bool
             \bool_gset_false:N \g__um_bfupgreek_bool
             \bool_gset_false:N \g__um_bfupLatin_bool
             \bool_gset_false:N \g__um_bfuplatin_bool
            }
      {TeX} {
             \bool_gset_false:N \g__um_bfliteral_bool
             \bool_gset_true:N  \g__um_bfupGreek_bool
             \bool_gset_false:N \g__um_bfupgreek_bool
             \bool_gset_true:N  \g__um_bfupLatin_bool
             \bool_gset_true:N  \g__um_bfuplatin_bool
            }
  {upright} {
             \bool_gset_false:N \g__um_bfliteral_bool
             \bool_gset_true:N  \g__um_bfupGreek_bool
             \bool_gset_true:N  \g__um_bfupgreek_bool
             \bool_gset_true:N  \g__um_bfupLatin_bool
             \bool_gset_true:N  \g__um_bfuplatin_bool
            }
  {literal} {
             \bool_gset_true:N  \g__um_bfliteral_bool
            }
David Carlisle
  • 757,742
  • Thank you, and sorry if this further question sounds naive, but is it possible to add an option without modifying the .sty file? Or should I just add the new list of boolean flags in the preamble? – Massimo Feb 11 '21 at 23:47
  • 1
    probably but not tonight, really I would have left this just as a comment but too much code to make the comment readable, I may post an answer later if no one else has (I'd have to look where best to patch this in) @Massimo – David Carlisle Feb 11 '21 at 23:51
1

Based on your comments, you might have an XY-problem. What you say you want is sans-serif math for captions. The problem you’re having is that unicode-math supports either range= or version=, but not both together. (There’s a warning about this buried in the manual.)

If that’s what you actually want, load a sans-serif math font with version=, and don’t use range=.

\documentclass{scrartcl}
\usepackage{unicode-math}

\setmainfont{KpRoman} \setsansfont{KpSans} \setmonofont{KpMono} \setmathfont{KpMath-Regular} \setmathfont{KpMath-Bold}[version=bold] \setmathfont{KpMath-Sans}[version=sans]

\addtokomafont{disposition}{\mathversion{sans}}

\begin{document} \section*{Isn’t (\mathbb{R}^3) Wonderful?}

Truly, (\mathbb{R}^3) is. \end{document}

KP-fonts sample

Unfortunately, you’re not spoiled for choice when it comes to sans-serif math fonts.

It’s trivial to define \sansversion analogous to \boldversion, and you can also adapt the \boldsymbol code from amsbsy.sty to a \sanssymbol command if you need to be able to switch to sans-serif math within an expression. Otherwise, set the formatting of captions and whatever else you want to be sans-serif to \sffamily\mathversion{sans}.

If you already knew this and you were just asking how you can change the Greek letters in your math font, without using range=, one way to do that would be to define a new \setmathfontface or math version= that selects your alternative Greek font.

\documentclass{article}
\tracinglostchars=2
\usepackage[math-style=ISO]{unicode-math}

\defaultfontfeatures{Scale=MatchLowercase} \setmainfont{EBGaramond}[Scale=1.0] \setsansfont{KpSans} \setmonofont{KpMono} \setmathfont{Garamond-Math} \setmathfont{KpMath-Sans}[version=sans] \setmathfontface{\altgreek}{GFS Olga}

\newcommand\altGamma{\altgreek{\mupGamma}} \newcommand\altzeta{\altgreek{\mupzeta}}

\begin{document} Truly, (\altGamma(\altzeta)) is wonderful. \end{document}

EB Garamond/GFS Olga sample

Davislor
  • 44,045
  • Thank you. I already knew the first solution. The problem is that I want both things, a math sans face and a different font for greek. Your (second) solution with \setmathfontface seems to work, although it requires that I redefine all Greek letters I'm using. – Massimo Feb 12 '21 at 21:02