5

The story about italic correction in LuaLaTeX when using unicode-math seems to be an old one. However, the issue does not appear to be fixed. Here is what it looks like with unicode-math

without italic correction

and without

with italic correction

Note the yellow box right to the second f, which indicates kerning. It looks even worse when using the Libertinus font, then the f and the > really overlap:

missing italic correction with libertinus

I guess this is because Libertinus defines the right border of the f to be different.

Here is the code used to generate the last screenshots:

%! TEX program = lualatex
\documentclass{article}

\usepackage{lua-visual-debug}

\usepackage{unicode-math}
\setmathfont{Libertinus Math}

% enable italic correction
\everymath\expandafter{\the \everymath \luatexcatcodetable\CatcodeTableLaTeX}
\everydisplay\expandafter{\th[enter image description here][4]e \everydisplay \luatexcatcodetable\CatcodeTableLaTeX}

\newcommand{\luatexcatcodetable}{}
\newcommand{\CatcodeTableLaTeX}{}

\newcommand*{\norm}[1]{{\ensuremath{\left\|{#1}\right\|}}}
\newcommand*{\inner}[1]{{\ensuremath{\left\langle{#1}\right\rangle}}}

\begin{document}
   \[
       \inner{f, f}       \hspace{2em}
       \norm{f}_2^2       \hspace{2em}
       \inner{g, g}       \hspace{2em}
       \norm{g}_2^2       \hspace{2em}
   \]
\end{document}

Also, dropping the \left and \right makes it looks as it should:

corrected libertinus math

Unfortunately the once recommended workaround

\everymath\expandafter{\the\everymath\luatexcatcodetable\CatcodeTableLaTeX}
\everydisplay\expandafter{\the\everydisplay\luatexcatcodetable\CatcodeTableLaTeX}

gives me the following error:

! Undefined control sequence.
<inserted text> \@displaytrue \luatexcatcodetable 
                              \CatcodeTableLaTeX

It looks like both commands \luatexcatcodetable and CatcodeTableLaTeX do not exist anymore. Adding

\newcommand{\luatexcatcodetable}{}
\newcommand{\CatcodeTableLaTeX}{}

makes my code compile (note that I did not have to use \renewcommand!), but obviously this has then no effect on italic correction. Any idea how to get italic correction now?

7
  • 1
    Please show the code the generated the screenshots you posted. The reason I ask is that I am unable to reproduce the screenshot with what I consider to be standard LaTeX commands. E.g., \documentclass{article} \usepackage{mathtools,unicode-math} \setmathfont{Libertinus Math} \begin{document} \[ \langle f,f\rangle \quad \lVert f\rVert_2^2 \quad \langle g,g\rangle \quad \lVert g\rVert_2^2 \] \end{document}
    – Mico
    Commented Apr 25, 2022 at 19:07
  • @Mico I added the code. Commented Apr 25, 2022 at 19:20
  • 1
    What is that catcodetable business supposed to do? Commented Apr 25, 2022 at 19:21
  • 3
    I think you found a bug in luaotfload (or in the font). I've built a Plain TeX reproducer and pinged the maintainers in chat: chat.stackexchange.com/transcript/message/60968585#60968585 Commented Apr 25, 2022 at 19:51
  • 1
    @red_trumpet It seems to go even deeper than just luaotfload. I've also reported this problem to the LuaTeX developers: tug.org/pipermail/luatex/2022-April/007701.html Commented Apr 25, 2022 at 20:13

1 Answer 1

2

From this answer I got the solution to add \mathitalicsmode=1 to the preamble. If I understand correctly, this enables italic correction in math mode. To obtain the desired result, one also has to remove the surrounding brackets { ... }, otherwise italic correction is not applied (except if there is a single character {f}, then it seems to work. Why?) So the following code example works fine:

%! TEX program = lualatex
\documentclass{article}

\usepackage{lua-visual-debug}

\usepackage{unicode-math}
\setmathfont{Libertinus Math}

\mathitalicsmode=1

\begin{document}
   \[
       \left\langle f,f \right\rangle
   \]
\end{document}
4
  • 1
    Braces create a sub_mlist but probably there is an optimization where the sub_mlist is omitted if it's only a single character. Normally the use of {...} is in inline math to prevent linebreaks, as in ${a + b}$ because + is a valid breakpoint for TeX. Commented Apr 26, 2022 at 6:54
  • @HenriMenke Removing braces when the math sublist contains a single character has been a TeX feature from the beginning.
    – egreg
    Commented Apr 26, 2022 at 8:21
  • 2
    @red_trumpet The next version of LuaTeX will have \mathitalicsmode=2 to deal with the sub_mlist problem: github.com/TeX-Live/luatex/commit/… Commented Apr 26, 2022 at 17:42
  • @HenriMenke I saw snippets with some …old… and …new… macro identifiers. As old and new depend on the time, the folks that read these identifiers in a few years (or, in the worst case, months) might not know what old and new would refer to. So the developer might consider giving more descriptive names.
    – user282514
    Commented Oct 17, 2022 at 16:44

You must log in to answer this question.

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