8

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

8
  • You might want to refer to a lemma when exposing the contents of the paper; a number can be handy anyway.
    – egreg
    Jan 13, 2014 at 12:41
  • That is true. The question remains though.
    – user66081
    Jan 13, 2014 at 14:14
  • 4
    Damn, where is my please-do-not-do-that tag when I need it?
    – yo'
    Jan 29, 2014 at 18:07
  • If you know what it looks like, just fake it. In other words, don't use \begin{theorem} etc. Jan 29, 2014 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, 2014 at 19:02

1 Answer 1

9
+100

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}

referenced theorems

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

You must log in to answer this question.

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