Tell me more ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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)?

share|improve this question
4  
Note that the weight of a character usually has mathematical meaning: $a$ is not the same as $\bm{a}$ (the package bm provides the command). If there are math formulas in titles, it would probably be best to avoid having them in boldface to begin with. – egreg Jan 17 '12 at 15:54
As people who frequently work with vectors, my friend and I are both quite familiar with notations which use boldface as a syntactic indicator. However, if working in a discipline where there is no particular use of boldface, the similarity of entities in the section heading to entities in the prose should be sufficient to suggest that the boldface does not serve to describe a different mathematical object, in which case uniformity of typesetting would be a greater desideratum than mitigating the (marginal) risk of confusion. – Niel de Beaudrap Jan 17 '12 at 16:11

2 Answers

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*.

share|improve this answer
Will this work if there is a mixture of maths and text? \section{On euler's equation, $e^{i\pi}+1=0$} – Seamus Jan 17 '12 at 16:55
1  
@Seamus Yes, of course. :) \boldmath is a declaration, not a command with arguments. When the section's title is typeset, it's in a group, so the declaration loses its effect afterwards. – egreg Jan 17 '12 at 17:06

Well, it is possible to do this automatically, but here is a simpler "semi-automatic" solution. Note that \section has two arguments: the mandatory one sets section title, and the optional one (if present) sets the table of contents entry. Here we use \boldmath in the mandatory argument, but not in the optional one. Note also that bold math is not upright, as you want:

\documentclass{article}
\begin{document}
\pagestyle{empty}
\tableofcontents
\section[First: $a=b$]{First: \boldmath{$a=b$}} 
\end{document}

enter image description here

Actually, \boldmath does not look bad in TOC either:

\documentclass{article}
\begin{document}
\pagestyle{empty}
\tableofcontents
\section{First: \boldmath{$a=b$}} 
\end{document}

enter image description here

I personally like the second solution better: here math blends with the text both in the section title and TOC.

share|improve this answer
Good point about the section headings in the table of contents; but that will probably vary with different styles (e.g. in the case of my friend's thesis, apparently they aren't in boldface). For article.cls, the subsection headings in the table of contents aren't in boldface either. Having an automatic approach which is independent of documentclass and section-level would be more in the spirit of good LaTeX-artisanship. – Niel de Beaudrap Jan 18 '12 at 14:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.