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:
\documentclass{article}
\usepackage{hyperref}
\begin{document}
\href{http://link}{text}
\end{document}
Compiles fine. When I change the documentclass
to nohref
with nohref.cls
being
\def\document{
\everypar{}
}
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?
Best Answer
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.Produces
as the text width is not set up
as
\normalsize
is not definedas the aux file has not been opened for writing.
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.UPDATED AFTER COMMENTS