在运行 fancyhdr 标头时,从 \mathcal{} 中删除粗体字样会导致崩溃

在运行 fancyhdr 标头时,从 \mathcal{} 中删除粗体字样会导致崩溃

虽然我的粗体书法字母在章节标题或目录中没有问题,但当它是页眉上唯一的粗体字符时,它就不合适了。我试图删除它,结果导致了编译错误。我有一个很长的文档,其中有几个章节的标题中有 \mathcal{}。我发现第一次编译成功后,第二次编译失败了。(其他尝试纠正第一次出现的情况,目录在随后的每一章中都受到影响,因为错误的内容附加到了合法的目录条目中。)显然我在这里遗漏了一些东西,欢迎提出建议。第二次运行时编译错误的 MWE 如下:

 \documentclass[a4paper,11pt,twoside,svgnames]{book}      
 \usepackage{fancyhdr}
\pagestyle{fancy}
 \usepackage{cite,lipsum}
\usepackage{amssymb}  
 \usepackage{amsbsy,amsmath}  
%  \usepackage{hyperref} %replace LaTeX in pdf file thumbnails with something more palatable, but this features in another broken case
\usepackage[inner=25mm,outer=15mm,bottom=25mm,top=20mm]{geometry} 
   \renewcommand{\baselinestretch}{1.5}

\renewcommand{\chaptermark}[1]{%
  \ifnum\value{chapter}>0
    \markboth{CHAPTER \thechapter{}: \MakeUppercase{#1}}{}%
  \else
    \markboth{\MakeUppercase{#1}}{}%
\fi}


\begin{document}
\fancyhf{}  
  \setlength{\headheight}{30pt}  
\setlength{\headwidth}{\textwidth}   


\fancyhead[LO]{\rightmark}
 \fancyhead[RO]{\makebox[0cm][l]{\makebox[0cm][r]{\thepage}}}
\fancyhead[LE]{\makebox[0cm][r]{\makebox[0cm][l]{\thepage}}}
 \fancyhead[RE]{\leftmark} 


\frontmatter
 \tableofcontents  
\pagenumbering{arabic}


\mainmatter

% chapters
 \chapter{first chapter} 
\lipsum

\chapter{second chapter}
\lipsum

\chapter{First pesky calligraphic character in chapter  $\boldsymbol{\mathcal M}$ }

%% comment this out to allow compilation to complete and see the unwanted bold characters in running headers
   \chapter{First pesky calligraphic character in chapter  $\boldsymbol{\mathcal N}$ \chaptermark{First pesky calligraphic character ${\mathcal N}$}}  \chaptermark{First pesky caligraphic character ${\mathcal N}$}

\lipsum[4] 

\chapter{Third pesky calligraphic character in chapter  $\boldsymbol{\mathcal O}$}

\newpage  
\lipsum[4] 

%  \chapter{Second pesky calligraphic character in chapter \texorpdfstring{$\boldsymbol{\mathcal N}$}{N}\chaptermark{First pesky calligraphic character ${\mathcal N}$}}  \chaptermark{First pesky caligraphic character ${\mathcal N}$}

% Add the bibliography to the table of contents
\addcontentsline{toc}{chapter}{Bibliography}  
\bibliographystyle{plain}
\end{document}

相关内容