3

The LaTeX2e font selection manual states

Commands defined by \DeclareTextFontCommand automatically take care of any necessary italic correction (on either side).

So running the following example

\documentclass{article}

\begin{document}

\showboxbreadth=\maxdimen
\showboxdepth=\maxdimen

f\textbf{H}f\showlists

f{\bfseries H}f\showlists

\end{document}

will produce the following relevant log

% for f\textbf{H}f
\OT1/cmr/m/n/10 f
\kern 0.77779
\OT1/cmr/bx/n/10 H
\kern 0.0
\OT1/cmr/m/n/10 f

% for f{\bfseries H}f
\OT1/cmr/m/n/10 f
\OT1/cmr/bx/n/10 H
\OT1/cmr/m/n/10 f

In certain applications, however, it is desired not to automatically insert the italic correction at all. How can I selectively/locally turn off the auto-insertion of italic correction from the \textXX{...} commands?

Ruixi Zhang
  • 9,553

1 Answers1

4

You can add \nocorr to suppress the italic correction at the beginning and/or at the end of a text command's argument:

\documentclass{article}

\begin{document}

\showboxbreadth=\maxdimen
\showboxdepth=\maxdimen
\tracingonline=1

f\textbf{\nocorr H\nocorr}f\showlists

f{\bfseries H}f\showlists

\end{document}

Prints for both hlists:

\hbox(0.0+0.0)x15.0
\OT1/cmr/m/n/10 f
\OT1/cmr/bx/n/10 H
\OT1/cmr/m/n/10 f
spacefactor 1000

From source2e.pdf (File w, ltfntcmd.dtx):

In addition to global customization of when to insert the italic correction, it is of course sometimes necessary to explicitly insert one with <code>\/</code>. It is also possible to suppress the italic correction in individual instances. For this, the command <code>\nocorr</code> is provided. The <code>\nocorr</code> must appear as the first or last token inside the braces of the argument of the <code>\text...</code> commands, at that end of the text where you wish to suppress the italic correction.

Or from usrguide.pdf, section 3.10 Font changing: text:

These are one-argument commands; they take as an argument the text which is to be typeset in the particular font. They also automatically insert italic corrections where appropriate; if you do not like the result, you can add an italic correction with <code>\/</code> or remove it with <code>\nocorr</code>. The <code>\nocorr</code> should always be the first or last thing within the <code>{<text>}</code> argument.

  • 2
    \nocorr has such a complicated definition:-) – David Carlisle Jun 03 '20 at 20:37
  • Ah yes, I forgot to check LaTeX2e for authors, where it says “… if you do not like the result, you can add an italic correction with \/ or remove it with \nocorr …” Seems like the information is quite scattered… – Ruixi Zhang Jun 03 '20 at 20:42
  • @DavidCarlisle Now I understand why it was defined that way, lol – Ruixi Zhang Jun 03 '20 at 20:46
  • @RuixiZhang Added the ursguide reference. The definition of \nocorr shows how you should not judge a macro by its definition ;-) – Phelype Oleinik Jun 03 '20 at 20:54
  • @PhelypeOleinik Wait a second… If I wrote \textXX{\nocorr\nocorr}, then \text@command{\nocorr\nocorr} expands to \check@nocorr@ \nocorr\nocorr\nocorr\@nil, then \reserved@a would be the same as \reserved@b, and \reserved@c would be \@empty. But in this case only \check@icl is set to be empty. Things get worse for \textXX{\nocorr} – Ruixi Zhang Jun 03 '20 at 22:48
  • @RuixiZhang Oh, I see, with two \nocorr then only one italic correction is switched off, whereas with one \nocorr, both are. If so, arguably the second one looks correct, since the \nocorr is both at the beginning and the end of the text. The first one is a bit odd, but that's what you get for not using the command properly ;-) (just kidding). I'll raise with the team to get more opinions... – Phelype Oleinik Jun 03 '20 at 23:27
  • @PhelypeOleinik Actually… calling \tracingall for f\textbf{\nocorr}f shows that only the starting italic correction is suppressed, while f\textbf{\nocorr\nocorr}f shows that both italic corrections are suppressed. For the macro \check@nocorr@, when user inputs two \nocorr in braces, the first \nocorr was identified as #1, the second was identified as the one in the prespecified parameter text. Looks like a very well-hidden “bug”. – Ruixi Zhang Jun 04 '20 at 01:05
  • @RuixiZhang Indeed, just using \nocorr in the seems to do what's expected (I should probably have checked :-). I don't understand what's the bug you're referring to... You mean like \textbf{{\nocorr}\nocorr}? – Phelype Oleinik Jun 04 '20 at 01:18
  • What I meant was this: If f\textbf{\nocorr}f were to be interpreted as “the user had input \nocorr both at the start and at the end of the argument”, then both italic corrections should be suppressed, but right now only the starting one is suppressed. On the other hand, f\textbf{\nocorr\nocorr}f truly suppresses both italic corrections and the two f’s are much closer. – Ruixi Zhang Jun 04 '20 at 01:27
  • @RuixiZhang Ah, I see, it inserts a single (the right one) italic correction, so there's a space between the f... Not sure about being a bug though, since f\textbf{\nocorr}f is a really weird input – Phelype Oleinik Jun 04 '20 at 01:58
  • Yep. Both f\textbf{\nocorr}f and f\textbf{\nocorr\nocorr}f are quite artificial (edge cases for sure). To support the f\textbf{\nocorr}f input, maybe the simplest change is in \text@command: Before reaching \check@nocorr@ #1\nocorr\@nil, do another check: \def \reserved@b {\nocorr} \ifx \reserved@a \reserved@b <set both ends empty> \else \check@nocorr@ #1\nocorr\@nil \fi. It’s up to the team whether this weird input should be support or not, of course :) – Ruixi Zhang Jun 04 '20 at 02:14
  • @RuixiZhang The problem is not really allowing or not. There are a lot of “weird input” cases that we do support (for instance this) because it doesn't harm. However this is a really old part of the code: the last change was 10 years ago and it was minimal. Changing these parts of the code is risky... – Phelype Oleinik Jun 04 '20 at 02:21