我正在使用memoir
类,并用 定义定理thmtools
。定理通常有一个名称,除了编号之外。我正在寻找编写一个\fullref
命令来输出环境的名称(此处为Theorem
)及其给定名称,但不输出其编号。(此命令适用于任何定义了名称的环境,例如通过\myenvautorefname
。)
我曾经使用过以下命令,可以在 TeX SE 上找到:
\newcommand{\fullref}[1]{\hyperref[#1]{\namecref{#1}\ \nameref*{#1}}}
不幸的是,memoir
和cleveref
互相冲突。所以我想不用cleveref
。
看来我应该能够autoref
仅使用以下命令来实现相同的效果
\newcommand{\fullref}[1]{\hyperref[#1]{\autoref*{#1}\ \nameref*{#1}}}
几乎按照我的要求做,除了它显示Theorem
和定理名称之间的定理编号。
下面是一个说明上述命令的 MWE:
\documentclass{memoir}
\usepackage{amsthm,thmtools}
\usepackage{nameref}
\usepackage{hyperref}
\declaretheorem{theorem}
\renewcommand{\theoremautorefname}{Theorem}
\newcommand{\fullref}[1]{\hyperref[#1]{\autoref*{#1}\ \nameref*{#1}}}
\begin{document}
\begin{theorem}[Whatever]
\label{thm:whatever}
Some witty theorem.
\end{theorem}
% The following outputs "Theorem 1 Whatever".
% I would like "Theorem Whatever".
Consider \fullref{thm:whatever}.
\end{document}
提前致谢!
答案1
為啥不用cleveref
?!
\documentclass{memoir}
\usepackage{amsthm,thmtools}
\usepackage{nameref}
\usepackage{hyperref}
\usepackage{cleveref}
\declaretheorem{theorem}
\renewcommand{\theoremautorefname}{Theorem}
\newcommand{\fullref}[1]{\hyperref[#1]{\namecref{#1}\ \nameref*{#1}}}
\begin{document}
\begin{theorem}[Whatever]
\label{thm:whatever}
Some witty theorem.
\end{theorem}
% The following outputs "Theorem 1 Whatever".
% I would like "Theorem Whatever".
Consider \fullref{thm:whatever}.
\end{document}
答案2
以下用途zref
作为替代cleveref
创造一个新的财产调用envname
(类似于模块提供的内容zref-env
)来存储\<env>autorefname
-\@currenvir
条目curr
名称envir
:
\documentclass{memoir}
\usepackage{amsthm,thmtools,zref}
\usepackage{hyperref}% Loads nameref
\makeatletter
\zref@newprop{envname}[??]{%
\expandafter\ifx\csname\@currenvir autorefname\endcsname\relax
\@currenvir
\else
\csname \@currenvir autorefname\endcsname
\fi}%
\AtBeginDocument{
\let\oldlabel\label
\renewcommand{\label}[1]{\zref@labelbyprops{#1}{envname}\oldlabel{#1}}
}
\newcommand{\fullref}[1]{%
\zref@refused{#1}% Mark label as used
\hyperref[#1]{\zref@extract{#1}{envname}\ \nameref*{#1}}}
\makeatother
\declaretheorem{theorem}
\renewcommand{\theoremautorefname}{Theorem}
\begin{document}
\begin{theorem}[Whatever]
\label{thm:whatever}
Some witty theorem.
\end{theorem}
% The following outputs "Theorem Whatever".
Consider \fullref{thm:whatever}.
\end{document}