I am trying to debug a custom documentclass that I need to use, in which the hyperref package (\href command) doesn't work.

This is my document:





Compiles fine. When I change the documentclass to nohref with nohref.cls being


it fails to compile, throwing

\hyper@linkurl ...tionraw >>}\relax \Hy@colorlink 
                                                  \@urlcolor #1\Hy@xspace@en...
l.9   \href{http://link}{text}

How do I need to change my code to make this work?

  • 1
    the nohref.cls you show redefines \document and will completely break latex, it's suprising that anything works without error. what is the intention of that file? Sep 17 '21 at 17:05
  • Well... It's a template for official letters from our university with headers, logo etc. that seems to have been passed on from generation to generation. According to the comments it's almost 30 years old ^^ Sep 17 '21 at 19:14
  • Note: It's actually a 840-lines class definition, I just removed all of it line by line to come up with the minimal example here. Sep 17 '21 at 19:14
  • but if it contains that definition of \document then it can never possibly have worked. Sep 17 '21 at 19:15
  • It is possible that you deleted too much, 840 lines isn't that much you could post the whole thing, in particular if the zzz example in my example works without error with the real class then you have deleted too much. Sep 17 '21 at 19:17

The class file shown completely breaks LaTeX, essentially nothing will work.

Redefining \document means that none of the things that normally are set up at \begin{document} happen.





Overfull \hbox (20.0pt too wide) in paragraph at lines 5--6

as the text width is not set up

! LaTeX Error: The font size command \normalsize is not defined:
               there is probably something wrong with the class file.

as \normalsize is not defined

\gdef \@abspage@last{1}

as the aux file has not been opened for writing.

! I can't find file `file.aux'.
\enddocument ...keatletter \@@input \jobname .aux 

Because the aux file was not written so can not be input at the end.

Specifically with hyperref none of the setup that it normally does \AtBeginDocument happens as the redefined \document never runs that code. But the exact error is fairly arbitrary as essentially no LaTeX constructs will work and will generate errors at more or less arbitrary internal failures.

In the linked chat the OP confirmed that the actual class being used was not quite as minimal, but almost as bad, it defined \document based on the LaTeX2.09 definition so in particular it does not run any code specified to run in \AtBeginDocument{...} any code specified to run there is silently discarded.

hyperref like many other classes delays lots of its setup with \AtBeginDocument which is why the colour in particular failed.

Adding the two lines below to run the AtBeginDocumentHook is a minimal patch to make the example work, but the class has not really been usable for 30 years. Note \document has further changes to add more hooks in the 2021 release and these are all broken by this class, you would need \RequirePackage[2020/01/01]{latexrelease} in the document to undo these updates.


 \@colht\textheight \@colroom\textheight \vsize\textheight
 \columnwidth\textwidth \@clubpenalty\clubpenalty
 \if@twocolumn \advance\columnwidth -\columnsep
 \divide\columnwidth\tw@ \hsize\columnwidth \@firstcolumntrue
 \hsize\columnwidth \linewidth\hsize
 \if@filesw \immediate\openout\@mainaux=\jobname.aux
% support \AtBeginDocment
 \def\do##1{\let ##1\@notprerr}

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.