How can I patch the natbib
commands \citep
, \citet
and the like? I have tried xparse
(MWE below), etoolbox
(the \pretocmd
and \apptocmd
commands) and xpatch
(the \xpretocmd
and \xapptocmd
commands) without any measureable success.
This is an attempt to find an automatic workaround for the error \pdfendlink ended up in different nesting level than \pdfstartlink that occurs when a link spans two pages. (Even with newest hyperref
, I'm seeing the error in twocolumn format.) The intention is to wrap all occurrences of \citep...{...}
and the like into an \mbox{}
. Note: This is not for publishing, this is just for making sure that intermediate states of my LaTeX document in development compile cleanly. I don't want to fix things that probably disappear anyway when the document is released.
EDIT: Originally, I was thinking that this would be a very simple thing to do, open-and-shut. What makes LaTeX behave so oddly in this particular case?
Another way to solve the practical issue behind this is to use Non-breaking space in \citet using natbib?
However, this doesn't work for some reason in my case (natbib
+ hyperref
+ babel
; sorry, no MWE here...) Yet another way would be to restrict the link to a single word in the reference (e.g., to the year), or to add a Wikipedia-style link icon instead of marking the entire reference as clickable.
MWE (also on GitHub)
The following code gives me the error shown below:
\documentclass{scrartcl}
\pagestyle{empty}
\usepackage{xparse}
\usepackage[authoryear,round]{natbib}
\let\oldcitep=\citep
\RenewDocumentCommand{\citep}{O{} O{} m}{\oldcitep{#3}}
\NewDocumentCommand{\citex}{O{} O{} m}{\oldcitep{#3}}
\begin{document}
\citep{SomeRef}
\end{document}
Error message
Runaway text?
\citep code {}{}{SomeRef}{SomeRef}{SomeRef}{SomeRef}{SomeRef}{SomeRef\ETC.
! TeX capacity exceeded, sorry [main memory size=5000000].
\l__xparse_args_tl ...omeRef}{SomeRef}{SomeRef}{So
meRef}{SomeRef}{SomeRef}{S...
l.12 \citep{SomeRef}
What baffles me most: When I replace \citep
by \citex
in the document body, the document compiles.
biblatex
? For your own documents,biblatex
is far better and flexible. For publication, the chance is high that they will simply ignore your fix.citep
can take a starred form, internally there is some stuff going on, very different macros for the open ( and the closing ) and the cite in between.