Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

\setmathfontface\mathit has no effect in preamble #618

Open
ysalmon opened this issue Jul 30, 2023 · 9 comments
Open

\setmathfontface\mathit has no effect in preamble #618

ysalmon opened this issue Jul 30, 2023 · 9 comments

Comments

@ysalmon
Copy link

ysalmon commented Jul 30, 2023

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

@hvoss49
Copy link

hvoss49 commented Jul 30, 2023

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
Copy link
Author

ysalmon commented Jul 30, 2023

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
Copy link

hvoss49 commented Jul 30, 2023

\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
Copy link
Author

ysalmon commented Jul 30, 2023

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
Copy link

FlatLanguage commented Jan 16, 2024

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
Copy link

hvoss49 commented Jan 16, 2024

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
Copy link

FlatLanguage commented Jan 16, 2024

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

@hvoss49
Copy link

hvoss49 commented Jan 16, 2024

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants