# When to use math mode?

In my document, the numbers inside math mode appear differently than those numbers out. Sometimes, I have numbers like "10 squared" within a paragraph, so it seems useful to use $10^2$. However, maybe on the same line, I have "10 km". The style of the 10 is different. In this case, should I also use $10$ km?

• Is there a general rule for when it is best to use math mode within a document?
• Another vote for siunitx, as suggested by uli. It properly spaces units from magnitudes. If you do have to do this manually for simple stuff, use 10\,km outside of math mode. The \, adds a half-space which is the neatest looking gap. Dec 5, 2011 at 11:11

Don Knuth touched on this topic in his article for TUGboat -- "Typesetting Concrete Mathematics". His examples don't include units (for that, the siunitx package is a good choice, as already mentioned), but the method for determining what is math and what isn't is well illustrated otherwise.

(The article is set in Knuth's Concrete fonts, and shows some of the special techniques used in setting that book. Irrelevant for this question, but interesting nonetheless.)

• I find particularly interesting the last paragraph on page 31 (ending on p. 32). Dec 5, 2011 at 15:07
• For the lazy, the last paragraph on page 31 describes the difference of numbers that are part of an english text ("see section 9") and which that are part of mathematics ("the greatest common divisor of 12 and 18 is 6") an therefor when to use '1' or '$1$' Dec 1, 2014 at 14:03
• Amazing reference, thanks! Do we know what to do with percentages (like "99 %")? I suppose same as units...? Sep 13, 2017 at 6:59

As the math font and the main text font are likely to have different looking numbers you should aim for consistency. Whenever you refer to a part of a document, e.g. chapter 4, theorem 3.4, bullet point 2, figure 9.3, table 12.1 or similar elements, stick with the same font, which is likely to be your main text font.

Whenever your talk about parts of a mathematical expression, e.g. the leading coefficient, then be consistent and use the same font as used for typesetting the formular.

In case of physical quantities I would recommend the use of siunitx that allows for a consistent application of the SI system throughout the document.

My simple rule, which is sort of like what uli and barbara beeton wrote:

Write numerals in plain text and numbers in math.

More casually, you could make the distinction that it's a numeral if it could belong (in context) in, say, an essay on literary criticism, and a number if a scientist might write it. Or with an eye towards utility, put it in math if you can imagine it being next to a plus sign.

As uli said, siuntix is recommended. I use it to typeset all numbers/values, that are not dates or something like that.

Example

\documentclass{article}

%\usepackage[default]{gfsneohellenic}% example font without math support

\usepackage{siunitx}
\sisetup{
locale=UK,
%   mode=text,% when using a font without math support
}

\begin{document}
Lorem Ipsum is simply \SI{10.5}{\kilo\meter} dummy text of the printing. Lorem
Ipsum has been the \num{2e-19} industry's standard dummy text ever since the
1500s, when an unknown printer took a galley of type and scrambled it to make a
type \SI{2,6}{\volt\per\meter} specimen book. It has survived not only five
centuries, but also the leap into electronic typesetting, remaining essentially
unchanged. It was popularised in the 1960s with the release of Letraset sheets
containing Lorem Ipsum passages, and more recently with desktop publishing
software like Aldus PageMaker including versions of Lorem Ipsum.
\end{document} Note the handling of 10.5 and 2,6 (both with . in output) and of 2e-9. The behavior of \per (in \volt\per\meter) is customizable.

This is the result for gfsneohellenic: I didn’t found a solution to write soemthing like \num{2^3}. Does anybody know if this is possible?

As said in the comments it is possible to use \num[parse-numbers=false]{2^3}. But this affects an e12 part too.

• 2^3 is a formula, rather than a number, so $$2^3$$ is the answer. Or maybe $$\num{2.6}^3$$ if you want to be fussy. Dec 5, 2011 at 15:24
• You could say \num[exponent-base=2]{e3}. Dec 5, 2011 at 15:24
• Thanks. @egreg: That could work but I can imagine a case like \SI{2,6^2e9}{\volt} where this solution would be inconvenient and inflexible (immune to \sisetup): \num{2,6}^2 \times 10^9\,\si{\volt}
– Tobi
Dec 5, 2011 at 15:44
• I can't imagine why somebody would write something like that. :) Dec 5, 2011 at 15:46
• @Aditya I suspect the old 'example code not actually used for the example output' issue. siunitx certainly knows the difference between a volt and a volt per metre. Dec 5, 2011 at 16:59

I totally agree with Don Knuth's suggestion in principle, however, in practice, it is a bit too taxing to decide whether a number belongs to the text mode or the math mode every time you write a number. Why not make them appear the same, so that $10$ or 10 does not matter? There is a package that can do this, mathastext, which did not exist when Knuth wrote that article.

I typically use mathastext to make alphanumeric letters in math mode to be the same as in the normal text. I put line this in my preamble

\usepackage[basic,italic,defaultimath,nohbar,defaultmathsizes]{mathastext}


This will apply the mathastext package conservatively, without altering other characters in the math mode.
{"ft_lang_label":"__label__en","ft_lang_prob":0.84420806,"math_prob":0.834473,"size":1431,"snap":"2023-40-2023-50","text_gpt3_token_len":399,"char_repetition_ratio":0.0721794,"word_repetition_ratio":0.0,"special_character_ratio":0.24109015,"punctuation_ratio":0.10909091,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9744531,"pos_list":[0,1,2,3,4],"im_url_duplicate_count":[null,8,null,8,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-10-03T16:31:21Z\",\"WARC-Record-ID\":\"<urn:uuid:5ab36715-c282-4e95-8a73-25caee1a55ae>\",\"Content-Length\":\"195776\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:c51c3f01-a7a3-4f10-8594-4965dcd7f15c>\",\"WARC-Concurrent-To\":\"<urn:uuid:3e34c18b-037f-4c3c-ba17-2cde324170d3>\",\"WARC-IP-Address\":\"104.18.10.86\",\"WARC-Target-URI\":\"https://tex.stackexchange.com/questions/37168/when-to-use-math-mode\",\"WARC-Payload-Digest\":\"sha1:SO4GCBNK5GT4WEMKULEI77OXEIYJC6A3\",\"WARC-Block-Digest\":\"sha1:4CQPELDQLJYWO5V3EFDMK54MIMWWLEUL\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-40/CC-MAIN-2023-40_segments_1695233511170.92_warc_CC-MAIN-20231003160453-20231003190453-00605.warc.gz\"}"}