I have tried (with partial success) to modify the solution here to the question: Cleveref and named theorems.
The idea is that I want to overload cleverref's Cref
(and also cref
) to give the name of theorems, lemmas, etc. where they are given. However, while I have achieved this, I want the behaviour unmodified for equations, tables, figures, listings, sections, etc.
NB: I would like to overload \Cref
, and not have to introduce a new command if possible.
MWE
\documentclass[a4paper,10pt]{extarticle}
\usepackage{amsmath}
\usepackage[amsmath]{ntheorem}
\usepackage{thmtools}
\usepackage{nameref,cleveref}
\usepackage{xspace}
\newtheorem{thm}{Theorem}[section]
\newtheorem{lemma}[thm]{Lemma}
\crefname{lemma}{lemma}{lemmas}
\Crefname{lemma}{Lemma}{Lemmas}
\crefname{thm}{theorem}{theorems}
\Crefname{thm}{Theorem}{Theorems}
\makeatletter %% My attempt at achieving the effect.
\let\crefOrig\cref
\let\CrefOrig\Cref
\renewcommand{\cref}[1]{\mynameref{#1}{\csname r@#1\endcsname}}
\renewcommand{\Cref}[1]{\Mynameref{#1}{\csname r@#1\endcsname}}
\def\Mynameref#1#2{%
\begingroup
\edef\@mytxt{#2}%
\edef\@mytst{\expandafter\@thirdoffive\@mytxt}%
\ifx\@mytst\empty\CrefOrig{#1}\else
\nameref{#1}\xspace(\CrefOrig{#1})\fi
\endgroup
}
\def\mynameref#1#2{%
\begingroup
\edef\@mytxt{#2}%
\edef\@mytst{\expandafter\@thirdoffive\@mytxt}%
\ifx\@mytst\empty\crefOrig{#1}\else
\nameref{#1}\xspace(\crefOrig{#1})\fi
\endgroup
}
\makeatother
\begin{document}
\section{Boring and Awesome stuff}
\label{sec}
\begin{figure}[htb]
\centering abc
\caption[something]{something more}
\label{fig}
\end{figure}
\begin{equation}
abc
\label{eqt}
\end{equation}
\begin{table}[htb]
\centering abc
\caption[content]{content...}
\label{tab}
\end{table}
\begin{lemma}\label{noname}
Extremely important lemma that has no name.
\end{lemma}
\begin{lemma}[Fubini's lemma]\label{boringLemma}
This is some boring statement.
\end{lemma}
\begin{thm}[Fataou's Theorem]\label{awesomeTheorem}
This is a really awesome statement.
\end{thm}
We have \Cref{boringLemma} and \Cref{awesomeTheorem}. Whereas \Cref{noname} doesn't have anything interesting.
We have \cref{boringLemma} and \cref{awesomeTheorem}. Whereas \cref{noname} doesn't have anything interesting.
Other environments go wrong. \hfill \textbf{what I want}\\
\Cref{fig} \hfill \CrefOrig{fig}\\
\Cref{eqt} \hfill \CrefOrig{eqt}\\
\Cref{sec} \hfill \CrefOrig{sec}\\
\Cref{tab} \hfill \CrefOrig{tab}
\end{document}
Output