Sie sind hier

How to make mathematics bold in headings

Bild von Markus Kohm

Auf Deutsch: Wie man Mathematik in Überschriften fett setzt

KOMA-Script normally makes text in headings bold. However, this does not apply to mathematics in headings. The reason for this is that font markings in mathematics often have a certain meaning. For example, a normal a may stand for a variable, while a bold a may stand for a vector.

However, via the font interface of KOMA-Script it is very easy to add the font command \boldmath to all headlines and thus select the bold version of the math fonts:

\documentclass{scrartcl}
\usepackage{blindtext}
\addtokomafont{disposition}{\boldmath}
\begin{document}
\tableofcontents
\section{Variable $a$ and Letter a}
\blindtext
\subsection{Variable $b$ and Letter b}
\blindtext
\subsubsection{Variable $c$ and Letter c}
\blindtext
\paragraph{Variable $d$ and Letter d}
\blindtext
\subparagraph{Variable $e$ and Letter e}
\blindtext
\end{document}

As you can see, the disposition element, whose font setting has been extended by \boldmath with \addtokomafont, is not only used for all headlines, but also for the table of contents entries of the section level by default.

However, the problem with \boldmath is that not all mathematical symbols are covered by the normally available bold version of the math fonts:

\documentclass{scrartcl}
\usepackage{blindtext}
\addtokomafont{disposition}{\boldmath}
\begin{document}
\tableofcontents
\section{The Sum $\sum_{n=0}^{\infty}$ and the Character $\Sigma$}
\blindtext
\end{document}

Here, the character Σ but not its use as a sum character is bold. On the other hand, the limits of the summation character are bold. Whether this is actually a disadvantage in terms of representation is a matter of dispute. I actually like the non-bold sum sign very much.

But if you like, you can also use amsopn to define an alternative sum operator, which then also uses the bold sigma:

\documentclass{scrartcl}
\usepackage{amsopn}% or amsmath or mathtools
\usepackage{blindtext}
\addtokomafont{disposition}{\boldmath}
\DeclareMathOperator*{\Sum}{\Sigma}
\begin{document}
\tableofcontents
\section{The Sum $\Sum_{n=0}^{\infty}$ and the Character $\Sigma$}
\blindtext
\end{document}

However, this is not more beautiful.

Another possibility would be to use \pmb. However, this command is not available as a font switch, but only as a command with an argument. The three letters stand for: poor man's bold. They already make it clear that the quality to be achieved is rather limited. In any case, the command must unfortunately be inserted into the heading itself. This already causes a problem on the subsection level, because you want to have the bold result in the headline, but not in the table of contents. The optional argument of the outline commands offers a remedy:

\documentclass{scrartcl}
\usepackage{amsbsy}% or amsmath or mathtools
\usepackage{blindtext}
\addtokomafont{disposition}{\boldmath}
\begin{document}
\tableofcontents
\section{Ein Beispiel}
\subsection[{The Sum $\sum_{n=0}^{\infty}$ and the Character $\Sigma$}]
{The Sum $\pmb{\sum}_{n=0}^{\infty}$ and the Character $\Sigma$}
\blindtext
\end{document}

But also on section level the use of \pmb can become problematic, namely when using page style headings. In this case, the sum sign in the column title would be bold. If the optional argument of \section were used, as shown in the previous example for \subsection, in order to not make the summation character bold in the column title, the summation character would not be bold in the table of contents either. Here, KOMA-Script helps by allowing you to choose where to use the optional argument. It is even possible to specify different values for table of contents and column title. However, this possibility must first be activated via option headings:

\documentclass[headings=optiontotocandhead]{scrartcl}
\usepackage{amsbsy}% or amsmath or mathtools
\usepackage{blindtext}
\addtokomafont{disposition}{\boldmath}
\pagestyle{headings}
\begin{document}
\tableofcontents
\section[head={The Sum $\sum_{n=0}^{\infty}$ and the Character $\Sigma$}]
{The Sum $\pmb{\sum}_{n=0}^{\infty}$ and the Character $\Sigma$}
\Blindtext[5]
\end{document}

The problem is that if you change the font of the table of contents entry, for example, you might have to change all \section statements. But this can be automated as well:

\documentclass{scrartcl}
\usepackage{amsbsy}% oder amsmath oder mathtools
\usepackage[automark]{scrlayer-scrpage}
\usepackage{blindtext}
\addtokomafont{disposition}{\boldmath}
\newcommand{\usearg}[1]{#1}
\DeclareRobustCommand*{\sectionpmb}{\pmb}
\AfterTOCHead{\DeclareRobustCommand*{\sectionpmb}{\pmb}}
\KOMAoption{onpsinit}{\DeclareRobustCommand*{\sectionpmb}{\usearg}}
\pagestyle{headings}
\begin{document}
\tableofcontents
\section{The Sum $\sectionpmb{\sum}_{n=0}^{\infty}$ and the Character $\Sigma$}
\Blindtext[5]
\end{document}

In this case, the new command \sectionpmb is used instead of \pmb directly in the heading. This is defined variously in the document preamble using two different configuration options of KOMA-Script. The basic definition is:

\DeclareRobustCommand*{\sectionpmb}{\pmb}

This is used in the heading itself, where it provides the bold sum character. If, on the other hand, you did not want a bold sum symbol in the headings, you could use:

\DeclareRobustCommand*{\sectionpmb}{\usearg}

The code line

\AfterTOCHead{\DeclareRobustCommand*{\sectionpmb}{\pmb}}}

ensures that \sectionpmb is also used in all directories. For example, if you change the font for section entries in the table of contents to the basic font using:

\setkomafont{sectionentry}{}

you don't want a bold sum symbol anymore and you change it as well:

\AfterTOCHead{\DeclareRobustCommand*{\sectionpmb}{\usearg}

To bring the automatism into the header and thus the page style, scrlayer-scrpage is used here. Its basis package scrlayer allows to execute commands with the onpsinit option every time a page style is used. This way, you can use

\KOMAoption{onpsinit}{\DeclareRobustCommand*{\sectionpmb}{\usearg}

make sure that \sectionpmb within the page style does not use \pmb either.

An alternative to using scrlayer-scrpage would have been to redefine \sectionmark after choosing the page style:

\documentclass{scrartcl}
\usepackage{amsbsy}% or amsmath or mathtools
\usepackage{blindtext}
\newcommand{\usearg}[1]{#1}
\DeclareRobustCommand*{\sectionpmb}{\pmb}
\AfterTOCHead{\DeclareRobustCommand*{\sectionpmb}{\pmb}}
\addtokomafont{disposition}{\boldmath}
\pagestyle{headings}
\let\origsectionmark\sectionmark
\renewcommand*{\sectionmark}[1]{%
  \DeclareRobustCommand*{\sectionpmb}{\usearg}%
  \origsectionmark{#1}%
}
\begin{document}
\tableofcontents
\section{The Sum $\sectionpmb{\sum}_{n=0}^{\infty}$ and the Character $\Sigma$}
\Blindtext[5]
\end{document}
Comments for "How to make mathematics bold in headings" abonnieren