latex3/unicode-math

\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.
Screenshot_20230730_181755

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

Use

\usepackage[math={mathit=sym}]{pagella-otf}

or

\usepackage[mathit=sym]{unicode-math}
\setmathfont{texgyrepagella-math.otf}

Bildschirmfoto 2023-07-30 um 18 32 02

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).

\documentclass{scrbook}
\usepackage{amsmath}
\usepackage{pagella-otf}
\begin{document}

$\mathit{different}$
$\symit{different}$
$\textit{different}$

\end{document}

Bildschirmfoto 2023-07-30 um 20 23 48

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}

Screenshot_20230730_205225

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}

aaa

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}

aaa

The default font is Latin Modern and your math Pagella, which makes no real sense!

\documentclass[border=10pt]{standalone}
\RequirePackage{pagella-otf}
\begin{document}
	a\textit{a}$a$$\mathit{a}$
\end{document}
Bildschirmfoto 2024-01-16 um 13 27 19

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.