# \bm{p} in the section title or subsection title produces error?

When I do this it says (my file is named Test.tex):

./Test.tex:397: TeX capacity exceeded, sorry [input stack size=5000].
\HyPsd@@LetCommand
l.397 \subsection{Here the error occurs $\bm{p}$}

./Test.tex:397:  ==> Fatal error occurred, no output PDF file produced!
Transcript written on Test.log.


\mathbf{p} and \vec{p} works and do not produce errors when written instead of \bm above.

Some minor info: I want p bold in the title because that would represent a vector in my case. p has a subscript that I don't want bolded.

-
\protect\bm (fragile command in moving argument) – David Carlisle May 2 '14 at 13:03
Or write \subsection{Here the error occurs {\boldmath $p$}}. But a prior yoy probably want all yours maths in a section title to be bold, like the text of the section title. Then write \boldmath at the beginning of the section title and drop the enclosing brackets. – Bernard May 2 '14 at 13:06
Actually the best, in my opinion, is to redefine the section format with the help of titlesec and include \bfseries\boldmath in the global formatting. – Bernard May 2 '14 at 13:12
In my opinion the best is to not making math bold. Math alphabets have a semantic value in themselves and a normal math italic p is different from a boldface italic p. – egreg May 2 '14 at 13:22
@egreg I specifically want bold italic p in the title. I understand your concern. – Faq May 2 '14 at 13:36

The problem is not a fragile command in a moving argument, because \bm is robust. The culprit here is hyperref.

You have two ways for solving your problem:

1. type \section{A vector \texorpdfstring{$\bm{p}$}{p}}

2. add \bm to the list of commands to be neutralized when bookmarks are made

The second strategy is perhaps better:

\documentclass{article}
\usepackage{bm}
\usepackage{hyperref,bookmark}

\DeclareRobustCommand{\vect}[1]{\bm{#1}}
\pdfstringdefDisableCommands{%
\renewcommand{\vect}[1]{#1}%
}

\begin{document}
\section{A vector $\vect{p}$}

\end{document}


You'll have to live with the warning

Package hyperref Warning: Token not allowed in a PDF string (PDFDocEncoding):
(hyperref)                removing math shift' on input line 12.


though.

Defining \vect is better than using directly \bm, because it adds semantics to your commands.

-
Hey I checked that bm wasn't robust: the first line of the package is \def\bm#1#2{% \let\bm@pmb\install@mathalphabet which is fragile, but I forgot to read past the first line where it is defined later with \DeclareRobustCommand The author saved one csname to help emtex.... – David Carlisle May 2 '14 at 13:59
I'll check it out and also consider your comment on \vect. Perhaps off-topic, but perhaps it is not wise to use \bm{p} for vectors in the first place? It is rarely used, and perhaps it is too much hassle to use it? I'm scratching my head right now. – Faq May 2 '14 at 14:02
@DavidCarlisle The author of bm always uses smart tricks that sometimes outsmart him. – egreg May 2 '14 at 14:03
@LoveLearning Bold italic for vectors is required by ISO, as far as I know. Of course, mathematicians do not care. – egreg May 2 '14 at 14:05
@LoveLearning And if you change your mind about the typesetting of vectors, you just need to change one line instead of chasing through the document for \bm`. – egreg May 2 '14 at 14:13