5

I'm using enumitem and cleveref packages and I would like to enforce a different behaviour of \ref and \cref for {enumerate} lists.

More precisely, whenever I have lists in a theorem environment I add a label=... and ref=... options to enumerate so to include theorem prefix (Thm, Lem, Prop, ...) and corresponding number. However, in the proof of the theorem I would like to avoid such redundant prefix, and I was hoping to achieve this by specifying different behaviours of \ref and \cref commands. The problem would be solved if enumitem offered a cref=... option to enumerate environment, which however is not the case.

EDIT: I changed the MWE to remove possible ambiguities.

I'm posting the following MWE hoping that it can help clarify what I want: specifically, (notice the different use of \ref and \cref for referring to items in the same Theorem being proved or in the external Theorem, which, however, are typeset the same) I would like to eliminate the prefix "Thm. 1.2" when referencing the items of the Theorem in its proof.

And yes, everything should be compatible with hyperref...

\documentclass[english]{amsart}
\usepackage[english]{babel}
\usepackage{enumitem}
\usepackage[colorlinks=true]{hyperref}
\usepackage{amsthm}
\usepackage{cleveref}

\newtheorem{thm}{Theorem}[section]
% cleveref options for thm
    \crefname{thm}{Thm.}{Thm.}
    \crefformat{thm}{#2Thm. #1#3}
% cleveref options for enumi: remove "item "
\crefformat{enumi}{#2#1#3}

\begin{document}
\section{First section}
\begin{thm}\label{Thm:One}
The following properties hold:
\begin{enumerate}[{label=(\alph*)},{ref=\cref{Thm:One}(\alph*)}]
    \item\label{Thm:One:1} \(1>0\)
    \item\label{Thm:One:2} \(0<1\)
\end{enumerate}
\end{thm}

\begin{thm}\label{Thm:Two}
The following properties hold:
\begin{enumerate}[{label=(\alph*)},{ref=\cref{Thm:Two}(\alph*)}]
    \item\label{Thm:Two:1} \(2>1\)
    \item\label{Thm:Two:2} \(1<2\)
\end{enumerate}
\begin{proof}
\ref{Thm:Two:1} follows from \cref{Thm:One:1} by adding 1 on both sides and similarly \ref{Thm:Two:2} follows from \cref{Thm:One:2}.
\end{proof}
\end{thm}
\end{document}

and the output is as follows enter image description here

3

Here's a possible solution (if I've understood the question correctly).

The key is to use a different \crefformat inside proof at the begin of the proof environment and restoring it back to the old one at the end.

This is achieved by using \AtBeginEnvironment{proof}{...} and \AtEndEnvironment{proof}{...}

\documentclass[english]{amsart}
\usepackage[english]{babel}
\usepackage{enumitem}
\usepackage{etoolbox}
\usepackage[colorlinks=true]{hyperref}
\usepackage{amsthm}
\usepackage{cleveref}

\newtheorem{thm}{Theorem}[section]
% cleveref options for thm
    \crefname{thm}{Thm.}{Thm.}
    \crefformat{thm}{#2Thm. #1#3}
\newtheorem{lem}[thm]{Lemma}
% cleveref options for lem
\crefname{lem}{Lem.}{Lem.}
\crefformat{lem}{#2Lem. #1#3}
% cleveref options for enumi: remove "item "
\crefformat{enumi}{#2#1#3}

\AtBeginEnvironment{proof}{%
  \crefformat{lem}{#2 #1#3}%
}

\AtEndEnvironment{proof}{%
  \crefformat{lem}{#2Lem. #1#3}%
}

\begin{document}
\section{First section}
\begin{thm}\label{Thm:One}
The following properties hold:
\begin{enumerate}[{label=(\alph*)},{ref=\cref{Thm:One}(\alph*)}]
    \item\label{Thm:One:1} \(1>0\)
    \item\label{Thm:One:2} \(0<1\)
\end{enumerate}
\end{thm}

\begin{lem}\label{Lem:Two}
  The following properties hold:
  \begin{enumerate}[{label=(\alph*)},{ref=\cref{Lem:Two}(\alph*)}]
  \item\label{Lem:Two:1} \(2>1\)
  \item\label{Lem:Two:2} \(1<2\)
  \end{enumerate}
\begin{proof}
  \ref{Lem:Two:1} follows from \cref{Thm:One:1} by adding 1 on both sides and similarly \ref{Lem:Two:2} follows from \cref{Thm:One:2}.
\end{proof}
\end{lem}

Original reference is: \ref{Lem:Two:1}
\end{document}

Update

\documentclass[english]{amsart}
\usepackage[english]{babel}
\usepackage{enumitem}
\usepackage{etoolbox}
\usepackage[colorlinks=true]{hyperref}
\usepackage{amsthm}
\usepackage{cleveref}



\newtheorem{thm}{Theorem}[section]
% cleveref options for thm
\crefname{thm}{Thm.}{Thm.}
\crefformat{thm}{#2Thm. #1#3}
\newtheorem{lem}[thm]{Lemma}
% cleveref options for lem
\crefname{lem}{Lem.}{Lem.}
\crefformat{lem}{#2Lem. #1#3}
% cleveref options for enumi: remove "item "
\crefformat{enumi}{#2#1#3}



\newcommand{\Lemcrefext}[1]{%
 \begingroup
 \crefformat{lem}{##2Lem. ##1##3}
 \cref{#1}%
 \endgroup
}

\newcommand{\Thmcrefext}[1]{%
 \begingroup
 \crefformat{lem}{##2Lem. ##1##3}
 \cref{#1}%
 \endgroup
}


\AtBeginEnvironment{proof}{%
  \crefformat{lem}{#2 #1#3}
}


\AtEndEnvironment{proof}{%
  \crefformat{lem}{#2Lem. #1#3}
}

\begin{document}
\section{First section}
\begin{thm}\label{Thm:One}
The following properties hold:
\begin{enumerate}[{label=(\alph*)},{ref=\cref{Thm:One}(\alph*)}]
    \item\label{Thm:One:1} \(1>0\)
    \item\label{Thm:One:2} \(0<1\)
\end{enumerate}
\end{thm}

\begin{lem}\label{Lem:Two}
  The following properties hold:
  \begin{enumerate}[{label=(\alph*)},{ref=\cref{Lem:Two}(\alph*)}]
  \item\label{Lem:Two:1} \(2>1\)
  \item\label{Lem:Two:2} \(1<2\)
  \end{enumerate}
\begin{proof}
  \ref{Lem:Two:1}  follows from \cref{Thm:One:1} by adding 1 on both sides and similarly \ref{Lem:Two:2} follows from \cref{Thm:One:2}. However, in \Lemcrefext{Lem:Three} and \Thmcrefext{Thm:One} it will be shown that...
\end{proof}
\end{lem}

\begin{lem}\label{Lem:Three}
Foo
\end{lem}

Original reference is: \ref{Lem:Two:1}
\end{document}

enter image description here

  • Thank you @ChristianHupfer for your answer, I think I get it. However, I guess that \refand \cref would still behave the same also in proof envirinoment. I mean, what if I want to refer to an external Lemma in the proof? – AndreasT Mar 7 '16 at 20:54
  • @AndreasT: Difficult at best, actually ;-) – user31729 Mar 7 '16 at 20:56
  • I edited the MWE, however other workarounds are also welcome, by possibly defining new commands or whatever. It need not involve different behaviours of \ref and \cref – AndreasT Mar 7 '16 at 21:08
  • 1
    @AndreasT: I've added two small commands that restore the cref format internally. Any other approach would involve label etc. parsing and comparisions, which is not feasible without much ado, actually – user31729 Mar 7 '16 at 21:52
  • 1
    I guess yours is just fine, it's me who probably didn't get it completely. I guess I have to test it on some real documents first. Thank you again! – AndreasT Mar 7 '16 at 22:11
2

Here's a solution that uses (a) cleveref's \crefalias device and (b) two dedicated enumeration environments, named enumthm and enumcor, to be used inside the environments named thm and cor, respectively. The idea is this allows you to use \ref and \cref independently -- their outputs will differ only in whether or not a label ("Thm.", "Cor.") will be prefixed to the compound "number" associated with the theorem or corollary being cross-referenced.

By the way, I would use upright rather than italic alphabetic "numbers" -- (a), (b), etc -- for enumerations in theorem-like environments.

enter image description here

\documentclass[english]{amsart}
\usepackage{babel}
\usepackage{enumitem}  % for '\newlist' and '\setlist' macros
\usepackage[colorlinks=true]{hyperref}
%%\usepackage{amsthm}  % is loaded automatically by amsart document class
\usepackage[nameinlink]{cleveref}

\newtheorem{thm}{Theorem}[section]
\crefname{thm}{Thm.}{Thms.} % singular and plural forms of label

\newtheorem{cor}[thm]{Corollary}
\crefname{cor}{Cor.}{Cors.} % singular and plural forms of label

\newlist{enumthm}{enumerate}{1} % set up a dedicated enumeration env.
\setlist[enumthm]{label=\upshape(\alph*),ref=\upshape\thethm(\alph*)}
\crefalias{enumthmi}{thm} % alias 'enumthmi' counter to 'thm'

\newlist{enumcor}{enumerate}{1} % set up a second dedicated enumeration env.
\setlist[enumcor]{label=\upshape(\alph*),ref=\upshape\thecor(\alph*)}
\crefalias{enumcori}{cor} % alias 'enumcori' counter to 'cor'


\begin{document}
\setcounter{section}{1} % just for this example

\begin{thm}\label{Thm:One}
The following properties hold:
\begin{enumthm}
    \item\label{Thm:One:1} \(1>0\)
    \item\label{Thm:One:2} \(0<1\)
\end{enumthm}
\end{thm}

\begin{cor}\label{Thm:Two}
The following properties hold as well:
\begin{enumcor}
    \item\label{Thm:Two:1} \(2>1\)
    \item\label{Thm:Two:2} \(1<2\)
\end{enumcor}
\begin{proof}
\ref{Thm:Two:1} follows from \ref{Thm:One:1} by adding 1 on both sides. Similarly, \cref{Thm:Two:2} follows from \cref{Thm:One:2}.
\end{proof}
\end{cor}

\end{document} 
  • Thanks @Mico, I got it. I also appreciate the comments and the typographical suggestions :) – AndreasT Mar 8 '16 at 10:54
  • 1
    @Mico I have a very similar problem, except that I don’t want the \ref output to be “1.2(a)”, but simply “(a)”. Is that possible to achieve in a way that maintains the \cref output “Theorem 1.2(a)”? – Gaussler Oct 27 '16 at 10:25
  • @Mico I have now created a separate question here. – Gaussler Oct 27 '16 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.