3

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.

Figure 1

Figure 2

My code for these is:

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

Thanks!

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

2 Answers 2

1

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} 

enter image description here

10
  • I get a bunch of errors if I include \titleformat command in my preamble. I suddenly get a missing \begin{document}. - __ -
    – MarkoP
    Commented Aug 5, 2016 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
    Commented Aug 5, 2016 at 11:51
  • I tried both with * and without and it doesn't work.
    – MarkoP
    Commented Aug 5, 2016 at 12:48
  • Even just the code I posted?
    – Bernard
    Commented Aug 5, 2016 at 13:04
  • Using siunitx and {\sisetup{detect-weight=true, detect-family=true}} finally did it. Thanks for ideas and help!
    – MarkoP
    Commented Aug 5, 2016 at 13:04
7

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}

enter image description here

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}

enter image description here


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

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

\setuphead[section][style=bold]

\starttext

\placecontent

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

\stoptext
5
  • 1
    For the non-ConTeXt solution I suggest the usage of siunitx package to typeset the inductance value
    – user31729
    Commented Aug 5, 2016 at 8:44
  • Thanks a lot for your replies. This seems neat but for some reason I can't install sectsty package. :/
    – MarkoP
    Commented Aug 5, 2016 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
    Commented Aug 5, 2016 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
    Commented Aug 5, 2016 at 13:02
  • How to use the \allsectionsfont command for bold math using unicode-math? kpfonts-otf provides a bold math font, but neither \allsectionsfont{\boldmath} nor \allsectionsfont{\mathversion{bold}} work. Commented Aug 22, 2023 at 11:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .