I would probably define macros that internally actually use mhchem
(which you've mentioned in your question) for these variables. For convenience one could define a macro that calls them by a key name. If I understand it correctly the variable part before the molecular formula should be typeset in italics?
For units @Joseph's siunitx
is the way to go, IMHO.
Maybe something like this:
\documentclass{article}
\usepackage{siunitx}
\usepackage[version=3]{mhchem}
\makeatletter
\newcommand*\DeclarePhysio[3]{\@namedef{#1}{\ensuremath{#2}\ce{#3}}}
\newcommand*\physio[1]{\@nameuse{#1}}
\makeatother
% \DeclarePhysio{<key>}{<var>}{<chem>}
\DeclarePhysio{FIO2}{F_I}{O2}
\DeclarePhysio{FEO2}{F_E}{O2}
\DeclarePhysio{PaCO2}{P_a}{CO2}
\begin{document}
\physio{FIO2} or \physio{FEO2} or \physio{PaCO2}
\SI{.5}{\liter\per\minute} or a standalone unit: \si{\newton\per\kilo\gram}
\end{document}
First of all, the problem presents for textual subscripts, such as those used in physics to distinguish between vectors with the same name (say a force) by a subscripted label that should go in upright type. Textual subscripts are used in many other fields.
In what follows, amsmath
is assumed.
$W_{\rm total}$
is totally wrong as it relies on a deprecated command that classes don't need to define (and indeed some don't).
$W_{\mathrm{total}}$
is the correct form of the above. Limitations: spaces are gobbled and hyphens become minus signs.
$W_{\textnormal{total}}$
uses the main roman font of the document, no matter the context; the argument is typeset as text at the correct size.
$W_{\mathup{total}}$
(with Ulrike Fischer's definition) has one advantage over \mathrm
, since it uses \familydefault
, but the same limitations.
$W_{\operatorname{total}}$
is like using a sledgehammer for killing a fly. It's the same as \mathrm
, but hyphens don't become minus signs.
$W_{\text{total}}$
might seem ideal, but it changes font according to the context, so the subscript would appear in italics in a theorem statement.
Therefore, form 3 seems the most natural. Notice that braces are not really necessary, except in case 5.
To be honest, for single words \mathrm
(or \mathup
) is more efficient, as \textnormal
uses \mathchoice
and typesets four times the subscript in different sizes. However, the overhead is almost negligible with modern machines and uniformity is to be preferred to efficiency, when it doesn't slow the workflow in a significant way.
If, for some reasons, one wants that textual subscripts are typeset in upright type, but keeping the current font family, for instance because some parts of the document use sans serif type also for math (which I don't agree with), a modified version of \textnormal
can be used:
\makeatletter
\DeclareRobustCommand{\textnormalf}[1]{% f for "keep the family
\text{\usefont{\f@encoding}{\f@family}{m}{n}#1}%
}
\makeatother
Here \f@encoding
and \f@family
are the current output font encoding and font family, as stored by LaTeX at each (text) font change; with font series m
and font shape n
we're choosing upright medium type.
Of course, a more meaningful name for \textnormalf
should be chosen according to its usage and semantics.
Best Answer
As the name implies, the commands
\textsubscript
and\textsuperscript
are used to typeset subscripts and superscripts in text mode, not in math mode. Indeed, compiling your code in the minimal documentyields the error
because
\mathit
is a math command, whereas\textsuperscript
expects its argument to be text.To typeset subscripts and superscripts in math mode, you should use
_
and^
respectively. So your code should rather be something like the following.Then the "n" and the "T" are italic, as usual math characters.