Is there any difference between quad in math mode and text mode?
Under normal conditions, using \quad
inside or outside \text
gives the same result, as far as the amount of space is concerned. I'm disregarding what happens when \text
is used in a sub/superscript, for the moment.
TeX maintains two current fonts when it's typesetting a math formula: it remembers the font that was current before the formula started and also takes note of the current math family so that math symbols which are given type 7 are typeset using the font corresponding to the current family. Note that the current math family is only saved as a number; this number will be turned into a real font only when the formula is finished and is being converted into a horizontal list.
When an instruction such as \quad
is found in a formula, it expands to \hskip1em
as usual and the em is converted into a length by examining the fontdimen 6 parameter of the current text font, so the first that was mentioned above. If \mskip18mu
were used, the em of the font attached to math family 2 would be used; but it's not.
When \text{text}
is processed in math mode, TeX executes (in a group)
\mathchoice
{\textdef@\displaystyle\f@size{text}}%
{\textdef@\textstyle\f@size{\firstchoice@false #1}}%
{\textdef@\textstyle\sf@size{\firstchoice@false #1}}%
{\textdef@\textstyle \ssf@size{\firstchoice@false #1}}%
and we're interested in the first and second arguments to \mathchoice
. The \firstchoice@false
command is just to avoid executing multiple times commands such as \label
or \stepcounter
that can possibly sneak in the argument to \text
, but it's irrelevant for the problem at hand.
For the sake of simplicity, let's assume we're in \displaystyle
(but for \textstyle
it would be the same). TeX typesets four boxes, but uses only the one resulting from
\textdef@\displaystyle\f@size{text}
This is turned into
\hbox{{\everymath{\displaystyle}\let\f@size\f@size\selectfont text}}
We have to remember that \f@size
, \sf@size
and \ssf@size
expand to the font sizes LaTeX has determined to be the current overall font size (they are 10pt, 7pt, 5pt when the size is \normalsize
in a 10pt document; they are 12pt, 8pt, 6pt when the size is \normalsize
in a 12pt document or \large
in a 10pt document; and so on). In this case the \let
does nothing, but \selectfont
is really relevant!
What does it do? It resets the current text font based on the current values of \f@encoding
, \f@family
, \f@series
, \f@shape
, \f@size
and \f@baselineskip
. In this case, since \f@size
has not changed, the same font that was current outside \text
is carried over inside it.
As a conclusion, \quad
will have the same width inside \text
as it has outside it.
If \text
is used in a first level subscript, only \f@size
changes, becoming equivalent to what \sf@size
was before, so the \quad
will use the width corresponding to the current text font, but at \sf@size
.
Of course, using \quad
outside \text
has another difference: the argument to \text
is typeset in a box, so this glue cannot be used as a break point if the formula is inline. (This was remarked by David Carlisle.)
Why the example by Przemysław Scherwentke gives different quads? When we do
\font\meta=logo10 at 20pt \meta
we're overriding the NFSS infrastructure for font selection: \meta
will become the current text font, but the values of the \f@...
macros is not changed. Therefore for the quads in
\meta $a \quad\text{META}\quad b$
the value corresponding to \meta
are used (it is the current text font). Conversely, in
\meta $a \text{\quad META\quad} b$
the determination of 1em happens after \selectfont
, so the font is reset to what it was before the \meta
instruction, because the \f@...
macros are not updated when issuing \meta
. Indeed “META” is typeset in the current text font, not using the logo font.
Here's a test.
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\font\meta=logo10 at 14.4pt
{\meta $a \quad\text{META}\quad b$}
{\meta $a \quad\mbox{META}\quad b$}
{\meta $a \text{\quad META\quad} b$}
{\meta $a \quad\text{META}\quad b$}
\newcommand{\goodmeta}{%
\fontencoding{U}%
\fontfamily{logo}%
\fontsize{14.4}{14.4}%
\selectfont}
{\goodmeta $a \quad\text{META}\quad b$}
{\goodmeta $a \quad\mbox{META}\quad b$}
{\goodmeta $a \text{\quad META\quad} b$}
{\goodmeta $a \quad\text{META}\quad b$}
\end{document}
One can see that in lines 1, 3 and 4 the word “META” is typeset in Computer Modern, while in line 2 it's in the logo
font (because \mbox
uses the current font without issuing any \selectfont
command).
In the other cases, where \goodmeta
is used, the results are identical.
In LaTeX, the definition of the macro \quad
(stated in latex.ltx
) is:
\def\quad{\hskip1em\relax}
Note that the macro works the same way in both text and math mode. (The macros \hskip
and \relax
are TeX "primitive" commands.)
Thus, as long as 1em
has the same value in text and math mode -- which will be the case if you're using a common font family and font size for math and text (which, happily, is the case for the MWE you've posted) -- you can use either variant and get the same output. You should thus feel free to use whichever variant feels most natural to you. To me, \quad\text{or}\quad
seems a bit more natural than \text{\quad or\quad}
does...
Addendum: As @PrzemysławScherwentl has demonstrated in a separate answer, it is possible -- say, through the use of a PlainTeX-type font-related instruction -- to create a setup in which the value of 1em
is not the same in math and text mode. His example thus serves as an important qualifier.
More generally, whenever you use different font families for text and math (possibly even at different sizes), you will find that the two variants do not produce the same output.
\quad
is an hskip of 1em and its definition is the same in math and text mode, however there are many differences between the two uses you give. Notably em
is a font dependent unit so the actual size depends on the fonts in use, but perhaps more importantly \text
is a box command so the use inside \text
is inside a box and will not be discarded at a line break:
\documentclass{article}
\setlength\textwidth{2cm}
\usepackage{amsmath}
\begin{document}
\noindent X\dotfill X
\noindent aaa aaa $a + \text{\quad text\quad} b$
\noindent aaa aaa $a + \quad \text{text} \quad b$
\end{document}