How to get italic correction in LuaLaTex with unicode-math and \left \right

fontsitalic-correctionkerningluatexunicode-math

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?

Best Answer

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}