I want to use suggestive variable and function names in math like the in the following:

result = f(input)


accumulator = sum(inputs)

I want the formula to stand out in relation to the surrounding text. So if I use the following:

\(\mbox{result} = F(input)\)

it doesn't work because then "result" looks just like the normal surrounding text, while "F(input)" is italicized in math mode. So how can I make the "result" be also italicized correctly and consistently. Maybe I shouldn't use math mode at all but just normal mode and italicize the whole? But I intend it to be a logical unit within the text.

2 Answers 2


I would probably use bold-upright for multi-letter names so \mathbf{result}=f(\mathbf{inputs}) you don't want to use math-italic for multi-letter names, the spacing is all wrong, but you could use text italic so:\mathit{input}

Depending on the document type you have other ways of making equations stand out from the surrounding text, different offset, or box them, or add colour or....


Assuming that "result" and "input" occur several times in the document, you could define the macros


and then use them in math expressions such as

$\Result = f(\Input)$

but also in running text without having to switch to math mode first.

If you want to change the look of the variable names from italics to upright, say, you'd only have to change the \mathit instructions in the definitions to \mathrm, and the change would show up everywhere in the document.

At any rate, I wouldn't use \mbox in the definitions of the macros, as doing so "freezes" the size (at \textstyle sizing) and thus precludes the easy of the variable names in subscripts, where you'd want \scriptstyle (or even \scriptscriptstyle) sizing.

  • 1
    Why go into math mode via \ensuremath{} only to go back to text mode via \text{}? Aug 14, 2012 at 14:49
  • What's wrong in using \mathit{result} instead of that complicated construction? This will ensure italics, while your macro, if used when the current font is italic, will produce upright text.
    – egreg
    Aug 14, 2012 at 14:50
  • @PeterGrill - the idea was to make the \Result and \Input macros work equally well in text mode and math mode, so that the user won't have to remember to switch into math mode when the variable names are used in running text.
    – Mico
    Aug 14, 2012 at 14:54
  • @egreg -- Excellent point about \emph generating an undesirable effect if the current mode happens to be italics (as could happen in the statement of a theorem). I'll change the code to correct this potential pitfall.
    – Mico
    Aug 14, 2012 at 14:55
  • 1
    @Mr.Roland -- If the expression you need to typeset is indeed an equation, as in \Result = f(\Input), it's best to use mathmode explicitly: doing so will not only generate math-appropriate amounts of whitespace around the = symbols automatically but also take care of math-appropriate (i) spacing around the parentheses and (ii) line breaking methods. Separately, to ensure that any variable names are always set in upright-roman mode, use \mathrm in the definitions of these variable names.
    – Mico
    Aug 14, 2012 at 15:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .