# [Tex/LaTex] Automatically typeset math in section headings in bold-face

This question is motivated by a question asked me by a friend who is working on his thesis in mathematics. His section headings occasionally contain math, which:

• he would like to be in boldface to match the rest of the section title; but
• he would like to be medium-weight when it occurs in the table of contents, as with the rest of the section title.

He was using \mathbf to make the math boldface in his section headings; this of course also made them bold in the table of contents. I gave him a simple solution which inserted code at the beginning of the table of contents, which would make \mathbf pass its arguments unchanged. Of course, \mathbf also makes its arguments upright rather than math-italics, which I would also consider less than desirable; and it has no effect on e.g. greek characters, for which you would have to use something like the \bm command of bm.sty instead. (You could play the same trick with \bm as with \mathbf in the table of contents, but having to repeatedly use different math macros for all math in section headings to me seems inelegant.)

What would be the most elegant way to automatically render all math (including non-latin characters) in bold-face for section headings, but the normal medium-weight everywhere else (including the entries of the table of contents)?

The simplest thing is to patch \@startsection and \@chapter (assuming book or report class):

\usepackage{etoolbox}
\makeatletter
% \tracingpatches
\patchcmd{\@sect}{#8}{\boldmath #8}{}{}
\let\ori@chapter\@chapter
\def\@chapter[#1]#2{\ori@chapter[\boldmath#1]{\boldmath#2}}
\makeatother


#8 is the argument to \@sect that contains the title; but \boldmath will not leak to the table of contents nor to the headers (for headers it's sufficient to use fancyhdr and issue \boldmath, if bold headers are desired).

It doesn't work with \paragraph and \subparagraph, nor with \chapter*. It shouldn't be a problem to issue \boldmath in the argument of an occasional \chapter*.