13

For my text-in-mathmode needs in LaTeX, I use \mbox. However, it does not seem to behave well in subscripts. How can I write text that adjusts its height?

$ 3 \mbox{dB} = f_{ 3 \mbox{dB} } $

compiles to

example

diabonas
  • 25,784
Tim N
  • 10,219
  • 13
  • 63
  • 88

1 Answers1

20

Use the \text macro of the amsmath package instead of \mbox for general text in mathmode. It takes care of these issues.

Note that for units in math- or textmode the use of the siunitx package is highly recommended.

Martin Scharrer
  • 262,582
  • Thanks. Should I always use \text instead of \mbox? – Tim N Mar 06 '11 at 23:01
  • @Tim: For text inside mathmode yes, but not in textmode. – Martin Scharrer Mar 06 '11 at 23:06
  • 4
    I do not quite agree, say you want to specify the radius of a circular lake, then $R_{\textup{lake}}$ would be a better choice. Why try setting it in an italic context. So for named indices I'd use \textup, one could use \mathrm or \textrm, but then what if one is using a sans serif context, so in these cases \textup (i.e. non italic text font) is better. But for general comments in math, \text is the right choice – daleif Mar 06 '11 at 23:13
  • @daleif: I didn't know about \textup which seems to be a nice alternative to \text. I was talking more about the general case in \mbox vs. \text where \text (or its friends) should always be used. – Martin Scharrer Mar 06 '11 at 23:19
  • @martin: remember use it only when appropriate, I usually recommend it for name-like indicies, for comments \text is the correct thing to use. In my (Danish) LaTeX book we have an 'evil' macro such that X_|text| equals X_{\textup}. Another reason for using \textup over, say, \mathrm is that \textup support national letters, whereas \mathrm does not. Lake in Danish is s\o{} and \o is not allowed in math. – daleif Mar 06 '11 at 23:56
  • 1
    @daleif: \textup is also not optimal; it'll be bold in a bold context. I guess \textnormal is better. – Hendrik Vogt Feb 15 '13 at 20:22
  • @Martin: Since the question is particularly about textual subscripts, I wouldn't really recommend \text here. – Hendrik Vogt Feb 15 '13 at 20:24
  • @HendrikVogt: I thought that is exactly what \text is for? – Martin Scharrer Feb 16 '13 at 09:06
  • @Martin: I wouldn't say so, \text is for text :-) such as \text{if} and \text{otherwise} in a cases environment. See also this recent question of mine. – Hendrik Vogt Feb 16 '13 at 09:15
  • @HendrikVogt: Well, textual subscripts are a form of text, aren't they? – Martin Scharrer Feb 16 '13 at 09:16
  • @Martin: Yes, they are :-) But would you want the subscript to change from upright to italic, depending on the context? At least in my field that's highly undesirable! – Hendrik Vogt Feb 16 '13 at 09:34