1

I am using the popular res.cls for my resume (CTAN Link)

I would like to put internal links in my file. However, the following does not successfully place the internal links:

\documentclass{res}

\usepackage{hyperref}


\begin{document}

\section{Section 1}
\label{sec:part1}

\hyperref[sec:part1]{Jump to Section 1}

\hyperref[sec:part2]{Jump to Section 2}

\section{Section 2}
\label{sec:part2}

\hyperref[sec:part1]{Jump to Section 1}

\hyperref[sec:part2]{Jump to Section 2}

\end{document}

However, if I use a built-in .cls the links are placed successfully:

\documentclass{article}

\usepackage{hyperref}


\begin{document}

\section{Section 1}
\label{sec:part1}

\hyperref[sec:part1]{Jump to Section 1}

\hyperref[sec:part2]{Jump to Section 2}

\section{Section 2}
\label{sec:part2}

\hyperref[sec:part1]{Jump to Section 1}

\hyperref[sec:part2]{Jump to Section 2}

\end{document}

What modifications need to be made to the .cls file in order for this to behave as expected?

  • 2
    res is an outdated class and popular is arguable ;-) Don't use it. The main cause is that res explicitly states \nofiles in the class file, which is totally absurd and leaves no user control – user31729 Jun 24 '17 at 19:41
4

res.cls is a strange class and should not be used, in my point of view. It has the explicit\nofiles statement in the class file, which prevents the generation of the auxiliary files such as .aux, which is needed desperately by hyperref.

Another issue is that \section is effectively redefined, so there is no counter used at all, i.e. \refstepcounter and \label is actually useless :-(

One possible solution (amongst not using res.cls) is to say \let\nofiles\relax before \documentclass{res}.

Using something like

\makeatletter
\@fileswtrue
\makeatother

does not solve the problem, since \protected@write is redefined within \nofiles to write to the terminal always, so nothing would be gained here really.

The \label issue can be solved by prepending the \section command with \phantomsection.

\let\nofiles\relax
\documentclass{res}
\usepackage{etoolbox}
\usepackage{hyperref}

\pretocmd{\section}{\phantomsection}{}{}
\begin{document}


\section{Section 1}
\label{sec:part1}

\hyperref[sec:part1]{Jump to Section 1}

\hyperref[sec:part2]{Jump to Section 2}

\clearpage
\section{Section 2}\label{sec:part2}

\hyperref[sec:part1]{Jump to Section 1}

\hyperref[sec:part2]{Jump to Section 2}

\end{document}

Much cleaner ways: Use \hyperlink or cleveref or \nameref.

| improve this answer | |
  • I omitted a screenshot since there's nothing visually interesting to show – user31729 Jun 24 '17 at 19:58

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.