当使用 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}

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


参考信息

相关文章:

  • 2022-12-23
  • 2021-04-30
  • 2022-12-23
  • 2021-08-29
  • 2023-01-23
  • 2022-12-23
  • 2022-02-07
  • 2022-12-23
猜你喜欢
  • 2021-05-17
  • 2022-01-20
  • 2021-11-13
  • 2021-10-01
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
相关资源
相似解决方案