# How to add mathcal to section titles?

I am currently using the following code to print the section and subsection in the header.

\pagestyle{fancy}
\fancyhf{}
\renewcommand{\footrulewidth}{0.5pt}
\rfoot{\textit{Page \thepage}}



However, if I try to use \mathcal in the section titles, it causes an error. How do I get around this?

• How does this differ from your earlier question: tex.stackexchange.com/q/533524 ? – barbara beeton Apr 3 at 20:42
• Put \protect before \mathcal when the latter is used in a section (or similar) heading. – barbara beeton Apr 3 at 20:43
• @barbarabeeton it doesn't, but no one answered my previous question – Manj Apr 3 at 21:38
• Suppose the heading is \section{Properties of \mathcal{S}_n}. Where would I add \protect? – Manj Apr 3 at 21:45
• \section{Properties of \protect\mathcal{S} ... – barbara beeton Apr 3 at 22:02

LaTeX will define \leftmark and \rightmark for you, don't force it.

\documentclass{article}

\usepackage{lipsum} % for mock text

\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhf{}
\renewcommand{\footrulewidth}{0.5pt}
\fancyfoot[R]{\itshape Page \thepage}

\begin{document}

\title{title}
\author{me}

\maketitle

\section{Test section}

\subsection{Test subsection $\mathcal{A}$}

\lipsum[1-20]

\end{document}