120

In math mode, TeX assumes "hidden multiplication" (so that two variable names put nearby have invisible multiplication between), so that, AFAICT, expressions like $ABC$ are rendered with small distances between letters.
Now, what to do if I have a two-letter variable name, like for instance TP or FN (true positive or false negative)? Leave as they are? Put them in \text? Yet in the first option they will look like T*P or F*N and in the second one they will differentiate from one-letter symbols.

In optics, the 2-letter variable NA is used for numerical aperture.

3
  • 3
    I think that for a two-letter variable name, you should use an upright font to make it clear that it is not a product of two variables. Nov 30, 2010 at 18:50
  • 2
    @Jukka: I think it depends. In this case I'm not sure if TP is a variable name; if not, then I'd say an upright font is indeed the better choice. I myself don't use two letter variables, but if I would, then I'd probably use the math italic font. Nov 30, 2010 at 18:53
  • 1
    \mathrm{TP} can be used for an upright font Aug 23, 2020 at 6:29

2 Answers 2

96

You would write \mathit{TP} or \mathit{FN}. If you're going to do this frequently, you can make macros for them.

\newcommand\TP{\mathit{TP}}
\newcommand\FN{\mathit{FN}}
13
  • 11
    +1. However, I much prefer the convention that entities with multicharacter names be typeset in roman, not italic. \mathit is good for stuff like “the triangle TUV”, though. Nov 28, 2010 at 14:21
  • 4
    If using \mathit you should add \ensuremath
    – Seamus
    Nov 28, 2010 at 14:43
  • 16
    @Seamus: I disagree. When writing mathematical material, I find it best to make that obvious in the source by explicitly adding the math shift characters (or their equivalents).
    – TH.
    Nov 28, 2010 at 16:23
  • 12
    @Seamus — My opinion vacillates on this. My current theory is that macros that are to be used in math mode should still require explicit markup to show they're "maths entities": e.g., I think where $\RE$ is the Reynolds number is slightly better. Nov 28, 2010 at 16:25
  • 2
    @Seamus: It's a visual indicator that you're typesetting math. In many cases, it works out to one extra character. To take Will's example, where \RE\ is the reynolds number seems worse to me. Still, \ensuremath works and there's no harm in having it.
    – TH.
    Nov 28, 2010 at 18:24
35

I guess that the best solution is to define a macro with manually adjusted negative space, e.g.

\newcommand\TP{T\!P}

or with \hspace{-0.1em} instead of \!. You can also use the \ric command from this answer of mine to remove the space after the T. (Then you won't have to guess the amount of negative space, but the result is not always satisfactory.)


As there's been some debate about this answer, let me provide more detail:

It is not the case that TeX puts space between the letters in math mode, but after each letter it puts the italic correction for the letter. There are ways to see what's happening, and both are a bit steep.

First possibility: On a console, run

tex '\tracingall $TP$ \bye'

If you are on a unix like system, better run

tex '\tracingall $TP$ \bye' | sed -n '/mathon/,/mathoff/p'

Then in the terminal output you'll find the lines

...\mathon
...\teni T
...\kern1.3889
...\teni P
...\kern1.3889
...\mathoff

The \tracingall command is telling TeX to, well, leave a trace of everything it's doing. The first 3 of these lines tell you the following: Math mode is entered, the letter T in font \teni (10pt math font cmmi10) is typeset, and then a kern of 1.3889(pt) is put after the T. This is exactly the italic correction of the T. How do I know this? On a unix system that's easy: Run

tftopl $(kpsewhich cmmi10.tfm) | grep 'CHARACTER C T' -A3

(tfm means "TeX font metric") and you'll get the terminal output

(CHARACTER C T
   (CHARWD R 0.584376)
   (CHARHT R 0.683332)
   (CHARIC R 0.13889)

This tells you the following about the character T in the font cmmi10: It has a width of 0.584376, a height of 0.683332 and an italic correction of 0.13889, all measured in pt.

The same applies to the lines above starting with ...\teni P; the letter P has the same italic correction, and then mathmode is turned off. Though this looks convincing, it doesn't prove that the \kern1.3889 provided by \tracingall comes from the italic correction. If you want to be fully convinced, then there is no other choice than to read Appendix G of the TeXbook really extremely carefully, which I regard the steeper path.

Second possibility:

Read Appendix G of the TeXbook. Unfortunately, this is not exactly what I'd call easy reading. You get a first approximation of the insertion of the italic correction on page 441:

We frequently need to execute a subroutine called “Set box x to the so-and-so field in style such-and-such.” This means (a) ... (b) if the field contains a symbol, x is set to an hbox containing that symbol in the appropriate size, and the italic correction for the character is included in the width of the box; ...

In the current circumstances, e.g. the letter T is such a symbol that is put into the box x, together with its italic correction. However, this is not the full truth. There is one circumstance where TeX doesn't insert the italic correction: In Rule 17 on page 445 it says

If the symbol was not marked by Rule 14 above as a text symbol, or if \fontdimen parameter number 2 of its font is zero, set δ to the italic correction; otherwise set δ to zero.

We don't have to care about Rule 14 and text symbols. Why? One important feature of a math font is that its \fontdimen parameter number 2 is zero. For cmmi10, you can convince yourself by typing

tftopl $(kpsewhich cmmi10.tfm) | grep FONTDIMEN -A2

which yields the output

(FONTDIMEN
   (SLANT R 0.25)
   (SPACE R 0.0)

and you see that the second parameter SPACE is indeed zero. This makes sense: As every novice in TeX and friends has to learn, spaces don't get typeset in math mode.

18
  • 5
    I don't think it's italic correction between the letters — the math font is an entirely separate font with different inherent spacing. Using \mathit is the correct approach here. Nov 28, 2010 at 16:23
  • 1
    @Will: Probably you didn't expect this when you posted this comment, but it got 5 upvotes so far although it is incorrect; see also the edit to this post of mine. (It even got me one downvote; although I don't care about the rep, I don't think that this answer deserves a downvote.) I don't deny that there are reasons for using \mathit (see my comments to TH's answer), but I do think that the approach is not entirely correct here. Nov 28, 2010 at 21:05
  • 1
    I don't think you're correct about the italic correction. See rule 14. In particular $TP$ should have two Ord atoms. The rule is applicable since the nucleus of the first is a symbol, the subscript and superscript are empty, the next item is an Ord, and its nucleus is a symbol in the same family. The first Ord is marked as a text symbols. The font's kern information is used to insert a kern between the two Ords. On to Rule 17. Typeset the nucleus in the current style. Delta is set to 0 since it was marked. No italic correction is inserted. On to Rule 18 which has nothing to do.
    – TH.
    Nov 28, 2010 at 22:27
  • 2
    The space is at my opinion the italic correction. The interesting question is why it is not inserted when you use \mathit. This is answered in Appendix F: fontdimen 7 (extra space) of cmmiXX is 0pt and "this is the mark of a font that is intended only for mathematical typesetting; the rules in Appendix G state that the italic correction is added between adjacent characters from such fonts." Nov 29, 2010 at 13:54
  • 2
    @TH., @Ulrike: In Rule 17 it says: "If the symbol was not marked by Rule 14 above as a text symbol, or if \fontdimen parameter number 2 of its font is zero, set $\delta$ to the italic correction; otherwise set $\delta$ to zero" (emphasis added by me). Yes, the symbol T was marked as a text symbol, but it is from a math font, i.e., \fontdimen2 is 0. Nov 29, 2010 at 14:04

You must log in to answer this question.