
我正在使用該類別memoir
並使用 定義定理thmtools
。除了編號之外,定理通常還有一個名稱。我正在編寫一個\fullref
命令,輸出環境名稱(此處為Theorem
)及其給定名稱,但不輸出其編號。 (此命令應該適用於定義名稱的任何環境,例如,通過\myenvautorefname
。)
我曾經使用過以下命令,可以在 TeX SE 上找到:
\newcommand{\fullref}[1]{\hyperref[#1]{\namecref{#1}\ \nameref*{#1}}}
不幸的是,memoir
又cleveref
互相衝突。所以我想不用cleveref
.
看來我用only應該也能達到同樣的效果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
ent curr
onmentenvir
名稱:
\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}