Excerpts from Hans Hagen's message of March 15, 2021 10:08 am:
On 3/15/2021 3:12 AM, Johannes Rosenberger wrote:
Hi LuaTeX developers,
first of all, thank you very much for all your work on this and the great OpenType support and possibility of fixing internals using Lua code!
In the following document, the math subscripts are so close to the following characters that they sometimes overlap:
\documentclass{article} \usepackage{unicode-math}
\def\supp{{\rm supp}}
\begin{document}
$$ I(P_X,P_{Y|X}) = \sum_{(X,Y) \in \supp P_{XY}} P_{XY}(X,Y) \log_2 \frac{P_{XY}(X,Y)}{P_X(X) P_Y(Y)}. $$
\end{document}
I can't speak for latex but it has to do with the fact that some of the tex related fonts have old school metrics: they lie about the width. The traditional engine always adds italic correction and in some cases afterwards removes it (for that reason the 'width' is the 'real width' minus 'italic correction'. In opentype the real width is used and such corrections are done with math kerns (and most otf tex fonts lack them); italic correction is only added is a few cases.
Aren't the two measures dual? The two concepts seem to me simply like positive (italic) and negative (kerning) correction. I don't see how it should be a problem to apply both if the respective amounts are specified by the font. The latter is the case e.g. for Latin Modern Math. It is simply not applied by LuaTeX. I only imagine that applying both could be a problem if the font specifies both variants alternaviely such that applying both would result in an overcorrection. But wouldn't this be a particularly badly designed font? So: Could compatibility with the $real top edge width = width + it. correction$ really hurt fonts with $real bottom edge width = width - kerning$? The OpenType spec [1] lets one apply italic correction to a base glyph to shift the superscript to the right. This seems very similar to applying italic correction to a subscript to shift the following base glyph right.
There are / have been ways to force luatex into old school mode but none of them is good enough to catch all so we no whave two code paths: old school tex fonts and opentype cf cambria (which sets the standard).
Unfortunately I have no cambria to test, because I'm on Linux. Are OpenType fonts relying on italics correction ignored, then? Apparently, such fonts like Latin Modern Math are effectively unusable for maths involving upper-case indices if they are uncorrected. No, LuaTeX is unusable if you want to use such a font.
We'll see if the gyre fonts will get this done the open type way. If not, we'll have to work around it and you solution is one of them although it might not work not out well with a font that has real widths and also italic corrections which then get applied. There are several solutions for it what aproach is chosen depends on the macro package and taste.
As above: What a font could this be? Why should italics correction be specified on top of the real maximal width? If the 'real width' is not the slanted/italic character width, how is it real? The TeX Gyre fonts don't seem to be developed further at lightning speed. E.g. the latest TeX Gyre fonts are from 2016. Do you know of any free math font which has intrinsic math kerning, so that I can test it?
Can you post the pdf of the test ? -- luigi scarso
Here is my correction code, together with example documents, as tex+pdf for some fonts: https://git.sr.ht/~jorsn/luatex-math-spacing Information on how to easily use other fonts is in the GNUMakefile. Best, Johannes [1]: https://docs.microsoft.com/en-us/typography/opentype/spec/math