在 lualatex 中的章节或部分内使用 ref

在 lualatex 中的章节或部分内使用 ref

正如该主题的原标题所述,我想在章节名称内使用参考编号。

实际上,它是使用类似结构来引用

\section{Data related to Figure~\ref{fig:XY}}

我想要的 MWE 是:

\documentclass[11pt,twoside,a4paper]{book}
\usepackage{hyperref}
\begin{document}
\chapter{First}\label{c:First}
\chapter{I want to use ref~\ref{c:First} here }\label{c:Second}
\section{Dummy section}
\newpage
\section{Dummy section in new page}
\end{document}

我尝试过多次将此类文件运行到 LuaLaTeX 中,因为我正在实际项目中使用它。日志输出中的相关行是

LaTeX Warning: Reference `C:FIRST' on page 4 undefined on input line 16.

PDF文件生成了,但是第4页的章节名称变成了

CHAPTER 2. I WANT TO USE REF ?? HERE

我尝试查找可能的重复项,但没有找到。提前致谢。

答案1

问题在于\MakeUppercase,用于页眉的 也会转换 的参数\ref。可以定义一个受保护的宏来防止这种情况:

\DeclareRobustCommand*{\refcfirst}{\ref*{c:First}}
...
\chapter{I want to use ref~\refcfirst\ here}

相关内容