# Bold math in title but not in TOC

I've seen similar problems around but I haven't been able to solve mine.

Basically, I have a bold math in section title but I don't want it to be bold in TOC as in figures below.

My code for these is:

\section{L\texorpdfstring{\textsubscript{L1} = 1.2\boldmath{$H$}}{First magnet}}\label{1st_magnet}


Thanks!

• Which documentclass are you using? It would be nice if you could add a minimal working example (MWE). – Henri Menke Aug 5 '16 at 7:57
• Hi, sorry for that. I'm new to this. Anyways, I'm using book class. \documentclass[a4paper,11pt,fleqn]{book} – MarkoP Aug 5 '16 at 7:59

A solution with titlesec:

\documentclass[11pt, fleqn]{book}
\usepackage{titlesec}
\titleformat*{\section}{\bfseries\boldmath}
\usepackage[detect-all]{siunitx}
\usepackage{hyperref} % for \texorpdfstring

\setcounter{chapter}{4}

\begin{document}

\tableofcontents

\section{\texorpdfstring{$L_\text{L1} = \SI{1.2}{\henry}$}{First magnet}}
\label{1st_magnet}

\end{document}


• I get a bunch of errors if I include \titleformat command in my preamble. I suddenly get a missing \begin{document}. - __ - – MarkoP Aug 5 '16 at 11:38
• Didn't you forget the * at the end of \titleformat*{? It's very important because it's the short version of \titleformat (which requires 5 mandatory arguments in its long version). – Bernard Aug 5 '16 at 11:51
• I tried both with * and without and it doesn't work. – MarkoP Aug 5 '16 at 12:48
• Even just the code I posted? – Bernard Aug 5 '16 at 13:04
• Using siunitx and {\sisetup{detect-weight=true, detect-family=true}} finally did it. Thanks for ideas and help! – MarkoP Aug 5 '16 at 13:04

You could use the sectsty package to apply \boldmath to all sections using \allsectionsfont{\boldmath}. See how I don't have to use explicit \boldmath in the section header anymore.

Furthermore, \boldmath does not take an argument but is a font switch. To see what I mean compare \boldmath{$a$} $b$ and {\boldmath $a$} $b$.

\documentclass{book}
\pagestyle{empty}
\usepackage{sectsty}
\allsectionsfont{\boldmath}
\usepackage{hyperref} % for \texorpdfstring
\begin{document}
\tableofcontents
\section{L\texorpdfstring{\textsubscript{L1} = 1.2$H$}{First magnet}}
\label{1st_magnet}
\end{document}


As Christian suggested in the comments it is much better to use a package for typesetting units. Just like Christian I also suggest siunitx for that matter.

\documentclass{book}
\usepackage{sectsty}
\allsectionsfont{\boldmath}
\usepackage[detect-all]{siunitx}
\usepackage{hyperref} % for \texorpdfstring
\begin{document}
\tableofcontents
\section{\texorpdfstring{$L_{\text{L1}} = \SI{1.2}{\henry}$}{First magnet}}
\label{1st_magnet}
\end{document}


You can ignore this solution, but others might be interested in how to do it with ConTeXt.

\setupinteraction[state=start]
\placebookmarks[section]

\starttext

\placecontent

\startsection
[
title={$L_{\tf L1} = \unit{1.2 henry}$},
bookmark={First magnet},
reference=1st_magnet,
]
\stopsection

\stoptext

• For the non-ConTeXt solution I suggest the usage of siunitx package to typeset the inductance value – user31729 Aug 5 '16 at 8:44
• Thanks a lot for your replies. This seems neat but for some reason I can't install sectsty package. :/ – MarkoP Aug 5 '16 at 8:51
• I tried installing it but I can't run .ins file and I cannot make a local texmf tree. No idea how to do it even if I follow the steps. – MarkoP Aug 5 '16 at 11:37
• @HenriMenke I know how to add packages using MikTeX but I was getting a 404 server error so I checked that one and I synchronized it and I managed to install the package even though I did not use it finally. Thanks anyways! – MarkoP Aug 5 '16 at 13:02