4

In my document I need to use Constantia as main font and Arial for different parts of the document. Therefore I use LuaLaTeX to compile the document. Furthermore I need siunitx and unicode-math. The actual problem arises when I use \SI{}{} for the first time in my document, since afterwards mathematical operators are set in Arial again (even though the main font is Constantia).

MWE:

\documentclass{scrreprt}
\usepackage{fontspec}
\setmainfont{Constantia}
\usepackage[output-decimal-marker=.,exponent-product=\cdot,per-mode=symbol]{siunitx}
\sisetup{detect-all}
\AtBeginDocument{\sisetup{math-rm = \symup}}
\usepackage{unicode-math}
\setmathfont{Latin Modern Math}
\begin{document}

\setmainfont{Arial}

\setmainfont{Constantia}

$\lim\limits_{x\rightarrow \infty}$ \SI{25}{\percent} $\lim\limits_{x\rightarrow \infty}$
\end{document}

yields:

enter image description here

As can be seen, "lim" is set in Arial. Commenting \setmainfont{Arial} helps:

enter image description here

Does anybody know where this comes from and how it can be fixed? Unfortunatelly I need to use the different fonts.

Thank you in advance!

Regards Julian

  • 2
    Welcome to TeX.SX! Why are you changing \setmainfont after \begin{document}? – egreg Jul 19 '18 at 15:11
  • 1
    Mhhh, it looks as though siunitx' \SI command influences the math mode after it, that should definitely not happen and I guess that should be reported at github.com/josephwright/siunitx/issues. At the same time I have the feeling that changing the main font with \setmainfont as often as you do does not constitute best practice. You should probably declare Arial as \newfontfamily and use that if appropriate. – moewe Jul 19 '18 at 15:22
  • 1
    \setmathrm{Constantia}? – Henri Menke Jul 20 '18 at 1:41
  • @egreg This comes from the template I am using – J. Prass Jul 20 '18 at 7:40
  • @moewe I will try this, thank you for the hint – J. Prass Jul 20 '18 at 7:41
4

The unicode-math package is supposed to set the operator font to the main font of the document. I’ve found that to be buggy sometimes. Here, it appears to be related to an interaction between fontspec and siunitx, but you knew that.

I haven’t attempted to debug this, but I do know a workaround: \setoperatorfont{\rmfamily}. Could be very handy if you’re changing the document font around or want to load a different font family for operator names.

\documentclass[varwidth, preview]{standalone}
\usepackage{fontspec}
\setmainfont{Constantia}
\defaultfontfeatures{Scale=MatchLowercase}
\usepackage[output-decimal-marker=.,exponent-product=\cdot,per-mode=symbol]{siunitx}
\sisetup{detect-all}
\AtBeginDocument{\sisetup{math-rm = \symup}}
\usepackage{amsmath}
\usepackage{unicode-math}
\setmathfont{Latin Modern Math}
\setoperatorfont{\rmfamily}

\begin{document}

% These confuse `unicode-math`:
\setmainfont{Arial}
\setmainfont{Constantia}

$\lim\limits_{x\rightarrow \infty}$ \SI{25}{\percent} $\lim\limits_{x\rightarrow \infty}$
\end{document}

Sample

Aside from that, I added two other lines: setting Scale= as a default font feature so all the fonts you load will match, and explicitly including amsmath.

I would strongly advise against using \setmainfont inside the document body, however. It would be better to load the families you need in your preamble, such as \setsansfont{Arial} or \newfontfamily\yourfavoritefont{Comic Sans}, and select a font family inside the document. You can also set these as your operator font and use the range= option of \setmathfont to change your math symbols to match the text font.

  • 1
    Thank you for this hint, it works very well to just use {\sffamily ... } with Arial set as sans font. I will thus mark this answer as solution. – J. Prass Jul 20 '18 at 9:29

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.