I have lately been creating custom classes, and found that one of my desired commands, \xpatchcmd, did not work on some occassions. I spotted that loading of package hyperref is the culprit.
For reference, I'm referring to this answer's application of \xpatchcmd, which I implemented in my own MWE:
Intended outcome (without loading hyperref)
In the minimal setup it works as intended, giving the horizontal rule:
\documentclass{article}
\usepackage{xpatch}
\makeatletter
\xpatchcmd{\maketitle}{@date}{@date\par\rule{\textwidth}{1pt}}{}{}
\makeatother
\begin{document}
\title{My Title}
\author{My Name}
\maketitle
\end{document}
Unexpected outcome (with loading hyperref)
If I additionally load hyperref, then the patch does not apply:
\documentclass{article}
\usepackage{xpatch}
\usepackage{hyperref}
\makeatletter
\xpatchcmd{\maketitle}{@date}{@date\par\rule{\textwidth}{1pt}}{}{}
\makeatother
\begin{document}
\title{My Title}
\author{My Name}
\maketitle
\end{document}
Further thoughts
- I have found this behaviour is not limited to documentclass
article. The same unexpected results are obtained with e.g.scrbook. - I am intentionally loading
hyperrefas the last package. Even changing the order ofxpatch`andhyperref`` did not change the behaviour. - I found no incompatibilities between either packages mentioned in their respective documentations.
Question
How can I load hyperref and get the desired patch working?



hyperrefchanges the definition. However, I am not really interested in thearticleclass only, but in working around/with this change in arbitrary classes. Take, e.g.scrbook, where I also want to be able to inject code. There,\maketitle and@maketitleare more convoluted, but yur example for thearticle`` class was sufficient in getting me towards the right path. – marc Aug 05 '22 at 21:46