When using ntheorem
with the thref
option to get the named reference command \thref
, sometimes the theorem numbers produced is "different" from the theorem numbers produced by just \ref
. Any suggestions on fixes/workarounds?
Here's a MWE:
\documentclass{book}
\usepackage{amsmath}
\usepackage[standard,amsmath,thref,hyperref]{ntheorem}
\usepackage{hyperref}
\makeatletter
\@addtoreset{chapter}{part}
\makeatother
\numberwithin{Theorem}{section}
\begin{document}
\part{Part 1}
\chapter{Chaptername}
\section{Test}
\begin{Theorem}\label{test1} Test theorem
\end{Theorem}
Cite with ref: \ref{test1}
Cite with thref: \thref{test1}
\end{document}
Which compiles to
Notice in particular that the \thref
output shows Theorem 1.1.1.1, the first (extra) 1 belonging to the \part
.
\documentclass{book}
\usepackage{amsmath}
\usepackage[standard,amsmath,thref]{ntheorem}
\makeatletter
\@addtoreset{chapter}{part}
\makeatother
\numberwithin{Theorem}{section}
\begin{document}
\part{Part 1}
\chapter{Chaptername}
\section{Test}
\begin{Theorem}\label{test1} Test theorem
\end{Theorem}
Cite with ref: \ref{test1}
Cite with thref: \thref{test1}
\end{document}
Without using hyperref, however, everything looks fine:
Remarks
Without the \@addtoreset{chapter}{part}
line, the output is okay. However, I need the \@addtoreset{chapter}{part}
because for this thing I am working on I want the chapter numbers to be within individual parts, and without explicitly setting this, hyperref
fouls up and gets confused between equation 1.1.1 of part 1 and equation 1.1.1 of part 2.
Best Answer
I don't think I understand: how can your reader distinguish between Theorem 1.1.1 in Part 1 from Theorem 1.1.1 in Part 2?
The following hack seems to work, but, like every hack, it might have unexpected consequences.
In order to get correct hyperlinks,
\thref
doesn't use\theTheorem
, but the more complex\theHTheorem
, which is set up byhyperref
. This representation of the internal counterHTheorem
(which is synchronized withTheorem
) must take into account the part number or wrong and duplicate links would be produced.The hack consists in modifying the definition of
\thm@fmt@hyplabel
that's usually defined as\def\thm@fmt@hyplabel@ii#1.#2{#2}
and put in front of the internal reference produced byhyperref
: in the "normal" case this would bebut with your setting it is
Thus the normal definition of
\thm@fmt@hyplabel
is producing the part number, while you want the chapter number; hence the modified definition.