Why Do Words Run Together in LaTeX Math Mode?
At a glance
- 1. Recognize the mode
Math mode is for formulas; ordinary spaces are ignored and letters are treated as mathematical symbols.
- 2. Put prose in text mode
Use the amsmath package’s text command for words that belong inside a formula.
- 3. Check the input file
An input file is processed in the mode where it is included, so wrap prose files in text mode.
LaTeX uses different rules for mathematical notation and ordinary prose. In math mode, spaces in the source are ignored and letters are treated as mathematical symbols. That is why words can appear to run together, and why ordinary text in an input file can produce errors.
The fix is to put prose in text mode. If the words are part of a formula, use \text{...} from the amsmath package. If they are not part of the formula, put them outside the math environment.
Why the words run together
In ordinary text, LaTeX uses spaces between words. In math mode—entered with $...$, \(...\), \[...\], or a math environment—ordinary spaces in the source do not create visible spaces. For example, \[the value is x\] does not typeset the phrase as normal prose. LaTeX treats the letters as math symbols, which may look joined and will usually be italicized.
A space command can add a gap in a formula, but it does not turn words into text. Use text mode when the content is language rather than mathematical notation.
What \input does in math mode
The command \input{file} reads a file and processes its contents where the command appears. It does not automatically switch to text mode. So, if you write \input{phrase.tex} inside an equation, LaTeX processes the file’s contents as math. Plain words may run together, and text-only commands or paragraph breaks may cause errors.
If the file contains a short phrase that belongs inside the equation, wrap the input in \text{...}. Here is a complete example; save and compile it as a .tex file:
\begin{filecontents*}{phrase.tex}
is positive
\end{filecontents*}
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
x > 0 \quad \text{\input{phrase.tex}}
\]
\end{document}
The filecontents* environment writes the example phrase to phrase.tex. The amsmath package provides \text, which typesets its contents as ordinary text while keeping the surrounding expression in math mode. The input file should contain a text fragment, not a complete paragraph or another display-math environment.
For a short phrase that does not need to come from a file, write it directly:
\[
x > 0 \quad \text{for all real } x
\]
If the words do not belong inside the formula, keep them outside instead:
The value is positive when
\[
x > 0.
\]
Common mistakes
- Adding spaces between math letters: Typing
t h eor inserting math spacing commands is not a substitute for text mode. It produces spaced mathematical symbols, not normal prose. - Putting prose in an input file and expecting automatic text mode:
\inputinherits the current mode. Wrap a prose fragment in\text{...}, or include it where LaTeX is already in text mode. - Using
\textwithout loadingamsmath: Add\usepackage{amsmath}in the preamble. For a simple fixed phrase,\mbox{...}is another option, though\textis generally more suitable in formulas. - Putting a whole paragraph inside
\text: Keep text inside a formula brief. Put longer explanations in the document’s normal text, outside the math environment.
The key distinction is the content’s role: use math mode for symbols and expressions, and text mode for words. An input command can be used in either context, but its contents are interpreted according to the mode active at the point of inclusion.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.