我有以下问题:
- 具有多种不同“类型”定理的文档,例如“定理”、“引理”、“命题”等。这些是
amsthm
使用环境kttheorem
、ktlemma
、ktprop
等以通常的 ( ) 方式定义的。 - 在文档本身(不是附录)中,假设第 5 章包含两个定理:一个带标签的命题
pugsrcute
和一个带标签的定理pugsrsmart
。在编写文档时,它们分别被称为命题 5.1 和定理 5.2。 - 的证明
pugsrcute
恰好很长,并且涉及一个支持引理和一个支持命题。因此,pugsrcute
也支持定理放在附录中。 - 在附录中,理想情况下我希望能够插入以下内容:
并使内部的定理环境\begin{supportfor}{pugsrsmart} \begin{ktlemma} \label{pugsrsmall} ... \end{ktlemma} \begin{ktprop} \label{smalldogsrcute} ... \end{ktprop} \end{supportfor}
supportfor
各方面表现正常除了那个该定理没有使用标准编号方案,而是以“引理 5.1(a)”和“命题 5.1(b)”的形式出现,其中 5.1 是标签编号pugsrsmart
,“a”和“b”是按字母顺序排列的前两个字母。 - 到
\cref
和pugsrsmall
也会smalldogsrcute
同样扩展为遵循此替代编号方案的值,并带有适当的超链接。因此,\cref{pugsrsmall}
将扩展为“引理 5.1(a)”,其中“5.1(a)”带有超链接,而\cref{smalldogsrcute}
将扩展为“命题 5.1(b)”,其中“5.1(b)”带有超链接。
问题
是否可以用这种方式选择性地覆盖定理标签?
平均能量损失
\documentclass{article}
\usepackage{amsthm}
\usepackage[
colorlinks,
final,
hyperfootnotes = false,
linkcolor = blue,
citecolor = blue]{hyperref}
\usepackage[capitalize]{cleveref}
% environments for theorems and lemmas
\NewDocumentCommand{\ktnewtheorem}{ommm}{ % \ktnewtheorem[usecounter]{type}{Long}{short}
\IfNoValueTF{#1}
{\newtheorem {#2} {#3} [section]}
{\newtheorem {#2} [#1] {#3}}
\crefname {#2} {#4} {\MakeLowercase{#3}}
\Crefname {#2} {#4} {#3}
}
\ktnewtheorem {kttheorem} {Theorem} {Theorem}
\ktnewtheorem[kttheorem] {ktlemma} {Lemma} {Lemma}
\ktnewtheorem[kttheorem] {ktprop} {Proposition} {Prop.}
\ktnewtheorem[kttheorem] {ktcor} {Corollary} {Cor.}
% ktrestate (restate theorem/proposition/lemma/etc.) environment
\newenvironment {ktrestate} [2] [0pt]
{\vspace{#1}\noindent\textbf{\Cref{#2}.}\hspace{2pt}\begingroup\em}
{\endgroup}
% placeholder \supportfor{label}; magic should happen here!
\newenvironment {supportfor} [1]
{\begingroup}
{\endgroup}
\begin{document}
\setcounter{section}{4}
\section{Pugs}
The following \namecrefs{pugsrcute} was first proved by Leonhard Euler in 1760.
\begin{ktprop}
\label{pugsrcute}
Let $c_{\mathrm{pug}}$ be the cuteness factor of a pug.
Then $c_{\mathrm{pug}} \geq 8\pi^{-1}$ a.s.
\end{ktprop}
\begin{proof}
See \cref{pugproofs} for proof.
\end{proof}
\noindent Euler hit another home run in 1762.
\begin{kttheorem}
\label{pugsrsmart}
Let $P$ be a pug. Then $P$ is as least as intelligent as an Artin representation
of degree $2$.
\end{kttheorem}
\begin{proof}
The result follows logically from the fact that abelian L-functions are
meromorphic for non-trivial characters, and $P$ looks kind of like an L-function
if you squint really hard.
\end{proof}
\newpage
\section{Appendix}
\label{pugproofs}
First, we prove some supporting results.
\begin{supportfor}{pugsrcute}
\begin{ktlemma} % Currently "Lemma 6.1"; Should be "Lemma 5.1(a)"
\label{pugsrsmall}
Pugs are small.
\end{ktlemma}
\begin{proof}
Just look at them.
\end{proof}
\begin{ktprop} % Currently "Proposition 6.2"; Should be "Proposition 5.1(b)"
\label{smalldogsrcute}
Small dogs are cute.
\end{ktprop}
\begin{proof}
The result follows from Fermat's celebrated treatise ``On the Adorableness of
Dogs and Other Small Mammals''.
\end{proof}
\end{supportfor}
% The following \cref currently expands to "Lemma 6.1 and Prop 6.2". NO!
% Should expand to "Lemma 5.1(a) and Prop. 5.1(b)"!
\noindent Now, we use \cref{pugsrsmall,smalldogsrcute} in the proof of \cref{pugsrcute}.
\begin{ktrestate}[3mm]{pugsrcute}
Let $c_{\mathrm{pug}}$ be the cuteness factor of a pug.
Then $c_{\mathrm{pug}} \geq 8\pi^{-1}$ a.s.
\end{ktrestate}
\begin{proof}
% The following \cref's expand to "Lemma 6.1" and "Prop 6.2". NO!
% Should expand to "Lemma 5.1(a)" and "Prop 5.1(b)".
The result follows from \cref{pugsrsmall}, mixed with \cref{smalldogsrcute},
baked at $350^\circ$ for $25$ minutes, and seasoned to taste.
\end{proof}
\end{document}
已添加:我能做的最好
以下是我目前想到的最佳解决方案。编译后的文档看起来正确,但代码中存在许多问题。
\documentclass{article}
\usepackage{amsthm}
\usepackage{etoolbox}
\usepackage[
colorlinks,
final,
hyperfootnotes = false,
linkcolor = blue,
citecolor = blue]{hyperref}
\usepackage[capitalize]{cleveref}
% environments for theorems and lemmas
\NewDocumentCommand{\ktnewtheorem}{ommm}{ % \ktnewtheorem[usecounter]{type}{Long}{short}
\IfNoValueTF{#1}
{\newtheorem {#2} {#3} [section]}
{\newtheorem {#2} [#1] {#3}}
\crefname {#2} {#4} {\MakeLowercase{#3}}
\Crefname {#2} {#4} {#3}
%% ADDED
\expandafter\def\csname #2Long\endcsname{#3}
\expandafter\def\csname #2long\endcsname{\MakeLowercase{#3}}
\expandafter\def\csname #2short\endcsname{#4}
%% END ADDED
}
\ktnewtheorem {kttheorem} {Theorem} {Theorem}
\ktnewtheorem[kttheorem] {ktlemma} {Lemma} {Lemma}
\ktnewtheorem[kttheorem] {ktprop} {Proposition} {Prop.}
\ktnewtheorem[kttheorem] {ktcor} {Corollary} {Cor.}
% ktrestate (restate theorem/proposition/lemma/etc.) environment
\newenvironment {ktrestate} [2] [0pt]
{\vspace{#1}\noindent\textbf{\Cref{#2}.}\hspace{2pt}\begingroup\em}
{\endgroup}
% placeholder \supportfor{label}; magic should happen here!
\newenvironment {supportfor} [1]
{\begingroup}
{\endgroup}
%% BEST I CAN DO
% Problems:
% - Uses \begin{ktsuppthm}{theoremenv}{label}{extension} rather than the desired
% \begin{supportfor}{label}
% \begin{theoremenv}
% syntax.
% - Requires all supplemental theorems to be declared in advance (i.e. in document
% preamble).
% - Requires proof definitions to specify their extension rather than assigning
% them automatically.
% - Requires writing to the .aux file, and is generally hackish.
% - Version below only supports supplemental theorems for ONE theorem. Support for
% more would be even messier.
\makeatletter
\def\csxdefaux#1#2{%
\protected@write\@mainaux{}{%
\csgdef{\detokenize{#1}}{#2}%
}%
}
\makeatother
\newcommand* {\ktdefsuppthm} [1] {
\expandafter\gdef\csname ktsuppthmext#1\endcsname{?}
\expandafter\gdef\csname ktsuppthmshort#1\endcsname{?}
\expandafter\gdef\csname ktsuppthmlong#1\endcsname{?}
\expandafter\gdef\csname ktsuppthmLong#1\endcsname{?}
\crefname {ktsuppthm#1} {\csname ktsuppthmshort#1\endcsname} {\csname ktsuppthmlong#1\endcsname}
\Crefname {ktsuppthm#1} {\csname ktsuppthmshort#1\endcsname} {\csname ktsuppthmLong#1\endcsname}
\creflabelformat {ktsuppthm#1} {\hyperlink
{L\csname ktsuppthmext#1\endcsname.#1}
{\labelcref*{\csname ktsuppthmext#1\endcsname}(#1)}}
\expandafter\newcommand \csname supplabel#1\endcsname [2] {% \supplabel<x> {type} {label}
\raisebox{12pt}{\hypertarget {L##2.#1} {}}%
\csxdefaux{ktsuppthmext#1}{##2}%
\csxdefaux{ktsuppthmshort#1}{\csname ##1short\endcsname}%
\csxdefaux{ktsuppthmlong#1}{\csname ##1long\endcsname}%
\csxdefaux{ktsuppthmLong#1}{\csname ##1Long\endcsname}%
\expandafter\gdef\csname ktsuppthmext#1\endcsname{##2}%
\expandafter\gdef\csname ktsuppthmshort#1\endcsname{\csname ##1short\endcsname}%
\expandafter\gdef\csname ktsuppthmlong#1\endcsname{\csname ##1long\endcsname}%
\expandafter\gdef\csname ktsuppthmLong#1\endcsname{\csname ##1Long\endcsname}%
\label[ktsuppthm#1]{##2.#1}%
}
}
\ktdefsuppthm{a}
\ktdefsuppthm{b}
\newenvironment {ktsuppthm} [4] [0pt] % ktsuppthm [leadvspc]{type}{label}{ext}
{%
\vspace{#1}\noindent\csname supplabel#4\endcsname{#2}{#3}%
\textbf{\csname #2Long\endcsname~\labelcref*{#3}(#4).}\hspace{5pt}\begingroup\em%
}
{\endgroup}
%% END BEST I CAN DO
\begin{document}
\setcounter{section}{4}
\section{Pugs}
The following \namecrefs{pugsrcute} was first proved by Leonhard Euler in 1760.
\begin{ktprop}
\label{pugsrcute}
Let $c_{\mathrm{pug}}$ be the cuteness factor of a pug.
Then $c_{\mathrm{pug}} \geq 8\pi^{-1}$ a.s.
\end{ktprop}
\begin{proof}
See \cref{pugproofs} for proof.
\end{proof}
\noindent Euler hit another home run in 1762.
\begin{kttheorem}
\label{pugsrsmart}
Let $P$ be a pug. Then $P$ is as least as intelligent as an Artin representation
of degree $2$.
\end{kttheorem}
\begin{proof}
The result follows logically from the fact that abelian L-functions are
meromorphic for non-trivial characters, and $P$ looks kind of like an L-function
if you squint really hard.
\end{proof}
\newpage
\section{Appendix}
\label{pugproofs}
First, we prove some supporting results.
%\begin{supportfor}{pugsrcute}
\begin{ktsuppthm}{ktlemma}{pugsrcute}{a}% should be: \begin{ktlemma}
%\label{pugsrsmall}
% This implementation automatically makes the label pugsrcute.a.
Pugs are small.
\end{ktsuppthm}
\begin{proof}
Just look at them.
\end{proof}
\begin{ktsuppthm}{ktprop}{pugsrcute}{b}% should be: \begin{ktprop}
%\label{smalldogsrcute}
% This implementation automatically makes the label pugsrcute.b.
Small dogs are cute.
\end{ktsuppthm}
\begin{proof}
The result follows from Fermat's celebrated treatise ``On the Adorableness of
Dogs and Other Small Mammals''.
\end{proof}
%\end{supportfor}
% Should expand to "Lemma 5.1(a) and Prop. 5.1(b)".
\noindent Now, we use \cref{pugsrcute.a,pugsrcute.b} in the proof of \cref{pugsrcute}.
\begin{ktrestate}[3mm]{pugsrcute}
Let $c_{\mathrm{pug}}$ be the cuteness factor of a pug.
Then $c_{\mathrm{pug}} \geq 8\pi^{-1}$ a.s.
\end{ktrestate}
\begin{proof}
% Should expand to "Lemma 5.1(a)" and "Prop 5.1(b)".
The result follows from \cref{pugsrcute.a}, mixed with \cref{pugsrcute.b},
baked at $350^\circ$ for $25$ minutes, and seasoned to taste.
\end{proof}
\end{document}
答案1
尝试
\newenvironment {supportfor} [1]
{\renewcommand\thekttheorem{\ref{#1}(\alph{kttheorem})}}
{}