如何使用 nameref 选择命名定理名称作为标签引用?

如何使用 nameref 选择命名定理名称作为标签引用?

我已经在 SSCCE 中以内联方式提出了这个问题:

\documentclass[12pt,oneside,onecolumn,a4paper]{article}

\usepackage{amssymb,amsmath,amsthm}
\usepackage{imakeidx}
% NOTE: Hyperref should typically be loaded last of all the packages.
\usepackage{hyperref}

% Add a label and an index entry at the same time.
\newcommand{\idxlabel}[2]{\label{#1}\index{#2}}

\makeindex

% Various theorem environments. Only one variety included here.
\theoremstyle{plain} % just in case the style had changed
\newcommand{\thistheoremname}{}

\newtheorem{thm}{Theorem}[section] % the main one
\newtheorem*{thm*}{Theorem} % unnumberedtheorem
% there are generic theorems used to construct the environments below:
\newtheorem*{genericthm*}{\thistheoremname}

\newenvironment{namedthm*}[1]
  {\renewcommand{\thistheoremname}{#1}%
   \begin{genericthm*}}
  {\end{genericthm*}}


\title{How do I select a named theorem name as a label reference using nameref?}
\begin{document}

\maketitle
\section{This is the first section}

\begin{namedthm*}{Some Theorem}[book-I-found-it-in]
\idxlabel{my-theorem}{Some Theorem}
Here, I define a theorem I would like to refer to later. I would like the
text form to display ``Some Theorem" rather than a section or page number.

It would be nice if \idxlabel could interpret the theorem name from the
namedthm environment, but I would also like to know how to override
that and provide my own just in case.

It may need to differ from the index, because the index supports nested
terms such as Latex!Cross-referencing.
\end{namedthm*}

\section{This is the second section}

Here I would like to talk about \nameref{my-theorem} (and this should say
``Some Theorem"", ideally.

\clearpage
\printindex

\end{document}

latexmk要编译此文件,您可能应该使用类似或(我使用前者)的工具,rubber以便获取链接。问题如下:

呈现的文档

我真正想要的是那本“我在书中找到它”能够正确地拾取定理名称。我还想知道我是否可以控制那里出现的内容。我尝试移动标签语句(包括定理定义内部),但它什么也没拾取,或者只是拾取了章节标题或定理前面的内容。

我从本网站的其他答案了解到这些标签如何进入辅助文件,现在我想控制它们的显示。

答案1

\@currentlabelname在定理头后重新定义。

\documentclass[12pt,oneside,onecolumn,a4paper]{article}

\usepackage{amssymb,amsmath,amsthm}
\usepackage{imakeidx}
% NOTE: Hyperref should typically be loaded last of all the packages.
\usepackage{hyperref}

% Add a label and an index entry at the same time.
\newcommand{\idxlabel}[2]{\label{#1}\index{#2}}

\makeindex

% Various theorem environments. Only one variety included here.
\theoremstyle{plain} % just in case the style had changed
\newcommand{\thistheoremname}{}

\newtheorem{thm}{Theorem}[section] % the main one
\newtheorem*{thm*}{Theorem} % unnumberedtheorem
% there are generic theorems used to construct the environments below:
\newtheorem*{genericthm*}{\thistheoremname}

\makeatletter
\newenvironment{namedthm*}[1]
  {\renewcommand{\thistheoremname}{#1}%
   \begin{genericthm*}%
   \def\@currentlabelname{#1}}% ADDED
  {\end{genericthm*}}
\makeatother

\title{How do I select a named theorem name as a label reference using nameref?}
\begin{document}

\maketitle
\section{This is the first section}

\begin{namedthm*}{Some Theorem}[book-I-found-it-in]
\idxlabel{my-theorem}{Some Theorem}
Here, I define a theorem I would like to refer to later. I would like the
text form to display ``Some Theorem" rather than a section or page number.

It would be nice if \idxlabel could interpret the theorem name from the
namedthm environment, but I would also like to know how to override
that and provide my own just in case.

It may need to differ from the index, because the index supports nested
terms such as Latex!Cross-referencing.
\end{namedthm*}

\section{This is the second section}

Here I would like to talk about \nameref{my-theorem} (and this should say
``Some Theorem"", ideally.

\clearpage
\printindex

\end{document}

相关内容