Should numbers inside the text be placed inside a math environment?

For example, if I am writing ...indent code by 4 spaces..., should I write it this way or ...indent code by $4$ spaces...?

Perhaps the output is the same but semantically they are not and maybe LaTeX can treat them differently in some cases. Which is the right one?

For instance, how does LaTeX treat the numbers in the counters it uses for numbering the sections or pages, etc? Does it treat them as numbers in a Math environment or as numbers inside text?

Of course, if the output can never be different in any situation, then well, it just doesn't matter.

  • 5
    That was almost a joke; but, in general, numbers up to ten or twelve which are not used as numbers in their mathematical meaning, are better spelled out in words. – egreg Dec 19 '11 at 21:09
  • 3
    see also this question about digits in math. – barbara beeton Dec 19 '11 at 22:28
  • If @barbarabeeton had not mentioned the other question I was about to. I'm voting to close as a duplicate (though this one has reasonable answers, I believe they are not actually different from the ones in the other question). – Ryan Reich Dec 20 '11 at 1:00

The answer to your question strongly depends on whether the math-mode numerals appear to be (more or less) the same as text-mode numerals, for the font you use. If the two sets of numerals happen to be exactly the same, nobody will ever be able to tell unless they have access to the source code...

However, if they differ noticeably in appearance -- say, because "oldstyle" numerals are used in text mode, which in general should not be used in mathematical expressions -- you obviously need to be careful to distinguish between the two types of numerals.

The following is an excerpt from Knuth's article "Typesetting Concrete Mathematics" (TUGBoat, 1989) [Aside: The textbook Concrete Mathematics was typeset using Concrete Roman as the text font and Euler as the math font]:

There was, however, one significant difference between typing the manuscripts for Concrete Mathematics and for The Art of Computer Programming, caused by the fact that the Euler numerals 0123456789 are distinctly different from the numerals 0123456789 in ordinary text. [...] This experience ... taught me that there is a useful and meaningful distinction between text numerals and mathematical numerals. Text numerals are used in contexts like '1776' and 'Chapter 5' and '41 ways', where the numbers are essentially part of the English language; mathematical numerals, by contrast, are used in contexts like 'the greatest common divisor of 12 and 18 is 6', where the numbers are part of the mathematics. [...] Equation numbers presented us with one of the most perplexing design questions. Should those numbers be typeset in Euler or cast in Concrete? After several experiments we hit on a solution that must be right, because it seems so obvious in retrospect: We decided to set equation numbers in an "oldstyle" variant of Concrete Roman ...

What's the upshot of all this? I'd say it's the following: even if at present you're using text and math fonts that have identical-looking numerals, you should still be willing to make the extra effort today to set those numerals that are parts of math expressions in math mode -- as long as there is a chance that you might wish to re-publish your piece one day using fonts for which the math- and text-mode numerals are no longer the same.

What, then, are instances of when you should use text-mode numerals? In addition to the examples given in the preceding quote, I'd also nominate the following: page numbers; numbers of chapters, sections etc; dates (December 25, August 1, ...), and (depending on the circumstances) equation numbers. Obviously, this short list is not meant to be exhaustive.

Addendum: I just noticed that the first two up-votes to this answer earned me my 10,000th point in the TeX.SE group. Thanks everyone!! :-)


I am always using the \num{} from the siunitx package. Here are some examples from the manual:

\num examples

  1. Numbers should always be given in $$, the single reason for this is that if you later choose a different font, which handles numbers in a different manner you will see the difference quite distinctively. (There are cases were this is not the case, for instance dates, thanks egreg)

  2. Counters have nothing to do with math-mode. You need also to set them in mathmode if using them as output tokens.

If having specific counters as \thepage or \thesection etc. you need to find out what that command does. It is up to you to make them behave as you like. See the following code which utilizes the kpfonts package.



In the output you will see what the command is expanded to, and also how to redefine it.

  • 7
    This is not true: dates should be in the text font. – egreg Dec 19 '11 at 21:02
  • I completely agree. I didn't elaborate on that! Have added. – zeroth Dec 19 '11 at 21:04
  • 1
    Yes, counters on their own have nothing to do but I was asking when LaTeX automatically uses them for numbering pages or sections. How does it treat them? For example if it uses the counters as text I don't want to be putting all numbers in math mode because then a number I am using for counting may look different from those numbering the sections or the pages. – Anna Taurogenireva Dec 19 '11 at 21:04
  • That depends on the command, i have updated my answer. – zeroth Dec 19 '11 at 21:11
  • 2
    I'd say that also page numbers should be in the main text font. But a choice depends mostly on the type of text: in a text with very little math, I'd probably typeset also "proper numbers" (in tables, for instance) as lowercase (old style), if the main font uses them. – egreg Dec 19 '11 at 21:42

My understanding is that the only time it matters is when you're using a math font like Euler that comes with its own set of digits instead of just "borrowing" its digits from the text font. And even then, the important thing is just to be consistent: you wouldn't want a document where some of the page numbers are in Euler and some are in Palatino or whatever text font you're using.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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