2

I am stuck with configuring siunitx to my liking.

Using LuaLaTex and fontspec I want siunitx to print numbers and units in normal text font when in text. When in math mode I want it to print numbers in serif math font and units in sans serif text font. No matter what I change, it always affects both typesettings, inside and outside of math mode.

Her is my MWE:

\documentclass[a4paper, 10pt, german]{scrartcl}

\usepackage{polyglossia}
    \setdefaultlanguage[spelling=new]{german}           
    \setotherlanguage{english}

\usepackage{fontspec}
    \setmainfont{Tex Gyre Heros}[Scale=0.91]            
    \setsansfont{Tex Gyre Heros}[Scale=0.93, LetterSpace=0, WordSpace=0.96]
    \setmonofont{TeX Gyre Cursor}[Scale=0.95]
\usepackage{microtype}  



\usepackage{mathtools}
\usepackage{unicode-math}

\usepackage{siunitx}
            \sisetup{%detect-all,
                    math-rm=\mathsf,
                    text-rm=\sffamily,
                    binary-units=true, %use binary units
                    per-mode=fraction, %\per inserts fraction
                    output-decimal-marker={,} %comma as decimal sperator
                    }

\begin{document}

In text I want siunitx to print sans serif text font: 1000kV, \SI{1000}{\kilo\volt}

In math mode I want it to print numbers in serif math font: $1000kV, \SI{1000}{\kilo\volt}$

\end{document}

Which gives this output:

enter image description here

What am I doing wrong here?

  • You mention what numbers should look like if \SI is encountered in math mode. What about the units, though: should they use sans serif or serif? – Mico Jun 28 '18 at 8:30
  • Sorry for not being clear enough. In math mode I want numbers serif and units sans serif – namron Jun 28 '18 at 8:35
  • Speaking for myself, I find that using serif numbers together with sans-serif units looks weird. – Mico Jun 28 '18 at 8:39
  • Thanks for this question: you've contributed to v3 of siunitx :) (See github.com/josephwright/siunitx/commit/…, which is for exactly this case.) – Joseph Wright Jun 28 '18 at 11:34
2

Here's a solution that uses (a) sans-serif glyphs for both numbers and units if \SI is encountered in text mode and (b) serif glyphs for both numbers and units if \SI is encountered in math mode. This may be achieved by setting the siunitx options math-rm=\symup and detect-all.

enter image description here

\documentclass[a4paper, 10pt, german]{scrartcl}

\usepackage{fontspec}
    \setmainfont{Tex Gyre Heros}[Scale=0.91]
\usepackage{unicode-math}
    \setmathfont{Latin Modern Math}

\usepackage{polyglossia}
    \setdefaultlanguage[spelling=new]{german}
    \setotherlanguage{english}

\usepackage{microtype}
\usepackage{mathtools}

\usepackage{siunitx}
\sisetup{math-rm=\symup,detect-all}

\begin{document}

Text mode: 1000\,kV, \SI{1000}{\kilo\volt} --- sans serif text font

Math mode: $1000\,\symup{kV}$, $\SI{1000}{\kilo\volt}$ --- serif math font

\end{document} 
  • I like how this looks. Thank you. Can you explain how you came up with the math-rm=\symup option? – namron Jun 28 '18 at 9:08
  • @namron - The basic LaTeX font-selection commands are \mathrm, \textrm, etc. To use \mathcal, \mathscr, \mathfrak, is generally necessary to load additional packages (e.g., amssymb). The unicode-math package offers many new font-selection commands; they generally begin with the "prefix" \sym: \symup, \symit, \symbf, \symbfit, \symscr, \symcal, etc. If one uses the unicode-math package, one might as well make use of its commands, right? :-) – Mico Jun 28 '18 at 9:13
  • @namron - Another thing to keep in mind is that \mathrm, mathit, etc take letter glyphs from the text font. This is likely due to old technical limitations of math fonts. With unicode-based math font families, it's in principle no longer necessary to do so. However, the old settings still apply to the actions of \mathrm, \mathit, etc, presumably for the worthy objective of maintaining backward compatibily. If backward compatibility and, relatedly, the ability to recompile 25-year-old documents aren't a priority, one might as well use \symup, \symit, etc., right? – Mico Jun 28 '18 at 9:21
  • 1
    @Mico It's a bit more complicated than that: the semantic meaning may be different ... one for TUG2018 I hope – Joseph Wright Jun 28 '18 at 11:33
  • @JosephWright - Thanks for this heads-up. I certainly look forward to attending your talk (talks, actually!) in Rio! – Mico Jun 28 '18 at 11:42

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.