[Tex/LaTex] How to show the labels of theorems, definitions, etc

showlabelstheorems

I'm using the package showlabels which has the effect that when I label something with \label{thing1} the thing1 gets typeset in the margin of my document next to where I put the label. This works fine for equations in align and proof environments, and things like that.

The problem is that it does not work when I label a theorem, which I do like this:

\begin{theorem}\label{fact1}
Important math statement.
\end{theorem}

I can still refer to said theorem via \ref{fact1}
but I cannot get the label to typeset in the margin next to the theorem.

EDIT:
I originally failed to include a compilable example of the problem. @DavidCarlisle posted an example of the problem not occurring, but with showlabels replaced with showkeys, upon which I noticed that showkeys did not produce the problem.

Looking more closely at my preamble, the problem had to do with the hyperref package. The following does not result in the label on the theorem being displayed.

\documentclass{article}

\usepackage{showlabels}
\usepackage{hyperref}
\usepackage[english]{babel}

\newtheorem{theorem}{Theorem}[section]

\begin{document}

\begin{theorem}\label{a theorem}
    Important math statement.
\end{theorem}

\end{document}

On the other hand, if one moves the hyperref package so it is implemented before showlabels, as follows, it works.

\documentclass{article}

\usepackage{hyperref}
\usepackage{showlabels}
\usepackage[english]{babel}

\newtheorem{theorem}{Theorem}[section]

\begin{document}

\begin{theorem}\label{a theorem}
    Important math statement.
\end{theorem}

\end{document}

Best Answer

With showlabels

enter image description here

\documentclass{article}
\usepackage{showlabels}
\newtheorem{theorem}{Theorem}

\begin{document}

\section{Zzzz}
zzz

\begin{theorem}\label{fact1}
Important math statement.
\end{theorem}

\end{document}

enter image description here

or with showkeys

\documentclass{article}
\usepackage{showkeys}
\newtheorem{theorem}{Theorem}

\begin{document}

\section{Zzzz}
zzz

\begin{theorem}\label{fact1}
Important math statement.
\end{theorem}

\end{document}
Related Question