Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
2  
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. –  Jukka Suomela Nov 30 '10 at 18:50
1  
@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. –  Hendrik Vogt Nov 30 '10 at 18:53

2 Answers 2

up vote 37 down vote accepted

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}}
share|improve this answer
6  
+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. –  Harald Hanche-Olsen Nov 28 '10 at 14:21
3  
If using \mathit you should add \ensuremath –  Seamus Nov 28 '10 at 14:43
7  
@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 '10 at 16:23
6  
@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. –  Will Robertson Nov 28 '10 at 16:25
1  
@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 '10 at 18:24

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.

share|improve this answer
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. –  Will Robertson Nov 28 '10 at 16:23
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 '10 at 22:27
1  
Continuing. Rule 2 applies for the kern that got inserted, but there's nothing more to do so we move on to the final Ord. Once again, Rule 14 applies. In this case, there is no next item in the math list so we go to Rule 17. It gets typeset in the current style. It was not marked in Rule 14, so delta gets set to the italic correction. If delta is nonzero, a kern of width delta is inserted. Rule 18 again has nothing more to do. The next item (if it exists) is the italic correction kern. It's processed in Rule 2 (by doing nothing). In the end, we should get two boxes (T, P) and 0, 1, or 2 kerns. –  TH. Nov 28 '10 at 22:36
1  
@mbq: It's quite OK that you accepted TH's answer, it has definitely some advantages. I'll add some more explanation to my answer later. –  Hendrik Vogt Nov 30 '10 at 12:08
1  
@TH.: No problem here (for the CM fonts) as there are no ligatures in cmmi, as tftopl $(kpsewhich cmmi10.tfm) | grep LIG reveals. (Try the same command with cmmi replaced by cmr.) –  Hendrik Vogt Dec 1 '10 at 8:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.