It’s an awfully simple rule: Don’t put words (of more than one letter) in pure math mode. This should be carved into the monitor of every mathematician and (particularly) computer scientist who ever wrote a paper in LaTeX. Don’t use math mode for words. Don’t (don’t you dare) use math mode for italics.

Why not?

The spacing is wrong. It’s usually only slightly, subtly wrong. But around an ‘f’, it’s grotesque. The reason is that in math mode TeX assumes individual letters represent individual variables, so it doesn’t use the kerning information that would otherwise tell it to close up the spacing around the ‘f’, since its ascender and descender stick out sideways. This behaviour is fine if the ‘f’ is a function variable, but it doesn’t work in ‘infold’, for instance.

Aren’t you being a bit picky?

Nope. I have in front of me page 307 of Type Theory & Functional Programming, which contains a function definition beginning in f old f st… or possible inf old f st, or (as in fact intended) infold f st, where infold is the function name, f is a function argument, and st is a state argument. The link takes you to an online PDF copy, go check it out. I’ll wait.

See it? If you look closely you might notice some weird spacing on the right-hand-side also — it would be truly picky to call that out, but the oddity on the left really interferes with the interpretation. (Why that page? It happened to come out on top of a signature as I was folding the book up for binding. And 307 is a nice number, don’t you think?)

What should it look like then?

Simple answer: use \mathit{} and \mathrm{} to get properly spaced words, italicised or roman, in math mode. (Thanks Tom for the reminder.)

Slightly more complicated and pedantic answer: it’s worth carefully considering whether you need italics at all. Traditionally these are used for variable quantities or entities; a function variable f which can take many values, a state variable st likewise (although I’d prefer s), and so on. It’s flatout wrong to use italics for well-known functions like sine and cosine, which is why LaTeX provides primitives \sin and \cos which typeset these in upright roman. So if you’re defining a function “infold”, which will always have the same definition, it might make sense to put that in roman too. Another case which crops up often (in the same line of TT&FP, for instance) is an equality symbol subscripted with ‘df’ or ‘def’ or similar, for “definitional”. Here there’s really no reason to use italics at all, and of course the spacing is again messed up by the ‘f’.

All right, now I am being picky.

Can I go now?

Yes yes, run along.

Oh, one more thing. I don’t mean to pick on Simon Thompson, who after all has written a textbook that I just downloaded and printed and expect to learn quite a lot from. I use that example because it shows that it’s not just students writing term papers who do this stuff, it crops up also in books with editors, that get published and that people pay money for. And it’s so easy to avoid, once you know there’s a problem. So do try, please? You’ll do wonders for my blood pressure.