Is ntheorem[thref] truly incompatible with hyperref

abntex2hyperrefntheorempackage-options

I was using the texlive version from Ubuntu's repos, but then started needing some features from the latest versions of some packages, so I replaced the repos' texlive with a new system from https://tug.org/texlive/acquire-netinstall.html

Then, some documents that compiled perfectly started giving this error message
(let's call it a "bug"):

ERROR: Paragraph ended before \Hy@setref@link was complete.

(After a mini heart attack)
I managed to isolate the problem to this (sort-of-MWE):

\documentclass{abntex2}  % subclass of memoir that loads hyperref
% using any other class is not an option

\usepackage[
  backend = biber,
  %style = abnt, % this option doesn't matter for the bug
]{biblatex}

\usepackage[thref]{ntheorem}


\begin{document}
\section{Lorem ipsum}\label{loremipsum}

Reference to section~\ref{loremipsum}.
Some other text.

\end{document}

Some comments:

  • Some versions:
    ntheorem: 1.33 2011/08/15,
    abntex2: 1.9.7 2018/11/24,
    hyperref: 7.00 2022/06/20.
  • Changing the class from abntex2 to memoir (its base class) dispels the bug;
  • Omitting the thref option of ntheorem dispels the bug, but you must also erase the files the compilation generates, and then recompile;
  • Loading amsmath (with or without the amsmath option to ntheorem) has no effect on the bug;
  • Using the hyperref option in ntheorem has no effect also.

It seems I didn't really need the thref functionality described in the package's docs, so for now I'll just remove it,
but I'd appreciate if someone savvier could tell what went wrong, whether there's a way to fix it, etc.

(Although ntheorem[thref] and hyperref seem known not to get along very well,
they were behaving just fine with the slightly outdated versions from the Ubuntu repos,
behave fine with the memoir class,
and ntheorem should (theoretically=according to its docs) work with hyperref, as long as you give it the proper loading option,
so I think there's some value in pointing out this "bug").

Best Answer

unchanged things

The thref option of ntheorem is and was always incompatible with hyperref.

Without hyperref a label like \label{theo}[additional text] will write

\newlabel{theo}{{1}{1}}[additional text]

to the aux file, and a \thref can then retrieve the additional text.

enter image description here

If hyperref is loaded this no longer works. ntheorem contains here a bit of repair code to retrieve at least a "keyword", but the optional argument of \label can no longer be used:

\documentclass{article}
\usepackage[thref,hyperref]{ntheorem}
\usepackage{hyperref}

\begin{document}
\newtheorem{prop}{Proposition}

\begin{prop}[Hallo]\label{theo}[additional text]
abc
\end{prop}

Cite with thref: \thref{theo}
\end{document} 

enter image description here

what is new

Since a few months hyperref no longer delays the loading of nameref to \begin{document} but loads it directly. For your example that means that hyperref and nameref are both loaded before ntheorem and so no longer overwrite its \label definition to repair at least in part the damage the thref option does.

So either don't use this option, or force the loading of ntheorem before hyperref:

\AddToHook{package/hyperref/before}{\RequirePackage[thref,hyperref]{ntheorem}}
\documentclass ...

what is new 2023

Since the LaTeX release 2023-06-01, the LaTeX kernel itself defines \label as needed for links. hyperref therefore no longer redefines it later.

Now the thref option of ntheorem really harms, as it redefine \label in way that is not usable with LaTeX and hyperref. The option should not be used anymore!

Related Question