# Remove numbering of unreferenced theorems

Can theorems, lemmas, etc., be automatically displayed without numbers if not referenced (like \mathtoolsset{showonlyrefs} for equation tags)?

• You might want to refer to a lemma when exposing the contents of the paper; a number can be handy anyway. – egreg Jan 13 '14 at 12:41
• That is true. The question remains though. – user66081 Jan 13 '14 at 14:14
• Damn, where is my please-do-not-do-that tag when I need it? – yo' Jan 29 '14 at 18:07
• If you know what it looks like, just fake it. In other words, don't use \begin{theorem} etc. – John Kormylo Jan 29 '14 at 19:00
• right now I'm using starred environments, but this is not good enough. I'm writing lecture notes, and it is not always clear where to put a star; I think it is helpful to omit numbers as an indication that a particular Example/Lemma/etc has local impact. (It would be even better to have a list of where it is used, if at all). – user66081 Jan 29 '14 at 19:02

This is certainly not the most elegant solution but it works:

\documentclass{article}
\usepackage{amsthm}

\newcommand{\helpercommand}{}
\newcommand{\thmref}[1]{\label{thm#1}\ref{#1}}
\newtheorem{theorem}{Theorem}
\newtheorem*{theorem*}{Theorem}
\newenvironment{thm}[1]
{
\renewcommand{\helpercommand}{#1}
\ifcsname r@thm#1\endcsname\begin{theorem}\else\begin{theorem*}\fi\label{#1}
}
{
\ifcsname r@thm\helpercommand\endcsname\end{theorem}\else\end{theorem*}\fi
}

\begin{document}

\begin{thm}{labelA}
This theorem is referenced later.
\end{thm}

\begin{thm}{labelB}
This is not.
\end{thm}

\begin{thm}{labelC}
This is again.
\end{thm}

Theorems \thmref{labelA} and \thmref{labelC} are great!
\end{document}


• doesn't this produce multiply defined labels if, say, \thmref{labelA} is used multiple times? – user66081 Feb 3 '14 at 18:01