在 \section[]{} 上使用 \nameref{} 会打印 [] 中的内容,而不是 {} 中的内容。为什么?

在 \section[]{} 上使用 \nameref{} 会打印 [] 中的内容,而不是 {} 中的内容。为什么?

因此要澄清一下。

这与\hyperref包裹有关。

我有\section[Introduction (Fin)]{Introduction} \label{Introduction}

当我然后去as stated in \nameref{Introduction}...

输出是as stated in Introduction(Fin)...

我想要输出as stated in Introduction...

我该如何实现?我需要目录的方括号,所以我不能直接删除它。

我希望即使没有适当的 MWE,我的意思也能被清楚地表达出来。

谢谢!

答案1

这是设计使然。你可以用不同的方法来实现:

\documentclass{article}
\usepackage{hyperref}

\NewDocumentCommand{\toconly}{m}{\ifintoc#1\fi}
\newif\ifintoc
\makeatletter
\pdfstringdefDisableCommands{\let\toconly\@gobble}
\makeatother

\begin{document}

\intoctrue
\tableofcontents
\intocfalse

\section{Introduction\toconly{ (Fin)}}\label{intro:fin}

\section{Introduction\toconly{ (egreg)}}\label{intro:egreg}

In section~\nameref{intro:fin} we say something.

\end{document}

在此处输入图片描述

相关内容