1

I am writing a dissertation and am including some mathematical terms in the titles of my subsections. To make these bold I am using the \boldsymbol command but in the subsections in the contents page they are also bold which looks odd as the rest of the text is not bold. Is there a way to make the text bold in the subsection but normal in the contents page?

Thanks in advance

\documentclass[12pt]{article}
\usepackage{graphicx}
\usepackage[svgnames]{xcolor} 
\newcommand{\plogo}{\fbox{$\mathcal{PL}$}} 
\usepackage[T1]{fontenc} 
\usepackage{fouriernc} 
\usepackage{mathtools}
\usepackage{amsthm}
\usepackage{afterpage}
\usepackage{blindtext}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{mathtools}
\usepackage{array, siunitx}
\usepackage{parskip}
\numberwithin{equation}{subsection}
\newtheorem{theorem}{Theorem}[subsection]
\linespread{1.3}
\begin{document}
\addcontentsline{toc}{section}{Introduction}
\section*{Introduction}

\section{Irrationality of $\boldsymbol{\pi}$}

\subsection{$\boldsymbol{\pi}$ is Irrational}

\end{document}
  • Simplest solution: instead of manually mark math in the sections, why not configure the sections to include \boldmath as its font settings. Then then markup does not propagate into the TOC – daleif Feb 5 '19 at 14:49
  • How do I do that? Sorry, my level of latex knowledge isn't very deep – user174579 Feb 5 '19 at 14:51
  • If you use the extended form of sectioning command like \subsection[text1]{text2}, the optional argument text1 is used for the headers (if any) and for the \tableofcontemts, while text2 in used in the body text. Hence you could use a non bold version in this optional argument. – Jhor Feb 5 '19 at 14:53
  • BTW, and off topic, a more efficient method to get bold mathematics would use the bm package. – Jhor Feb 5 '19 at 14:55
  • See the sectsty and titlesec packages. – daleif Feb 5 '19 at 14:56
1

To explicit my suggestion in the comment: with the same preamble and

\begin{document}
\tableofcontents
\section{Irrationality of $\boldsymbol{\pi}$}
\subsection[$\pi$ is Irrational]{$\boldsymbol{\pi}$ is Irrational}
\subsection[Proof that {$\sqrt[n]{p}$} is irrational, for an integer $n$ and prime $p$]    {Proof that $\boldsymbol{\sqrt[n]{p}}$ is irrational, for an integer $\boldsymbol{n}$ and prime $\boldsymbol{p}$}
\end{document}

I get: enter image description here which seems to be what you are looking for. Please notice the curly brackets arround the $\sqrt[n]{p}$.

Alas, this does not works in the same way for section, as

\section[Irrationality of $\pi$]{Irrationality of $\boldsymbol{\pi}$} 

would produce the correst section in body, but non bold \pi in toc.

Edit: following the suggestion of @daleif, buth without titlesec : load the package etoolbox and use:

\patchcmd{\section}{\bfseries}{\bfseries\boldmath }{}{}
\patchcmd{\subsection}{\bfseries}{\bfseries\boldmath }{}{}

with also \usepackage{bm} one would get (when removing everything is not needed to exemplify) the MWE:

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[T1]{fontenc} 
\usepackage{fouriernc} 
\usepackage{etoolbox}
\usepackage{bm}
\patchcmd{\section}{\bfseries}{\bfseries\boldmath }{}{}
\patchcmd{\subsection}{\bfseries}{\bfseries\boldmath }{}{}

\begin{document}
\tableofcontents
\section{Irrationality of $\bm{\pi}$}
\subsection{$\pi$ is Irrational}
\subsection{Proof that $\sqrt[n]{p}$ is irrational, for an integer $n$ and prime $p$}
\end{document}

with the same result but with much less code.

| improve this answer | |
0

Instead of wrapping all math symbols in \boldsymbol, insert the \boldmath command into your header formatting. I use titlesec and titletoc. This lets you just use math mode in your section names, and have the preamble give them the correct formatting. Otherwise, you would need to rewrite every section and subsection title whenever the formatting changes either in the title or the table of contents.

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc} % The default since 2018
\usepackage{fouriernc} 
\usepackage{mathtools} % Includes amsmath
\usepackage[english]{babel}
\usepackage{parskip}
\usepackage{titlesec, titletoc}
% To make the document an appropriate size for a MWE on TeX.SX.  Remove this
% line in your version:
\usepackage[paperwidth=10cm]{geometry}

\titleformat*{\section}{\boldmath\bfseries}
\titleformat*{\subsection}{\boldmath\bfseries}
\contentsmargin{2.55em}
\dottedcontents{section}[3.8em]{\boldmath\bfseries}{2.3em}{1pc}
%\dottedcontents{subsection}[6.1em]{}{3.2em}{1pc}

\numberwithin{equation}{subsection}
\newtheorem{theorem}{Theorem}[subsection]
\linespread{1.3}

\begin{document}
\tableofcontents

\addcontentsline{toc}{section}{Introduction}

\section*{Introduction}

\section{Irrationality of $\pi$}

\subsection{$\pi$ is Irrational}

\end{document}

Sample of headers

A couple of points unrelated to your main question.

You include many redundant packages, some more than once. A lot of the time I see this, it’s because someone copied a package list from someone else’s preamble. If you have any packages in your preamble and you don’t know why, I’d suggest you try commenting them out and see if anything breaks. If not, you can remove them. I removed all the packages from this MWE that it doesn’t actually use, but a real document might need to add back amssymb, textcomp and bm before fouriernc.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy