# How to refer to custom-numbered theorem?

Short form: Suppose I have sporadically numbered theorems:

Thm A
Thm 1
Thm B


Code below shows how to force this numbering when printing the Theorems. However, when I refer back to these via \ref, they still show up as "Thm 1", "Thm 2", "Thm 3", respectively. How to force \ref to show their displayed titles?

History of this question

Long form: I devised a way to replicate Serre's numbering of Corollaries by the number of the preceding Lemma / Proposition [see bottom for full code]. For example:

Section 1
Lemma 1.1
Corollary 1.1
Proposition 1
Corollary 1

Section 2
Lemma 2.1
Proposition 2
Lemma 2.2
Corollary 2.2A
Corollary 2.2B
I want to say: by Corollary 2.2A, we win!
Instead, TeX gives: by Corollary 2, we win!


However, the displayed Corollary number does not affect the internal numbering of the Corollary. For example, the first replem corollary (1.1) is internally remembered as Corollary 1, the second one (2.1) as Corollary 2, etc.
Then, when I refer to the corollary in text, I get a reference to the internal number instead. How to modify the internal numbering to match the labeled text?

\documentclass[11pt]{amsart}
\usepackage{amsmath}

\makeatletter
\newtheorem*{rep@theorem}{\rep@title}
\newcommand{\newreptheorem}[2]{%
\newenvironment{rep#1}[2][]{%
\def\rep@title{#2 \ref{##2}##1}%
\begin{rep@theorem}}%
{\end{rep@theorem}}}
\makeatother

\newtheorem{lem}{Lemma}
\newreptheorem{lem}{Corollary}
\newtheorem{Lem}[lem]{Lemma}%*
\numberwithin{lem}{section}
\newtheorem{prop}{Proposition}
\newreptheorem{prop}{Corollary}
\newtheorem{Prop}[prop]{Proposition}
\newtheorem{Cor}{Corollary}%}[lem]{
\newtheorem{cor}[Cor]{Corollary}%*

\begin{document}
\section{asdf}
\begin{lem}\label{lem1}
\end{lem}
\begin{replem}{lem1}\label{cor1}
\end{replem}
\begin{prop}\label{p1}
\end{prop}
\begin{repprop}{p1}\label{cor2}
\end{repprop}
\section{fdsa}
\begin{lem}\label{lem2}
\end{lem}
\begin{prop}\label{p2}
\end{prop}
\begin{lem}\label{lem3}
\end{lem}
\begin{replem}[A]{lem3}\label{cor3}
\end{replem}
\begin{replem}[B]{lem3}\label{cor4}
\end{replem}

By Corollary \ref{cor3}, we win!
\end{document}


One solution is to say: "By Corollary \ref{lem3}A..." instead of "By Corollary \ref{cor3}; however, the corollaries tends to move frequently, so I'd like a way to make the reference independent of the actual Lemma.

• The output is By Corollary 2, we win! ... Do you have some older TeX distribution, older than April 2015? If so, try \usepackage{fixltx2e}
– user31729
Dec 31 '16 at 21:16
• Regardless of whether it's By Corrollary 2 or By Corollary 3, it's still not By Corollary 2.2A, which is what I want.
– Alex
Dec 31 '16 at 21:20
• And thanks for the clarification, I mistyped. :) Just took a while to re-compile and check.
– Alex
Dec 31 '16 at 21:23

A 'trial' of a solution, by querying the state of the \@lemmamode conditional and the value of the proposition counter.

This way, the references seem to be correct.

However, this will get into trouble at the time hyperref comes into action!

\documentclass[11pt]{amsart}
\usepackage{amsmath}
\usepackage{etoolbox}

\newcommand{\corcntrfmtlem}{%
\ifnum\value{prop} > 0\relax
\thelem.\Alph{cor}%
\else
\arabic{lem}.\arabic{cor}%
\fi
}

\newcommand{\corcntrfmtprop}{%
\arabic{cor}%
}

\makeatletter
\newif\if@lemmamode

\newtheorem{lem}{Lemma}[section]
\newtheorem{prop}{Proposition}
\newtheorem{cor}{Corollary}[prop]% Restart the cor counter

\AfterEndEnvironment{lem}{\@lemmamodetrue}% Enable lemma mode
\AfterEndEnvironment{prop}{\@lemmamodefalse} % Disable lemma mode

\renewcommand{\thecor}{%
\if@lemmamode
\corcntrfmtlem%
\else
\corcntrfmtprop%
\fi\relax
}
\makeatother

\begin{document}
\section{asdf}
\begin{lem}\label{lem1}
\end{lem}
\begin{cor}\label{cor1}
\end{cor}
\begin{prop}\label{p1}
\end{prop}

\begin{cor}\label{cor2}
\end{cor}

\section{fdsa}
\begin{lem}\label{lem2}
\end{lem}
\begin{prop}\label{p2}
\end{prop}
\begin{lem}\label{lem3}
\end{lem}
\begin{cor}\label{cor2a}
\end{cor}
\begin{cor}\label{cor2b}
\end{cor}

By Corollary \ref{cor2a} and \ref{cor2b}, we will win!
\end{document}


• We also get into trouble if there is more than one proposition with a corollary. Because the corollary counter resets after every proposition. But I think that's an exercise for me to figure out, to practice my LaTeX programming skills while I try to mimic the Lemma construction. Thanks!
– Alex
Dec 31 '16 at 22:03
• @Alex: Well, you must admit, that the numbering scheme is not really logical!
– user31729
Dec 31 '16 at 22:04
• Of course this is not the final scheme: I would probably adopt a variant of it after discussing it with my advisor. The point is, that when there's many Corollaries, they should be easy to find, without jacking up any of the numbers to over 100. I just wanted to have an idea of what was feasible, when I come in to discuss it with him after the break.
– Alex
Dec 31 '16 at 22:08