LaTeX 标题中使用 \bm 命令与 hyperref 的冲突

问题

当使用 hyperref 宏包时,在标题中使用 \bm 为数学符号加粗会出现错误

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

\begin{document}

\section{$\bm{x^2}$}

\end{document}

报错信息为

ERROR: TeX capacity exceeded, sorry [input stack size=5000].

原因是,使用 hyperref 创建的书签信息中不能含有特殊格式。

解决方法

有如下的几种解决方法

  1. 使用标题的可选项
    \section[$x^2$]{$\bm{x^2}$}
  1. 使用 hyperref\texorpdfstring 命令
    \section{\texorpdfstring{$\bm{x^2}$}{$x^2$}}
  1. 使用 hyperref\pdfstringdefDisableCommands 命令抑制命令作用在PDF字符串上
    \documentclass{article}
    \usepackage{bm}
    \usepackage{hyperref}
    \pdfstringdefDisableCommands{%
    \renewcommand*{\bm}[1]{#1}%
    % any other necessary redefinitions 
    }

    \begin{document}
    \section{$\bm{x^2}$}
    
    \end{document}

最后一种方法使用起来比较方便,因为不需要改变正文。


参考信息

posted @ 2016-12-13 11:24  wenbosheng  阅读(4065)  评论(0编辑  收藏  举报