The hyperref package is returning the following error when I try to compile the pdf:
Argument of \Hy@setref@link has an extra }.
<inserted text>
\par
l.45
The line 45 is just an empty line between my paragraphs, there is no \ref
or \label
command. If I comment the \usepackage{hyperref}
statement the document compiles successfully. I'm using the template from overleaf that can be found here. I tried several solutions from similar errors but none worked for me. Couldn't find open {}
or other inconsistency. Deleting .aux
files, compiling online on overleaf or local via texstudio and teXshop also doesn't work and return the same error message.
My document follows the structure bellow:
\documentclass{comnet} % class from journal of complex networks
\bibpunct{[}{]}{,}{n}{,}{;}
\usepackage[utf8]{inputenc}
\usepackage{microtype}
\usepackage{graphicx}
\usepackage{algorithmicx}
\usepackage{hyperref}
\begin{document}
\title{Complicated title}
\shorttitle{Complicated title}
\shortauthorlist{author 1, author 2}
\author{
\name{author 1}
\address{springfield}
\name{author 2}
\address{springfield}}
\maketitle
\begin{abstract}
{abstract text}
{key words}
\end{abstract}
\section{Introduction}
\section{section 1}
\subsection{section 1.1}
\section{section 2}
\section{Conclusion}
\bibliographystyle{comnet}
\bibliography{mybib}
\end{document}
I also noted that if I comment the maketitle
command the document is able to compile. Can anyone give a clue of what can I do to solve this?
Best Answer
The error comes not directly from
\maketitle
itself, but from the\thispagestyle{plain}
macro usage in\maketitle
.The
plain
page style is defined incomnet.cls
asNow,
\fpage
and\lpage
(used in\@oddhead
) are shortcuts toHere the real error comes in:
\label{FirstPage}
is written at the start of the document, due to the\AtBeginDocument
hook, buthyperref
is loaded later on, redefining the\label
etc. macros with additional information on the labeling, meaning that\label{FirstPage}
writes too few information to the.aux
file forhyperref
to grab it with the redefined\pageref
command.A look into the
.aux
file after first compilation run of the document shows (unnecessary information not given here) -- the first run is 'ok', the second compilation shows the error then!It is obvious, that
LastPage
has more information 'slots' (especially thepage.2
anchor) which is expected byhyperref
to be read, but this does not work forFirstpage
.The solution is to change
\fpage
to\def\fpage{\pageref{CorrectFirstPageLabel}}
and add theCorrectFirstPageLabel
after loading ofhyperref
.Another solution would be to redefine
\ps@plain
in order to remove the\fpage
macro and replace it with1
, but I don't recommend this, since other authors could make use ofplain
style at places in the document other than for the title page as well.The error vanishes of course if
hyperref
is not loaded at all, whether the Journal of Complex Networks allowshyperref
ed document submissions is not known to me. In doubt omithyperref
rather then.Update
Here is a minimal non - working version that has the same issue by forcing a label in
\AtBeginDocument
and loading thehyperref
package after that:The
.aux
file containsThe
foolabel
is from the regular\label
command as defined inlatex.ltx
, storing the section number1
for the first page, whereas the second label definition is extended byhyperref
to contain2
1
Foo again
, to be extracted with\nameref
or\nameref*
section.2