I am perplexed by the error:
Use of \@uad doesn't match its definition.
\kernel@ifnextchar ...rved@d =#1\def \reserved@a {
#2}\def \reserved@b {#3}\f...
l.11 ...iversity.edu}{mailto:a2@myuniversity.edu}}
Arising in the following minimal tex file using the standard elsarticle class:
\documentclass{elsarticle}
\usepackage{hyperref}
\begin{document}
\begin{frontmatter}
\title{Remarks on something interesting}
\author[myu]{Author 1}
\ead{a1@myuniversity.edu}
\author[myu]{Author 2 \corref{cor1}}
\ead{\href{mailto:a2@myuniversity.edu}{mailto:a2@myuniversity.edu}}
\address[myu]{My Department, My Building, My University in My City}
\cortext[cor1]{Corresponding author}
\end{frontmatter}
\maketitle
A \href{http://google.com}{link to google.com}
\end{document}
It looks as though the class file doesn't support \href
arguments here, but it is not obvious to me why that is. So, I'm left with several questions:
-
What does this error mean?
-
How I might go about modifying either the
.tex
or the.cls
file so that the above can be compiled successfully?
I've taken a look at where \ead
is defined in the class field but lack the tex-foo to figure out what's going on. I believe the relevant lines are:
\def\ead{\@ifnextchar[{\@uad}{\@ead}}
\gdef\@ead#1{\bgroup\def\_{\string\_}\def\{{\string\{}%
\def\}{\string\}}%
\edef\tmp{\the\@eadauthor}
\immediate\write\@auxout{\string\emailauthor
{#1}{\expandafter\strip@prefix\meaning\tmp}}%
\egroup
}
The error seems like it might be related to how and where tex defines macros, but that is a bit over my head.
Background: Not directly relevant to this question, but sometimes context is useful. I encounter this when trying to use the elsarticle template in RStudio's rmarkdown, which uses pandoc with the option autolink_bare_uris
which apparently cannot be turned off. This forces pandoc to transform bare emails into href
'd ones, rather annoyingly breaking this template.
Best Answer
The
\ead
command inelsarticle
writes the\emailauthor
command to theaux
file with the passed email address and the associated author as arguments. On subsequent runs, theaux
file is read and the\emailauthor
command is executed. The issue with adding\href
as you have tried is that the\immediate\write\@auxout
tries to expand it prior to writing the contents to theaux
file, resulting in the error. As we want\href
to be written to theaux
file, you can do what you are after by prefacing\href
with\string
or\noexpand
. For example:You can check the
aux
file to see the following line (as expected):Additionally, you can automate hyperlinking for all author emails and urls by modifying
\@ead
and\@uad
, repsectively, with the following:The
\ifhyperrefloaded
is used to so that the\patchcmd
calls are in the global scope and only used if thehyperref
package is loaded.Finally, I took the liberty of removing the
mailto:
from the displayed portion of\href
and the unnecessary\maketitle
from your MWE.The result: