章节标题内的复杂数学表达式会产生错误 TeX 容量超出,抱歉

章节标题内的复杂数学表达式会产生错误 TeX 容量超出,抱歉

TeX capacity exceeded, sorry [input stack size=5000]我收到以下 .tex 文件第 47 行的错误。

每当节标题中有复杂的数学表达式时,我都会收到这样的错误。此类表达式在正文中编译成功,但在标题中编译失败。如何修复此问题?

这是我的.tex 文件。

\documentclass[aps,prb,amsmath,amssymb,floatfix,twocolumn,amsmath,superscriptaddress,twocolumn,nofootinbib,tighten]{revtex4}
\usepackage{multirow}
\usepackage{subfigure}
\usepackage{color}
\usepackage{mathrsfs}
\usepackage{hyperref}
\usepackage{physics}
\usepackage[normalem]{ulem}
\usepackage{bm}
\newcommand{\pg}[1]{\textcolor{red}{#1}}

\usepackage{amssymb}   % for math
\usepackage{amsmath}
\renewcommand\vec[1]{\ensuremath\boldsymbol{#1}} % bold font for vectors

\usepackage{amsfonts, relsize, color}
\usepackage{graphics}
\usepackage{graphicx}
\usepackage{subfigure}
\usepackage{hyperref}
\usepackage{color}
\usepackage{comment}
\newcommand{\expect}[1]{#1}
\newcommand{\ig}{\includegraphics}

\begin{document}

\title{Title}

\maketitle

\section{Introduction}

Some math expressions like this works $\mathcal{A}_{ij}$ when inside titles of the sections.

But complicated expressions containing $\bra{}$, $\ket{}$, or $\langle$ or $\rangle$ inside section or subsection does not work.

\onecolumngrid
\appendix

\section{Some math expressions like this works $\mathcal{A}_{ij}$ when inside title}

Here it works $\bra{\frac{\partial}{\partial \vec{k}} u_{\vec{k}}} \tilde{\vec{P}}(\vec{k}) \ket{u_{\vec{k}}}$, but this does not work when inside section's title.

%The following fails to compile

\section{Calculation of $\bra{\frac{\partial}{\partial \vec{k}} u_{\vec{k}}} \tilde{\vec{P}}(\vec{k}) \ket{u_{\vec{k}}}$}

\end{document}

答案1

对于章节标题,必须使用\texorpdfstring(由提供hyperref)作为书签(无数学符号)和目录。

(如果不需要书签,请参见本答案的末尾。)

\texorpdfstring有两个参数:第一个是普通的 TeX 代码(用于标题和目录),第二个是字符串,可以用来替换书签中的 TeX 代码。

https://tex.stackexchange.com/a/180269/161015以获得更完整的解释。

C

(使用revtex4-2并简化重复包的序言。)

\documentclass[aps,prb,floatfix,twocolumn,amsmath,superscriptaddress,twocolumn,nofootinbib,tighten]{revtex4-2}

\usepackage{amsmath,amssymb} % math symbols
\usepackage{bm} % bold math font
\usepackage{graphicx} %
\usepackage{comment} % 
\usepackage{textcomp} % 

\usepackage{xcolor} % 

\usepackage{multirow}
\usepackage{subfigure}  
\usepackage{mathrsfs}   
\usepackage{physics}
\usepackage[normalem]{ulem}

\newcommand{\expect}[1]{#1}
\newcommand{\ig}{\includegraphics}

\newcommand\vecx[1]{%
\texorpdfstring{\bm{\vec{#1}}}{}} % bold font for vectors  <<<<<<<<<<<<<<

\usepackage{hyperref}

\begin{document}

\title{Title}

\maketitle


\section{Introduction}

Some math expressions like this works $\mathcal{A}_{ij}$ when inside titles of the sections.

But complicated expressions containing $\bra{}$, $\ket{}$, or $\langle$ or $\rangle$ inside section or subsection does not work.

\onecolumngrid
\appendix

\section{Some math expressions like this works $\mathcal{A}_{ij}$ when inside title}

Here it works $\bra{\frac{\partial}{\partial \vecx{k}} u_{\vecx{k}}} \tilde{\vecx{P}}(\vecx{k}) \ket{u_{\vecx{k}}}$, but this does not work when inside section's title.

%The following fails to compile

\section{Calculation of 
    $\bra{\frac{\partial}{\partial \vecx{k}} u_{\vecx{k}}} \tilde{\vecx{P}}(\vecx{k}) \ket{u_{\vecx{k}}}$
}

 \end{document}

如果您不需要书签,请使用:

\newcommand\vecx[1]{%
\bm{\vec{#1}}} % bold font for vectors  <<<<<<<<<<<<<<

\usepackage[bookmarks=false]{hyperref} % supress bookmarks <<<<<<<<<<<

相关内容