Tx · LaTeX & TikZ

How to Fix Ugly Spacing Around f in Math Mode

Published By the 9to5Science editorial team

At a glance

  1. 1. Check the role

    Decide whether f is a variable or a named function operator.

  2. 2. Use math notation

    Write function application as f(x), and mappings with \colon rather than spaces.

  3. 3. Choose operator styling

    For an upright named operator, use \operatorname; avoid manual spacing unless you need a specific adjustment.

The right spacing around ff in LaTeX depends on what the symbol represents. A function symbol such as ff is normally italic and is written directly next to its argument: $f(x)$. A named operator is usually upright and receives operator spacing; use \operatorname{f} for that meaning.

Typing an ordinary space in math mode does not add a visible space. So $f (x)$ and $f(x)$ generally have the same spacing. First check the notation and symbol class rather than inserting spaces by trial and error.

Function symbol or named operator?

In standard mathematical typesetting, a single-letter function name is usually treated as an ordinary math symbol. This is why expressions such as f(x)f(x), fnf_n, and f ⁣:X→Yf\colon X\to Y use italic ff. The letter identifies a function, but it is not automatically typeset like a word such as “sin.”

A named operation such as “rank” or “tr” is usually upright and treated as a math operator. LaTeX’s \operatorname command sets a name in upright text and gives it operator spacing. Use it when the intended notation is an operator, not merely to force a different gap around an italic function symbol.

A complete example

This example shows common notation for a function and an operator. It compiles with the amsmath package.

\documentclass{article}
\usepackage{amsmath}

\begin{document}
A function symbol: $f(x)$ and $f\colon X\to Y$.

A named operator: $\operatorname{rank}(A)$.

An operator named $f$: $\operatorname{f}(x)$.
\end{document}

In the first line, the italic ff is a function symbol, and the parentheses follow it as the argument notation. In the second, \colon produces the properly spaced colon used for a mapping. In the final line, \operatorname{f} deliberately changes the meaning and appearance: it makes ff an upright operator name. Use that form only if it matches your notation.

Why spacing commands often make it worse

Math mode ignores ordinary source whitespace. For example, putting a space before a parenthesis does not reliably add a visible gap. To add explicit space, LaTeX provides commands such as \, (thin space), \: (medium space), and \quad (wide space). These are useful when a mathematical convention calls for a deliberate gap, but they should not be used to compensate for a symbol being in the wrong math class.

Likewise, \! inserts a negative thin space. It can correct a known typographic issue, but using it just because f(x)f(x) looks odd may make the formula cramped or inconsistent with the rest of the document. If only one occurrence looks wrong, compare it with the same notation elsewhere and check for nearby commands, delimiters, or font changes.

Common mistakes

  • Adding ordinary spaces in math mode: $f (x)$ does not mean “put a space here.” Use a spacing command only when you have a reason to change mathematical spacing.
  • Making every function an operator: \operatorname{f} is upright and has operator behavior. It is not a general spacing fix for the usual italic function symbol ff.
  • Using text mode for mathematical symbols: \text{f} typesets text, not a math variable. For a conventional function symbol, use $f$.
  • Writing a mapping with a bare colon: Prefer $f\colon X\to Y$ to $f:X\to Y$; \colon is designed for the spacing of a mapping colon.
  • Overusing manual corrections: A local \, or \! may hide the cause and make similar formulas look inconsistent. Correct the notation or command first.

If you are typesetting a single-letter function, start with $f(x)$ and leave the spacing to TeX. If the intended symbol is an operator name, use \operatorname{...} and check that the upright style is appropriate.

References

  1. The LaTeX2e unofficial reference manual: Math formulas
  2. amsmath package documentation

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.