Removing math italic correction: Should kern stay outside or go inside of subscript field

best practicesitalic-correction

Sometimes it is desirable to remove the automatic italic correction appended after a math object (e.g., any ordinary math letter, the integral sign, etc.) while in math mode. Applications include:

  1. Hendrik Vogt’s answer to Math letter's italic correction.
  2. jfbu’s answer to Bad spacing of math letters within italic text.
  3. Someone uses Computer Modern for math, but sets text in a different font. Consider this sentence: Let $f$ and $g$ be elements of a Hilbert space, and let $\langle f,g\rangle$ denote their inner-product. This sentence contains two commas (one in text, the other in math). It would be weird to see two different commas. A solution is \DeclareMathSymbol{,}{\mathpunct}{operators}{`,} which tells LaTeX to use text font for commas in math. But then $\langle f,g\rangle$ would look horrible because of the italic correction after the f. Removing such italic correction cures this problem.

The method to remove italic correction is simple: TeX does not add italic correction to a math atom if this atom has a subscript and has no superscript. So appending _{} almost does the trick. One needs to remove an additional \scriptspace because of the added subscript field.

My question is: Should \kern-\scriptspace stay outside or go inside of the subscript field? The majority answers on this site seem to be _{}\kern-\scriptspace (i.e., stay outside; this includes egreg’s use of \aftergroup). But what about _{\kern-\scriptspace}? What are the benefits and/or drawbacks?

\documentclass{article}
\begin{document}

\newcommand*\sampletext{%
  Here is some sample text with no significance.
  It tries to typeset a math $f\noic$ before a line break
  and another before period: $f\noic$.
  How about $f'\noic$?%
}

\newcommand*\noic{}

\noindent\verb|\newcommand*\noic{}|

\sampletext

\medskip

\renewcommand*\noic{_{}\kern-\scriptspace}

\noindent1.~\verb|\renewcommand*\noic{_{}\kern-\scriptspace}|
aka stay outside

\sampletext

\medskip

\renewcommand*\noic{_{\kern-\scriptspace}}

\noindent2.~\verb|\renewcommand*\noic{_{\kern-\scriptspace}}|
aka go inside

\sampletext

\end{document}

remove italic correction

Best Answer

enter image description here

\documentclass{article}

\begin{document}

\showoutput

0 $f\mathrm{x}$

1 $f_{}\mathrm{x}$

2 $f_{}\kern-\scriptspace\mathrm{x}$

3 $f_{\kern-\scriptspace}\mathrm{x}$



\end{document}

The log shows

0 Italic correction

....\OML/cmm/m/it/10 f
....\kern1.0764

1 scriptspace

....\OML/cmm/m/it/10 f
....\hbox(0.0+0.0)x0.5, shifted 1.49998

That is an empty subscript 0.5pt wide

2 (after)

....\OML/cmm/m/it/10 f
....\hbox(0.0+0.0)x0.5, shifted 1.49998
....\kern -0.5

A negative kern to back up after the subscript

3 (inside)

....\OML/cmm/m/it/10 f
....\hbox(0.0+0.0)x0.0, shifted 1.49998
.....\kern -0.5

a zero width subscript (containing the negative kern)


So somewhat surprisingly I'd say that of the last two the most natural output is the last one which produces the empty subscript of zero width.

In this case with fx cases 2 and 3 with the italic correction supressed don't look good, but that isn't the point here.