Problem with sffamily
with this code, the \pi and \alpha disappear when \sffamily is active.
\documentclass{article}
\usepackage[warnings-off={mathtools-colon,mathtools-overbracket},math-style=french]{unicode-math}
\usepackage[default]{fontsetup}
\usepackage{siunitx}
\sisetup{%
text-family-to-math = true,%
text-series-to-math = true,%
}%
\begin{document}
2$\pi$ -- 3$\alpha$ --
\SI[parse-numbers=false]{2\pi}{\centi\meter} --
\SI[parse-numbers=false]{3\alpha}{\centi\meter}
{\bfseries
2$\pi$ -- 3$\alpha$ --
\SI[parse-numbers=false]{2\pi}{\centi\meter} --
\SI[parse-numbers=false]{3\alpha}{\centi\meter}
}
{\sffamily
2$\pi$ -- 3$\alpha$ --
\SI[parse-numbers=false]{2\pi}{\centi\meter} --
\SI[parse-numbers=false]{3\alpha}{\centi\meter}
}
{\sffamily\bfseries
2$\pi$ -- 3$\alpha$ --
\SI[parse-numbers=false]{2\pi}{\centi\meter} --
\SI[parse-numbers=false]{3\alpha}{\centi\meter}
}
\end{document}
What is happening is that with the settings you have, siunitx is applying \mathsf and \boldmath to the output. If you try that as a 'reference'
\bfseries\boldmath
$\mathsf{2\pi}$ -- $\mathsf{3\alpha}$
you'll find the symbols also disappear - so in that sense it's not the package's fault. You also see the log warnings about this:
Missing character: There is no 𝜋 (U+1D70B) in font cmss10!
Missing character: There is no 𝛼 (U+1D6FC) in font cmss10!
One could argue for \symsf here in a Unicode setup - that would give printed output in your case. However, that would be problematic with any content with multiple symbols - this remains something of an issue in trying to swap neatly between \math... and \sym... (generally).
I will think about this to see what the best current solution might be - using \sym... is not difficult (just needs a change to one internal - either with an option or a hard decision by me), but I'm not totally convinced it's the right decision.
Just curious, something puzzles me in this code: if I add a \showouput, the output of the first \SI[parse-numbers=false]{2\pi}{\centi\meter} command (for \rmfamily) is:
....\TU/NewCMMath-Book.otf(1)/m/n/10 2
....\TU/NewCMMath-Book.otf(1)/m/n/10 π
....\mathoff
....\penalty 10000
....\kern1.66702
....\mathon
....\hbox(4.48+0.11)x12.77, direction TLT
.....\TU/NewCM10-Book.otf(1)/m/n/10 c
.....\TU/NewCM10-Book.otf(1)/m/n/10 m
....\mathoff
and for the same command in \sffamily:
....\hbox(6.78+0.0)x5.0, direction TLT
.....\TU/NewCMSans10-Book.otf(1)/m/n/10 2
....\mathoff
....\penalty 10000
....\kern1.66702
....\mathon
....\hbox(4.61+0.11)x12.38, direction TLT
.....\TU/NewCMSans10-Book.otf(1)/m/n/10 c
.....\TU/NewCMSans10-Book.otf(1)/m/n/10 m
....\mathoff
- So, in the first case, the output of
2\picomes from the Math font NewCMMath-Book, while in the second case the2comes from the Text font NewCMSans10-Book and TeX complains "There is no 𝜋 (U+1D70B) in font [NewCMSans10-Book.otf]". - Why is an italic 𝜋 required there? An upright one (U+03C0) is part of NewCMSans10-Book, while it is hopeless to find U+1D70B in a text font.
I understand that an italic 𝜋 is also required in the first case but is turned to upright due to "math-style=French" option of unicode-math.
@dflipo
1. So, in the first case, the output of `2\pi ` comes from the _Math_ font NewCMMath-Book, while in the second case the `2` comes from the _Text_ font NewCMSans10-Book and TeX complains "There is no 𝜋 (U+1D70B) in font [NewCMSans10-Book.otf]".
Yes, because to match sanserif text into math mode I need to surround with \mathsf, which then takes from the text font. The alternative is as I've said \symsf but then one has the issue with kerning. This is a tricky area.
2. Why is an italic 𝜋 required there? An upright one (U+03C0) is part of NewCMSans10-Book, while it is hopeless to find U+1D70B in a text font.
Because \pi in a Unicode setup is the italic character not simply 'the concept of pi' - try \show\pi :-).
Spoiler:
> \pi=macro:
->\mitpi .
l.10 \show\pi
...
> \mitpi=the character 𝜋.
l.10 \show\mitpi
@josephwright Thanks for these clarifications, point 2. is clear for me now.
Regarding point 1, I expected that option text-family-to-math = true would also surround the first mandatory argument of \SI (2\pi) with \mathrm in the first case… and return the text font NewCM10-Book instead of NewCMMath-Book. What am I missing?
@dflipo First, ideally we don't want to apply anything at all: in an ideal world this would be a font change in all cases. More concretely, the code was written first for pdfTeX, which remains a key target. There, \mathrm{\pi} is bad news - you want \mathnormal. So I avoid applying fond changes without a good reason. In a Unicode worl, the distinction between math and text fonts is more complex - but at the moment it's really still not ideal. Most importantly, we really want math font here - which with 'just use the input' we get for a decent amount of stuff.
@josephwright OK, I understand siunitx omits \mathrm on purpose, the output is what the user expects in that case.
One more question, sorry: in the {\bfseries ...} example, I get
why are the {\cent\meter} units not printed in bold? surrounding en-dashes are bold…
@josephwright OK, I understand
siunitxomits\mathrmon purpose, the output is what the user expects in that case.One more question, sorry: in the
{\bfseries ...}example, I get
Can you post your input?
My input (lualatex, TL2025 updated this morning) is extracted from ChristophePoulain's example above):
\documentclass{article}
\usepackage[warnings-off={mathtools-colon,mathtools-overbracket},math-style=french]{unicode-math}
\usepackage[default]{fontsetup}
\usepackage{siunitx}
\sisetup{%
text-family-to-math = true,%
text-series-to-math = true,%
}%
\begin{document}
\showoutput
{\bfseries
2$\pi$ -- 3$\alpha$ --
\SI[parse-numbers=false]{2\pi}{\centi\meter} --
\SI[parse-numbers=false]{3\alpha}{\centi\meter}
}
\end{document}
the .log file shows for \SI[parse-numbers=false]{2\pi}{\centi\meter}:
....\mathon
....\TU/NewCMMath-Bold.otf(1)/m/n/10 2
....\TU/NewCMMath-Bold.otf(1)/m/n/10 π
....\mathoff
....\penalty 10000
....\kern1.66702
....\mathon
....\hbox(4.48+0.11)x12.77, direction TLT
.....\TU/NewCM10-Book.otf(1)/m/n/10 c
.....\TU/NewCM10-Book.otf(1)/m/n/10 m
....\mathoff
@dflipo In your code above, please change:
```\documentclass{article}
for:
```latex
\documentclass{article}
otherwise \documentclass{article} is missing on GitHub.
@dbitouze Thanks, done.