Spring til indhold

Introduction

This article explains how to manually adjust the style of typeset mathematics—but we’ll start with a quick reminder of the visible differences between inline and display style math.

Typeset mathematics contained inline (within) with the text of a paragraph needs to take less space than the same math typeset outside the paragraph text as standalone, display-style, material. To see this in practice, let’s explain that the equation \( f(x) = \sum_{i=0}^{n} \frac{a_i}{1+x} \) may diverge or converge depending on the value of \(x\). We can also typeset \(f(x)\) outside the paragraph in display style:

\[ f(x) = \sum_{i=0}^{n} \frac{a_i}{1+x} \]

Even a cursory glance at the previous example reveals changes in the size and formatting of math symbols, such as \(\sum\) and the placement of its limits, together with variations in size/positioning of superscripts, subscripts and fractions.

These mathematical typography issues are an interplay of typesetting algorithms built into TeX engines together with certain spacing parameters contained in math fonts. Those font parameters help fine-tune math typesetting according to the design characteristics of the math font(s) being used.

Overriding default mathematical styles

Occasionally you may want to change the default style used to typeset a piece of mathematics. For example, you might want to change inline math, such as \(f(x) = \frac{1}{1+x}\), and include it in the paragraph but typeset in display style: \(\displaystyle f(x) = \frac{1}{1+x}\), although it does impact heavily on the line spacing.

TeX engines provide several commands which can be used to override the default style in which a piece of math is typeset:

  • \textstyle: apply the style used for mathematics typeset in paragraphs
  • \displaystyle: apply the style used for mathematics typeset on lines by themselves
  • \scriptstyle: apply the style used for subscripts or superscripts
  • \scriptscriptstyle: apply the style used for second-order subscripts or superscripts

The canonical example is taken from page 142 of the TeXBook, although we've replaced $$ by LaTeX's preferred \[ and \]:

\[
a_0+{1\over a_1+
      {1\over a_2+
        {1 \over a_3 + 
           {1 \over a_4}}}}
\]

By default, this is typeset as:

\[a_0+{1\over a_1+{1\over a_2 +{1 \over a_3 + {1 \over a_4}}}}\]

The default typesetting style can be amended by using the \displaystyle command:

\[
a_0+{1\over\displaystyle a_1+
      {1\over\displaystyle a_2+
        {1 \over\displaystyle a_3 + 
           {1 \over\displaystyle a_4}}}}
\]

yielding

\[a_0+{1\over\displaystyle a_1+{1\over\displaystyle a_2+{1 \over\displaystyle a_3 +{1 \over\displaystyle a_4}}}}\]

Here’s another example which demonstrates the effect of \textstyle, \scriptstyle and \scriptscriptstyle:

\[
\begin{align*}
f(x) = \sum_{i=0}^{n} \frac{a_i}{1+x} \\
\textstyle f(x) = \textstyle \sum_{i=0}^{n} \frac{a_i}{1+x} \\
\scriptstyle f(x) = \scriptstyle \sum_{i=0}^{n} \frac{a_i}{1+x} \\
\scriptscriptstyle f(x) = \scriptscriptstyle \sum_{i=0}^{n} \frac{a_i}{1+x}
\end{align*}
\]

which renders as \[ \begin{align*} f(x) = \sum_{i=0}^{n} \frac{a_i}{1+x} \\ \textstyle f(x) = \textstyle \sum_{i=0}^{n} \frac{a_i}{1+x} \\ \scriptstyle f(x) = \scriptstyle \sum_{i=0}^{n} \frac{a_i}{1+x} \\ \scriptscriptstyle f(x) = \scriptscriptstyle \sum_{i=0}^{n} \frac{a_i}{1+x} \end{align*} \]

Here’s an example you can open in Overleaf:

\documentclass{article}
\usepackage{amsmath}
\title{Exploring math display styles}
\author{Overleaf team}
\begin{document}
\maketitle
Depending on the value of \(x\) the equation \( f(x) = \sum_{i=0}^{n} \frac{a_i}{1+x} \) may diverge or converge.

\[ f(x) = \sum_{i=0}^{n} \frac{a_i}{1+x} \]

\vspace{1cm}

Inline maths elements can be set with a different style: \(f(x) = \displaystyle \frac{1}{1+x}\). The same is true for display math material:

\begin{align*}
f(x) = \sum_{i=0}^{n} \frac{a_i}{1+x} \\
\textstyle f(x) = \sum_{i=0}^{n} \frac{a_i}{1+x} \\
\scriptstyle f(x) = \sum_{i=0}^{n} \frac{a_i}{1+x} \\
\scriptscriptstyle f(x) = \sum_{i=0}^{n} \frac{a_i}{1+x}
\end{align*}
\end{document}

 Open this example in Overleaf


Further reading

For more information see

Overleaf guides

LaTeX Basics

Mathematics

Figures and tables

References and Citations

Languages

Document structure

Formatting

Fonts

Presentations

Commands

Field specific

Class files

Advanced TeX/LaTeX