2

I have the following problem:

  • Document with many different 'types' of theorem, e.g., "theorem", "lemma", "proposition", etc. These are defined in the usual (amsthm) way using environments kttheorem, ktlemma, ktprop, etc.
  • In the document proper (not the appendix), suppose chapter 5 contains two theorems: a proposition with label pugsrcute and a theorem with label pugsrsmart. When the document is compiled, these happen to be called Prop. 5.1 and Theorem 5.2 respectively.
  • The proof of pugsrcute happens to be quite long and refers to a supporting lemma and a supporting proposition. As a result, the proof of pugsrcute as well as the supporting theorems are placed in the appendix.
  • In the appendix, ideally I'd like to be able to insert the following:
    \begin{supportfor}{pugsrsmart}
        \begin{ktlemma}
            \label{pugsrsmall}
            ...
        \end{ktlemma}
    
        \begin{ktprop}
            \label{smalldogsrcute}
            ...
        \end{ktprop}
    \end{supportfor}
    
    and have the theorem environments inside supportfor behave normally in all respects except that instead of using the standard numbering scheme, the theorems appear as "Lemma 5.1(a)" and "Proposition 5.1(b)", where 5.1 is the number of label pugsrsmart and where "a" and "b" are the first two letters in alphabetic sequence.
  • The \crefs to pugsrsmall and smalldogsrcute would likewise expand to values that respect this alternate numbering scheme, with proper hyperlinks. Hence, \cref{pugsrsmall} would expand to "Lemma 5.1(a)" with "5.1(a)" hyperlinked, and \cref{smalldogsrcute} would expand to "Prop. 5.1(b)", with "5.1(b)" hyperlinked.

Question

Is selective overriding of theorem labeling in this way possible?

MWE

\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}

Added: Best I Can Do

The following is the best solution I've come up with this far. The compiled document looks right, but there are a number of problems identified in the code.

\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}
2
  • You asked, "Is selective overriding of theorem labeling ... possible?" Yes. In particular, do take a look at Section 6, entitled "Overriding the cross-reference type", of the user guide of the cleveref package. To open the user guide in a pdf viewer, just type texdoc cleveref in a command wiindow.
    – Mico
    Commented Sep 15, 2022 at 4:53
  • 1
    @Mico: Selective overriding meeting all of these specifications is particularly tricky. I've added "The Best I Can Do" code to the question to show the best solution I've come up with thus far. The resulting compiled document looks and work as required, but a number of problems and hacks are identified in the code, which is why I'm looking for a more elegant solution.
    – COTO
    Commented Sep 15, 2022 at 11:31

1 Answer 1

1

Try with

\newenvironment {supportfor} [1]
    {\renewcommand\thekttheorem{\ref{#1}(\alph{kttheorem})}}
    {}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .