latex3 / unicode-math

XeLaTeX/LuaLaTeX package for using unicode/OpenType maths fonts
http://ctan.org/pkg/unicode-math
LaTeX Project Public License v1.3c
239 stars 28 forks source link

\setmathfontface\mathit has no effect in preamble #618

Open ysalmon opened 11 months ago

ysalmon commented 11 months ago

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:

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

hvoss49 commented 11 months ago

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
ysalmon commented 11 months ago

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

hvoss49 commented 11 months ago
\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
ysalmon commented 11 months ago

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.

FlatLanguage commented 5 months ago

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

hvoss49 commented 5 months ago

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
FlatLanguage commented 5 months ago

The purpose is consistantly to use different font between \textit and \mathit, isn’t it? So, \textit should not be Pagella.

hvoss49 commented 5 months ago

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

FlatLanguage commented 5 months ago

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.