latex3 / unicode-math

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

Superscript/subscript kerning when using text font #579

Open xsrvmy opened 2 years ago

xsrvmy commented 2 years ago

It is usually considered proper form to switch to text font for the subscript if the subscript is not a variable or number (eg. n_{\mathrm{in}}). However, this ignores the kerning for the subscript in the math table. Is it possible somehow to change this behaviour in unicode-math? Or is this the same "no kerning between different math families" issue from latex that cannot be fixed?

There is a workaround for this BTW: adding \Umathchar"0"00"00200B at the start of the subscript before the \mathrm command shifts the no-kerning boundary to inside the subscript, without adding space since this is a zero-width character, so the subscript kerning is now respected.

davidcarlisle commented 2 years ago

Can you clarify the issue you are seeing?

with

\documentclass{article}

\usepackage{unicode-math}

\begin{document}

\ifx\directlua\undefined XeTeX\else LuaTeX\fi:
$
P_{in} +
P_{\symrm{in}} +
P_{\mathrm{in}} +
P_{\Umathchar"0"000"00200B \mathrm{in}}
$
\end{document}

I get different behaviour with luatex and xetex

image

image

so in luatex the subscript is kerned under the P in all cases, but in xetex the zero width character prevents the kerning

xsrvmy commented 2 years ago

Use need to use STIX2 to see the issue. I think LM is using a negative bearing.

davidcarlisle commented 2 years ago

@xsrvmy ah adding \setmathfont{STIX Two Math} I get

image

image

So yes it shows the issue there, although having the effects be both engine and font dependent might make it "interesting" to handle in a common way in neutral code in the package. Something for @wspr :-)

khaledhosny commented 7 months ago

This is a font and engine issue similar to https://github.com/latex3/unicode-math/issues/592. The font has (excessive) math kerning for P and each engine is applying it differently.

khaledhosny commented 6 months ago

This issue should be closed, see https://github.com/latex3/unicode-math/issues/592#issuecomment-2041224153