Problems with theoremref

I'm having some problems with the theoremref package. Basically, instead of giving me as output something like "Lemma 1.1.1", where "Lemma" is the name of the theorem, it gives me something like "lem 1.1.1", where "lem" is the theorem identifier. Here's my code:

\documentclass{article}

\usepackage[amsthm, thmmarks]{ntheorem}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{array}
\usepackage{makeidx}
\usepackage{mathrsfs}
\usepackage{theoremref}

\newtheorem{lem}{Lemma}[subsection]

\begin{document}

\section{Section}

\subsection{Subsection}

\begin{lem}\thlabel{test}
Test
\end{lem}

As we can see from \thref{test}

\end{document}


And here's the output:

What am I doing wrong?

• Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Jan 27, 2014 at 6:22
• My suggestion is not to use ntheorem, but amsthm. In my opinion, ntheorem just seems better or more powerful, but it makes more problems than it solves. Jan 27, 2014 at 8:31

From the theoremref documentation (section 4 Caveats, p 3):

The new referencing commands only work for theorem environments declared using the \newtheorem command. You cannot use them for e. g. tables, figures, equations, sections, and other environments.

So far so good... now, the ntheorem documentation (section 3.2.2 amsthm, p 16):

amsthm.sty conflicts with the definition of theorem layouts in theorem.sty, some features of amsthm.sty have been incorporated into option [amsthm] which has to be used instead of \usepackage{amsthm}.
...
The command \newtheoremstyle is not taken over from amsmath.sty. ...

The change of interface provided by ntheorem seem to make it incompatible with theoremref in this way. You need a little more fudging to make it work:

\documentclass{article}

\usepackage{amsmath}
\usepackage[amsthm, thmmarks]{ntheorem}
\makeatletter
\let\old@thm\@thm
\usepackage{theoremref}
\def\@thm#1#2#3{\def\thmref@currname{#3}\old@thm{#1}{#2}{#3}}
\makeatother

\newtheorem{lem}{Lemma}[subsection]

\begin{document}

\section{Section}

\subsection{Subsection}

\begin{lem}\thlabel{test}
Test
\end{lem}

As we can see from \thref{test}

\end{document}


The above suggested solution stems from the compatibility of theoremref with amsthm, and the following lines in theoremref.sty that captures the theorem type/name:

%hook in \@thm to get the name
\def\thmref@newthm#1#2{\thmref@lc{\def\thmref@currname{#2}}%
\thmref@oldthm{#1}{#2}}
\def\thmref@amsthm#1#2#3{\thmref@lc{\def\thmref@currname{#3}}%
\thmref@oldthm{#1}{#2}{#3}}


Later on, depending on whether or not amsmath is loaded, a replacement is made:

\AtBeginDocument{\thmref@setup}
\def\thmref@setup{%
\let\thmref@oldthm\@thm
{\let\@thm\thmref@newthm}%
\expandafter\let\csname thlabel\space\endcsname\thlabel@hyperref
\let\thmref@setref\thmref@sethyp
}\relax
\ifx\thmref@th\@undefined\else\let\th\thmref@th\fi%
}


It may also be sufficient to fool that package in thinking amsmath is loaded (be setting \ver@amsthm.sty to anything other than \relax).

There is some incompatibility between ntheorem and theoremref.

Since ntheorem defines its own \thref command when loaded with the thref option, I suggest you simply not to load theoremref.

MWE:

\documentclass{article}

\usepackage[amsthm,thmmarks,thref]{ntheorem}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{array}
\usepackage{makeidx}
\usepackage{mathrsfs}
%\usepackage{theoremref}

\newtheorem{lem}{Lemma}[subsection]

\begin{document}

\section{Section}

\subsection{Subsection}

\begin{lem}\label{test}
Test
\end{lem}

As we can see from \thref{test}

\end{document}


Output: