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}

\texorpdfstring{math}{something for bookmarks}– Ulrike Fischer Aug 29 '21 at 20:35\texorpdfstring{math}{something for bookmarks}, it does not look like a title of a section. Themathgoes 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\ensuremathtakes 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\section{\texorpdfstring{math}{something for bookmarks}}? – Archisman Panigrahi Aug 29 '21 at 20:42subfigurepackage is badly deprecated. Don't use it. Instead, use thesubfigpackage if the document employs one of therevtexclasses. – Mico Aug 30 '21 at 04:18