2

How to distinguish variables and unit symbols in LaTeX?

Should I write something like

$$222\mathrm{K}$$ instead of $$222K$$ 

and something like $$\int\;...\;\mathrm{d}\mu(x)$$ instead of the same with $$...\;d\mu(x)?$$

Is \mathrm the best way to do this?

Sigur
  • 37,330
Kutsubato
  • 23
  • 3

2 Answers2

5

A general typographic convention is that physical units should be typeset using glyphs from the upright text font. Moreover, there should be a "thinspace" between the numbers and the associated units. Thus,

$222K$

isn't correct because "K" will be typeset using a math-italic glyph, making it look like a variable named "K" rather than the abbreviation for a unit of temperature. Note that

$222\mathrm{K}$

isn't quite right either since there's no space between "222" and "K".

If you don't want to load a package that simplifies and standardizes the typesetting of numbers and their associated units, you should write

$222\,\mathrm{K}$

However, typing lots of \, and \mathrm directives (a) gets very tedious very quickly and (b) flies in the face of the design philosophy of LaTeX, which is for users to engage in little or no visual formatting and, instead, to express the meaning of the material. (Let LaTeX handle to not-so-exciting chores of translating the meaning into actual typesetting instructions.)

My recommendation is that you load the siunitx package and write

$\SI{222}{\kelvin}$

Here, \SI is a macro that takes two arguments: A number, and the associated unit(s). This setup may look like overkill if all you need to do is to typeset 222\,K. However, its superiority over visual-formatting solutions quickly becomes evident when it comes time to write, say, \SI{9.81}{\meter\per\second\squared}. Importantly, you can configure siunitx to select from various possible visual representations of \per. E.g., both math-fraction and inline-fraction styles may be chosen.

Mico
  • 506,678
0

For the units, and for the general insertion of text in mathmode, you may simply use the \text command, e.g.

$$222\text{K}$$

As for the differential inside the integral, it's usually displayed in mathmode, to my experience.

  • 3
    This is completely wrong, \text is for textual comments in displayed math. If the context is italic, the output from \text will be italic: Try \textit{test $\text{test}$ test}, units should always be upright. You could use \mathrm instead, but it is better to switch to siunitx – daleif Jan 30 '18 at 13:43