3

I am attempting to use the tufte-handout document class with the verse package. However, it seems that tufte-handout loads hyperref by default and this causes the following error in verse.sty:

! LaTeX Error: Command \theHpoemline already defined.

Researching options for resolution led me to this answer: What is the right way to use hyperref options with Tufte handout class?

Loading with the nohyper option on the tufte-handout document class does allow the verse package to function, but I also need the hyperref package. (Loading hyperref after the fact still results in the same error.)

How do I manage this apparent incompatibility?

MWE:

\documentclass{tufte-handout}
\usepackage{verse}

\begin{document}
\begin{verse}
    A sprig, with its flower, I break.
\end{verse}
\end{document}
  • 1
    It's a very bad mistake for any class to load hyperref unconditionally, because the user might want to load other packages and this will, in many cases, create incompatibilities, as hyperref needs to be called last (with a few exceptions). – egreg Apr 18 '15 at 13:54
  • @egreg: I agree with that, but isn't it equally bad from verse package designers to define a \theHpoemline command while it's known that \theH.... commands are introduced by hyperref automatically? – user31729 Apr 18 '15 at 15:59
  • 1
    @ChristianHupfer Yes, of course. – egreg Apr 18 '15 at 16:17
6

This should work: Temporarily disable the loading of hyperref and load it after verse. verse (unnecessarily?) defines \theHpoemline counter format, in my point of view.

\documentclass[nohyper]{tufte-book}
\usepackage{verse}
\usepackage{hyperref}

\begin{document}
\begin{verse}
    A sprig, with its flower, I break.
\end{verse}
\end{document}

A dirty workaround, without direct changes in verse.sty

Since verse.sty defines a counter poemline, hyperref will do automatically a \theHpoemline definition. However, this is bad, since

\newcommand*{\theHpoemline}{\arabic{verse@envctr}.\arabic{poemline}}

is used in verse.sty.

A workaround is to use \providecommand temporarily instead of \newcommand, which does not complain about already existing commands and after verse is loaded, switch back to \newcommand.

\documentclass{tufte-book}
%\hypersetup{colorlinks=true} Not needed, just for debug
\let\orignewcommand\newcommand  % store the original \newcommand
\let\newcommand\providecommand  % make \newcommand behave like \providecommand
\RequirePackage{verse}
\let\newcommand\orignewcommand  % use the original `\newcommand` in future
\makeatletter
% Use the original definition from verse.sty
\renewcommand*{\theHpoemline}{\arabic{verse@envctr}.\arabic{poemline}}
\makeatother

\begin{document}
\tableofcontents
\chapter{first}

\chapter{second}
\begin{verse}
    A sprig, with its flower, I break.
\end{verse}
\end{document}
  • Works on the MWE, but beyond this complexity, does not work. (The sample-handout.tex file included with tufte still breaks with deferred loading on hyperref when verse is also loaded.) I'll see if I can complicate my MWE to replicate. – twip Apr 18 '15 at 6:00
  • @twip: Yes, I feared that it wouldn't work for a larger document – user31729 Apr 18 '15 at 6:09
  • Compiles with the updated workaround. Thank you for digging deeper. – twip Apr 18 '15 at 16:10
  • @twip: You're welcome. Happy TeXing ;-) – user31729 Apr 18 '15 at 16:11
-1

I had the same problem and solved it tidily by loading package \hyperref before loading \verse.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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