16

I was having some difficulty with LuaTeX and the unicode-math package. Below is a MWE,

\documentclass[12pt]{article}
\usepackage[math-style=ISO]{unicode-math}

\begin{document}
\[
    f(T), f\left( T \right),
    \int_{a}^{b} f\left( x \right) d x, \frac{1}{T},
\]
\mathitalicsmode=1
\[
    f(T), f\left( T \right),
    \int_{a}^{b} f\left( x \right) d x, \frac{1}{T},
\]
\mathitalicsmode=2
\[
    f(T), f\left( T \right),
    \int_{a}^{b} f\left( x \right) d x, \frac{1}{T},
\]
\end{document}

Here is a screenshot of the document it produces,

unicode

We can see a couple issues here,

  1. Incorrect spacing before the closing \right).
  2. Incorrect spacing before the closing ).
  3. Fraction line is too short.
  4. Last comma is too close.
  5. Incorrect spacing of the limit in the integral.

Default setting has issues 1,3,4, while \mathitalicsmode=1 has issues 3,4 and \mathitalicsmode=2 has issues 2,5.

Here is a screenshot without the unicode-math package, everything looks perfect.

nounicode

Seems it is related to the italic correction of LuaTeX. A couple recent discussion suggest changing \mathitalicsmode but we see it introduces new problems, not exactly sure how to proceed.

All documents are produced with the latest packages using MacTeX.

6
  • Welcome to TeX.SE.
    – Mico
    Commented Oct 3, 2023 at 4:17
  • 1
    nice question (and I have felt this pain before:-) Commented Oct 3, 2023 at 7:56
  • I edited your "134" line a bit as it confused me initially, roll back the edit if you are not happy with that. Commented Oct 3, 2023 at 7:59
  • Concerning β€œHere is a screenshot without the unicode-math package, everything looks perfect.”: no, in β€œπ‘“ (𝑇)” you have too much space between 𝑓 and 𝑇.
    – AlMa1r
    Commented Mar 7 at 17:15
  • @David Carlisle so the ultimate solution is XeTeX, see github.com/alerque/libertinus/issues/… Commented Jun 4 at 7:31

2 Answers 2

11

In short: As of now there does not seem to be a good way to solve your problems in LuaLaTeX with Opentype Math fonts.

Read on: The problem you see is essentially that the handling of italic correction in traditional TeX fonts and Opentype math fonts are different, and that some fonts converted were not really made to follow the new (vague) standard (essentially set by Cambria). If you do not load unicode-math, you will get the old type1 fonts, and that is why you get what you expect. Let me start by showing the result of your example, set with Cambria:

Cambria

Here, I'd say that the first example looks OK (except for the space between the f and the (, but that could be avoided by not using \left). I would say that the reason is that Cambria is the "model Opentype math font", the font made by Microsoft at the same time as the rather vague specification was done, and luatex was adapted to that (what else?).

Looking at the specification we find

Italics correction can be used in the following situations:

  • When a run of slanted characters is followed by a straight character (such as an operator or a delimiter), the italics correction of the last glyph is added to its advance width.
  • When positioning limits on an N-ary operator (e.g., integral sign), the horizontal position of the upper limit is moved to the right by Β½ of the italics correction, while the position of the lower limit is moved to the left by the same distance.
  • When positioning superscripts and subscripts, their default horizontal positions are also different by the amount of the italics correction of the preceding glyph.

Latin modern math (the font used in your screenshots), was converted from the traditional Computer modern math fonts, and so it inherits some of the behaviors from that as well (one could argue that it was not really made into a real Opentype math font, whatever that would mean). This means that one will see problems like these pop up, and even with quick fixes like \mathitalicsmode2 (added in April 2022) that was added to cure one problem in one situation, what happens is that the problem is just pushed to some other place/construction.

I think that what needs to be done (challenge to the unicode-math maintainers) to finally get rid of this problem is to use some similar model as we now have in ConTeXt and luametatex, where the italic correction taken care of by altering widths of glyphs and adding corner kerns. This seems to be a model that works OK with most fonts.

Your example (adapted for ConTeXt) looks like:

ConTeXt example

In case you are curious, the code used to generate this was:

\usebodyfont[modern]
\usebodyfont[cambria]
\setupbodyfont[modern]

\starttext
\startbuffer
\startformula
  f(T), f\left( T \right),
  \int_{a}^{b} f\left( x \right) \dd x, \frac{1}{T},
\stopformula
\stopbuffer

\getbuffer

\switchtobodyfont[cambria]
\getbuffer
\stoptext
1
  • Thanks for the detailed explanation. This is really unfortunate cause originally I thought I was missing something. Finally got time to read The Not So Short Introduction to LaTeX, and ``` unicode-math ``` is the recommended setup. I do like the idea of Unicode in the pdf, but if basic format turns out to be a problem I guess will avoid it from now on. Thank you again!
    – flinch9483
    Commented Oct 5, 2023 at 0:27
5

You can encourage luatex to add italic correction by adding zero width character at the end of the math lists, this isn't perfect but gives a bit more control than the italics mode param. See try 4 here.

enter image description here

\documentclass[12pt]{article}
\usepackage[math-style=ISO]{unicode-math}

\begin{document}
\[1+
    f(T), f\left( T \right),
    \int_{a}^{b} f\left( x \right) d x, \frac{1}{T},
\]
\mathitalicsmode=1
\[2+
    f(T), f\left( T \right),
    \int_{a}^{b} f\left( x \right) d x, \frac{1}{T},
\]
\mathitalicsmode=2
\[3+
    f(T), f\left( T \right),
    \int_{a}^{b} f\left( x \right) d x, \frac{1}{T},
\]
\mathitalicsmode=0
\let\oldright\right
\protected\def\right{^^^^200b\oldright}
\let\oldfrac\frac
\protected\def\frac#1#2{\oldfrac{#1^^^^200b}{#2^^^^200b}}
\[4+
    f(T), f\left( T \right),
    \int_{a}^{b} f\left( x \right) d x, \frac{1}{T},
\]
\end{document}
2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .