0

I get the error TeX capacity exceeded, sorry [input stack size=5000] for the line 47 of the following .tex file.

I get such an error whenever there is a complicated math expression inside the title of a section. Such expressions compile successfully when in the body, but fail to compile when in the title. How to fix this?

Here is my .tex file.

\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}

  • 2
    try to suppress it from the bookmarks with \texorpdfstring{math}{something for bookmarks} – Ulrike Fischer Aug 29 '21 at 20:35
  • @UlrikeFischer When I use \texorpdfstring{math}{something for bookmarks}, it does not look like a title of a section. The math goes to the body. And also, I don't need bookmarks because I intend to write a paper without any content page. – Archisman Panigrahi Aug 29 '21 at 20:40
  • \ensuremath takes an argument so \ensuremath\boldsymbol{#1}is \ensuremath{\boldsymbol}{#1} so will do entirely the wrong thing if not used in math mode. delete the \ensuremath – David Carlisle Aug 29 '21 at 20:42
  • @UlrikeFischer Did you mean \section{\texorpdfstring{math}{something for bookmarks}} ? – Archisman Panigrahi Aug 29 '21 at 20:42
  • Off-topic: the subfigure package is badly deprecated. Don't use it. Instead, use the subfig package if the document employs one of the revtex classes. – Mico Aug 30 '21 at 04:18

1 Answers1

2

For section titles it must be used \texorpdfstring (provided by hyperref) for the bookmarks (no math symbols) and the TOC.

(If bookmarks are not needed see the end of this answer.)

\texorpdfstring has two arguments: the first is the normal TeX code (used in the title and the TOC), the second is a string, which can be used as replacement for the TeX code in the bookmarks.

See https://tex.stackexchange.com/a/180269/161015 for a more complete explanation.

c

(Use revtex4-2 and simplify your preamble of repeated packages.)

\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}

If you do not need bookmarks use:

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

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

Simon Dispa
  • 39,141