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.

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.

share|improve this question
9  
"Indent code by four spaces" would be better. :) –  egreg Dec 19 '11 at 20:58
    
Thank you. I know there is a way but always forget how is it. –  ABC Dec 19 '11 at 21:03
1  
I should read the things I write. –  ABC Dec 19 '11 at 21:09
1  
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
1  
see also this question about digits in math. –  barbara beeton Dec 19 '11 at 22:28
show 1 more comment

4 Answers 4

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!! :-)

share|improve this answer
add comment

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

\num examples

share|improve this answer
add comment
  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.

\documentclass{article}
\usepackage{kpfonts}
\begin{document}
\mathversion{boldsf}
\makeatletter
\meaning\thesection
\meaning\thepage
\meaning\@arabic
$2$
2
\thepage
\def\thepage{$\arabic{page}$}
\thepage
\meaning\thepage

\end{document}

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

share|improve this answer
5  
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
    
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. –  ABC 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
add comment

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.

share|improve this answer
add comment

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.