![titlesec 更新后,使用 nameref 的引用消失了](https://linux22.com/image/470473/titlesec%20%E6%9B%B4%E6%96%B0%E5%90%8E%EF%BC%8C%E4%BD%BF%E7%94%A8%20nameref%20%E7%9A%84%E5%BC%95%E7%94%A8%E6%B6%88%E5%A4%B1%E4%BA%86.png)
随着 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}