\setmathfontface\mathit has no effect in preamble
Opened this issue · 9 comments
Description
Issuing \setmathfontface\mathit{texgyrepagella-italic.otf}
in the preamble of my document does not change the appearance of things typeset with \mathit
.
Add info or delete as appropriate:
- Relevant for XeTeX, Version 3.141592653-2.6-0.999995 (TeX Live 2023)
- Relevant for LuaHBTeX, Version 1.17.0 (TeX Live 2023)
- May be related to how unicode-math tries to update math font when the main font is changed in fontspec (the
\mathit
looks like the italic variant of the main font). However this happens without any call to\setmainfont
as well.
Minimal example demonstrating the issue
\documentclass[border=5pt]{standalone}
\RequirePackage{unicode-math}
\setmathfont{texgyrepagella-math.otf}
\setmathfontface\mathit{texgyrepagella-italic.otf}
\begin{document}
a$a$$\mathit{a}$
\end{document}
The third a
should look like the second one, because TexGyrePagella italic does look like the math characters of TexGyrePagella-math.
Further details
Issuing \setmathfontface
after \begin{document}
gives an error that it should only be used in preamble.
Issuing \AtBeginDocument{\setmathfontface...}
in the preamble works.
The log shows that the requested font is indeed loaded at some point.
document1.log
Thank you for this valuable bit of information, but I think this does not suit my needs, because of kerning (eg. when typesetting \mathit{different}
).
My use case is I typeset computer science, where multi-letter variables are a thing. I need the kerning of such a variable to be word-like, not product-of-single-letter-variables-like, while retaining letters that are of the same nature as single-letter variables (that is : not the same italic which is used to emphasise text).
Nice. After going through the package, it seems I can get the output I want by saying
\documentclass[varwidth, border=3pt]{standalone}
\usepackage{fontspec, unicode-math}
\setmainfont{texgyrepagella}
\setmathfont{texgyrepagella-math.otf}
\setmainfont{Gentium}
\begin{document}
different\\
$d$\\
$\mathit{different}$ \\
\textit{different}
\end{document}
Removing \setmainfont{texgyrepagella}
makes \mathit
look like \textit
, ie. Gentium Italic (which I do not want).
Removing \setmathfont{texgyrepagella-math.otf}
reverts $d$
to the default LaTeX font (which was to be expected !) but does not change \mathit
(which confounds me).
Also, the first \setmainfont
changes both \mathit
and \textit
while the second one only changes \textit
.
I wonder if this is normal.
Poor Solution:
\documentclass{standalone}
\RequirePackage{unicode-math}
\setmathfont{texgyrepagella-math.otf}
\AtBeginDocument{\let\mathit\relax}
\setmathfontface\mathit{texgyrepagella-italic.otf}
\begin{document}
a\textit{a}$a$$\mathit{a}$
\end{document}
Or:
\documentclass{standalone}
\RequirePackage{unicode-math}
\setmainfont{TeX gyre Heros}
\setmathfont{texgyrepagella-math.otf}
\setmathfontface\mathit{texgyrepagella-italic.otf}
\begin{document}
a\textit{a}$a$$\mathit{a}$
\end{document}
The purpose is consistantly to use different font between \textit and \mathit, isn’t it?
So, \textit should not be Pagella.
it depends on what you define!
\textit{} --> always textfont
\mathit{} --> character from the TEXTfont!!
\symit{} --> character from the MATHfont
Only for fonts which have text and math glyphs, it is the same for \mathit
and \symit
, e.g. Libertinus, kpfonts, modern,pagella, ...
No fonts have text and math glyphs. \symit and \mathit should be distinguished. 〇〇-Math.otf should be assigned for \symit, but 〇〇-Italic.otc should be assigned for \mathit.
Now we have discussed about how to assign different (text) fonts to \textit and \mathit. Easy way is using \setmathrm, but unicode-math also provide \setmathfontface. But it sometimes doesn’t work, like ysalmon pointed out.