Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I initially thought that this problem was with Unicode characters, but reducing the file led to the MWE below which has none, so it seems that theoremref and hyperref don't like each other. Consider:

\documentclass{book}
\usepackage{theoremref}
\usepackage{hyperref}
\newtheorem{theorem}{Theorem}

\begin{document}
\begin{theorem}
\thlabel{vmezofelint}
Sample text
\end{theorem}
Sample text (see \thref{vmezofelint} ) .
\end{document}

It produces an error message saying

File ended before scanning use of \Hy@setref@link.

My question is: does anyone know a fix, or a simple workaround for this bug? One that requires few changes to the code?

UPDATE: The problem no longer exists with the latest version of theoremref. See the maintainer's answer below.

share|improve this question

3 Answers 3

up vote 8 down vote accepted

Just don't use theoremref:

\documentclass{book}
\usepackage{hyperref}
\newtheorem{theorem}{Theorem}

\begin{document}
\begin{theorem}\label{vmezofelint}
Sample text
\end{theorem}
Sample text (see \autoref{vmezofelint}).
\end{document}

enter image description here

Expanded definition

One can set up a new theorem defining command, so the necessary steps to get the \autoref right are made once and for all.

\documentclass{book}

\usepackage{xparse,aliascnt,hyperref,bookmark}

\NewDocumentCommand{\xnewtheorem}{m o m}
 {%
  \IfNoValueTF{#2}
   {\newtheorem{#1}{#3}}
   {%
    \newaliascnt{#1}{#2}%
    \newtheorem{#1}[#1]{#3}%
    \aliascntresetthe{#1}%
    \expandafter\newcommand\csname #1autorefname\endcsname{#3}%
   }%
 }

\xnewtheorem{theorem}{Theorem}
\xnewtheorem{corollary}[theorem]{Corollary}

\begin{document}
\begin{theorem}\label{vmezofelint}
Sample text
\end{theorem}
Sample text (see \autoref{vmezofelint}).
\begin{corollary}\label{cor}
Sample text
\end{corollary}
Sample text (see \autoref{cor}).
\end{document}

enter image description here

share|improve this answer
    
I've changed it, but now, given that my numerous theorem environments all share the same counter (I don't like two entities with the same number), I had to add 3 more lines for each \newtheorem: \newcommand{\<name>autorefname}{<Name>} \newaliascnt{<name>}{theorem} \aliascntresetthe{<name>} That's tedious! –  marczellm Nov 10 '12 at 11:39
1  
@marczellm I've added a way to define an \xnewtheorem command, so all you need is to change \newtheorem into \xnewtheorem –  egreg Nov 10 '12 at 12:03
    
Why is the bookmark package needed in this case? Also, have you considered writing a package with all these useful hacks and submitting it to CTAN? I always feel that there should be a "canonical" way of solving these problems other that copy-pasting a 20-line hack into the preamble. –  marczellm Dec 8 '12 at 9:39
    
@marczellm bookmark is just a convenience, because it manages bookmarks better than the default method used by hyperref. The code is there, if you want; I don't believe very much in automatic references. –  egreg Dec 8 '12 at 9:50

If you're willing to use the cleveref package and its \cref command instead of the hyperref package's \autoref command, the following method may be all you need (using @egreg's MWE - many thanks!):

\documentclass{book}

\usepackage{ntheorem}
\usepackage[colorlinks]{hyperref}
\usepackage[nameinlink,capitalize]{cleveref}
  % nameinlink and capitalize options used to emulate
  % appearance of output of \autoref command
\newtheorem{theorem}{Theorem}
\newtheorem{corollary}[theorem]{Corollary}

\begin{document}
\begin{theorem}\label{vmezofelint}
Sample text
\end{theorem}
Sample text (see \cref{vmezofelint}).
\begin{corollary}\label{cor}
Sample text
\end{corollary}
Sample text (see \cref{cor}).
\end{document}

enter image description here

share|improve this answer
    
That's a very good solution indeed! No need to RenewDocumentCommand and all the hacking. Unfortunately I'm writing in Hungarian and cleveref typesets all the references using their environment name, not the display label. (My environments are defined this way: \newtheorem{corollary}[theorem]{Következmény} but cleveref still prints "lásd Corollary 2" instead of "lásd Következmény 2" and I want to keep all code English.) –  marczellm Nov 10 '12 at 22:40

I wasn’t aware of this discussion, however since someone else recently complained about the incompatibility of the two packages, I’ve updated the theoremref package to add support for hyperref. It should be available through CTAN shortly.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.