Is there a way to add italic correction at the end of inline math

fontsitalic-correctionkerningluatexmath-mode

I would like to add italic correction at the end of inline math, depending on the italic correction of the last math character. Here is a MWE showing why I would like to have that:

%! TEX program = lualatex
\documentclass{article}

\usepackage{fontspec}
\usepackage{unicode-math}

\setmainfont{Libertinus Serif}
\setmathfont{Libertinus Math}

\begin{document}
Some text interlaced with an \(f\) here.
\end{document}

As you can see, the f is pretty near the word "here". Of course I could just add some constant space, but ideally LaTeX would use the italic correction provided from the math font. In that way, only characters that lean heavily to the right would get an additional space (provided the font has correct italic correction). Is that possible?

I tried adding \/ both at the end of the math (\(f\/\)) and after the math mode (\(f\)\/), but neither had any effect. Using \(f\) \/ had some effect, though I guess latex just inserted an additional space there, not really the italic correction.

Best Answer

If one adds \mathitalicsmode=1, the italic correction \/ will have an effect inside math mode. Also note that if one uses a command, like \(\overline{f}\), then \/ has to be added inside the braces, so only \(\overline{f\/}\) works as intended. So this example works as intended:

%! TEX program = lualatex
\documentclass{article}

\usepackage{fontspec}
\usepackage{unicode-math}

\setmainfont{Libertinus Serif}
\setmathfont{Libertinus Math}

\mmathitalicsmode=1

\begin{document}
Some text interlaced with an \(f\/\) here. Again with an overline \(\overline{f\/}\) here.
\end{document}

working italic correction