随着 titlesec 包的最新更新(从 v2.14 到 v2.15),所有引用都nameref
消失了。我认为这是一个错误?
此 MWE 显示了该问题:
\documentclass{article}
\usepackage{titlesec}
\usepackage{hyperref}
\begin{document}
\section{This is my section}
\label{label:thisisthelabel}
This is my reference: \nameref{label:thisisthelabel}
\end{document}
注意:这似乎与以下报告的问题有关@currentlabelname 未正确清理。
答案1
嗯,titlesec 修复了当\label
位于 section 参数中时的情况,但当 位于外部时情况就出错了。请提交错误报告https://github.com/jbezos/titlesec/issues
\documentclass{article}
\usepackage{titlesec}
\makeatletter
\def\ttl@sanitizedlabel#1\@@\@@{%
\in@{\label}{#1}%
\ifin@
\ttl@sanitizedlabel@i#1\@@\@@
\expandafter\ttl@sanitizedlabel\@currentlabelname\@@\@@
\else % <--------- missing
\def\@currentlabelname{#1}% <---------missing
\fi}
\makeatother
\usepackage{hyperref}
\begin{document}
\section{This is my section 1}\label{label:thisisthelabel-1}
\section{This is my section 2\label{label:thisisthelabel-2}}
This is my reference: \nameref{label:thisisthelabel-1}
This is my reference: \nameref{label:thisisthelabel-2}
\end{document}