3

My goal is to use a sans serif math font in all figures and I found several approaches with my favourite being the use of \mathversion and the unicode-math package to change between different math fonts. However, I am not able to switch between fonts due to the warning

Package fontspec Warning: Font "Latin Modern Math" does not contain requested (fontspec) Script "Math".

that repeats for all fonts I import with a [version=] parameter. However, I can change the math font for the whole document.

So my question: What am I doing wrong? I basically copied my code from another answer (will add the link when I find it again).

My mwe for testing is

\documentclass[authoryear,preprint,5p,11pt]{scrartcl}
\usepackage{amsmath}
\usepackage{pgfplots}

\usepackage{fontspec}
\usepackage[]{unicode-math}
\defaultfontfeatures{ Scale=MatchLowercase, Ligatures=TeX }
\setmathfont{XITS Math}
\setmathfont{Latin Modern Math}[version=lm]
\setmathfont{TeX Gyre Pagella Math}[version=pagella]

\begin{document}
This is some text.

And a figure with maths elements
\begin{figure}[ht]
  % \mathversion{sansmath}
 \begin{pgfpicture}
 \pgftext[x=0.691229in,y=0.540666in,,top]{\sffamily\selectfont 125}%
 \pgftext[x=0.354158in,y=0.432447in,left,base]{\sffamily\selectfont \(\displaystyle \frac{-\pi}{2}\)}%
 \pgftext[x=1.054158in,y=0.432447in,left,base]{\sffamily\selectfont \(\displaystyle 10^{3123x} \cdot 12389\)}%
 \end{pgfpicture}
\end{figure}
and a formula
\[ \frac{\pi}{2.42132}= \beta\]
 and some math in another font
\mathversion{lm}
\[ \frac{\pi}{2.42132}= \beta\]
 and yet another one
\mathversion{pagella}
 \[\frac{123456} {some text}\]

\end{document}

The full logfile is here: https://pastebin.com/kS3quC7A

4
  • I don't get your warnings. Is your system up-to-date? Can you show the complete log-file? – Ulrike Fischer Dec 1 '20 at 13:18
  • Added the logfile. System should be very much up to date, I just reinstalled texlive. – Hering Dec 1 '20 at 14:40
  • 1
    well your system is not really up-to-date, you have eg a latex format from februar, and mine is from october. But imho the main problem is that your xelatex seems to find some mathjax fonts: LatinModernMathJax_Size1-Regular/OT and similar for Pagella: GyrePagellaMathJax_Symbols-Regular/OT and this fonts confuses it. Try if it works if you use filenames like latinmodern-math.otf instead of the font name. – Ulrike Fischer Dec 1 '20 at 15:14
  • @UlrikeFischer This is indeed the origin of the problem. I did not draw the connection to a font mixing issue. If I use the font names from the files installed in /usr/local/share/fonts/OTF it's working well. You may raise your comment to an answer :) – Hering Dec 1 '20 at 15:50
1

Your log shows that xelatex is finding mathjax fonts:

LatinModernMathJax_Size1-Regular/OT and similar for Pagella: GyrePagellaMathJax_Symbols-Regular/OT and these fonts confuses it.

Try if it works if you use filenames like latinmodern-math.otf instead of the font names.

1

The only OpenType sans serif math font I know of is GFS Neohellenic Math.

\documentclass{article}
\usepackage{amsmath}

\usepackage{fontspec}
\usepackage[]{unicode-math}

\setsansfont{GFSNeohellenic}[
  Extension=.otf,
  UprightFont=*,
  ItalicFont=*It,
  BoldFont=*Bold,
  BoldItalicFont=*BoldIt,
]
\setmathfont{Latin Modern Math}
\setmathfont{GFSNeohellenicMath.otf}[version=sansmath]

\begin{document}
This is some text.

And a figure with maths elements

\begin{figure}[ht]
\centering
\sffamily\mathversion{sansmath}

\[
125+\frac{-\pi}{2}+10^{3123x} \cdot 12389+\sin3
\]

\caption{Whatever}

\end{figure}

and a formula
\[ \frac{\pi}{2.42132}= \beta\]

\end{document}

enter image description here

3
  • Very very nice the font GFSNeohellenicMath.otf. I put this question between my favorities. – Sebastiano Dec 1 '20 at 12:37
  • There's also Fira Math. – Sergei Golovan Dec 1 '20 at 14:18
  • Yes, that's true, I could perhaps do something similar. I still don't know why I can not use the mathversion command to switch fonts. I can successfully change all math in the document to some sans serif like Fira Math or Nimbus Sans Math but not in combination with other fonts.I'll see what I can take from your example. – Hering Dec 1 '20 at 14:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.