The \ead
command in elsarticle
writes the \emailauthor
command to the aux
file with the passed email address and the associated author as arguments. On subsequent runs, the aux
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 the aux
file, resulting in the error. As we want \href
to be written to the aux
file, you can do what you are after by prefacing \href
with \string
or \noexpand
. For example:
\ead{\string\href{mailto:a2@myuniversity.edu}{a2@myuniversity.edu}}
You can check the aux
file to see the following line (as expected):
\emailauthor{\href{mailto:a2@myuniversity.edu}{a2@myuniversity.edu}}{Author 2 \corref {cor1}}
Additionally, you can automate hyperlinking for all author emails and urls by modifying \@ead
and \@uad
, repsectively, with the following:
\usepackage{etoolbox}
\makeatletter%placed AFTER \usepackage{hyperref}, if to be used
\newif\ifhyperrefloaded\hyperrefloadedfalse
\@ifpackageloaded{hyperref}{\hyperrefloadedtrue}{\hyperrefloadedfalse}%check if hyperref is loaded
\ifhyperrefloaded%
\patchcmd{\@ead}{#1}{\string\href{mailto:#1}{#1}}{}{}
\patchcmd{\@uad}{#2}{\string\url{#2}}{}{}\fi
\makeatother
The \ifhyperrefloaded
is used to so that the \patchcmd
calls are in the global scope and only used if the hyperref
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:
\documentclass{elsarticle}
\usepackage{hyperref}
\usepackage{etoolbox}
\makeatletter%placed AFTER \usepackage{hyperref}, if to be used
\newif\ifhyperrefloaded\hyperrefloadedfalse
\@ifpackageloaded{hyperref}{\hyperrefloadedtrue}{\hyperrefloadedfalse}%check if hyperref is loaded
\ifhyperrefloaded%
\patchcmd{\@ead}{#1}{\string\href{mailto:#1}{#1}}{}{}
\patchcmd{\@uad}{#2}{\string\url{#2}}{}{}\fi
\makeatother
\begin{document}
\begin{frontmatter}
\title{Remarks on something interesting}
\author[myu]{Author 1}
\ead{a1@myuniversity.edu}
\author[myu]{Author 2 \corref{cor1}}
\ead{a2@myuniversity.edu}
\ead[url]{www.google.com}
\address[myu]{My Department, My Building, My University in My City}
\cortext[cor1]{Corresponding author}
\end{frontmatter}
A \href{http://google.com}{link to google.com}
\end{document}
(edited to discuss the use of \fntext
directives to provide additional information about an author, such as that he/she is to be taken to be a "corresponding author")
You wrote,
I need to put 3 corresponding authors using the elsarticle
class.
If all you need to do is list the authors' correspondence addresses, you should definitely not be using the \corref
/\cortext
machinery to provide address-related information. Instead, use \address
directives to state the authors' correspondence addresses.
A general comment: It usually makes little sense to list more than 1 author as "corresponding" author. The whole point of designating an author as the "corresponding author" is to channel inquiries, comments, suggestions, criticisms, and all other communications to a single person. If all authors of a journal article are in a position to react to communications about their journal article, there's simply no need to provide footnotes to point out that all authors are, in fact, qualified to receive communications related to the article.
The elsarticle
document class actually allows one to specify 1 or 2 authors to be "corresponding" authors via \corref
and \cortext
directives. If, for whatever reason, you need to designate more than 2 authors as "corresponding" authors, I would recommend that you use \fnref
and \fntext
machinery to do so (and, conversely, not use the \corref
/\cortext
machinery).
Given the information you provided in your code fragment, it's probably a very good idea to employ \address
directives to state the authors' correspondence addresses. If you need to provide email addresses as well, provide \ead
directives immediately after the corresponding \author{...}
directives.
In the following screenshot, I've highlighted the various footnote-type markers. Note that only 1 author is designated as the "corresponding" author.
\documentclass{elsarticle}
\title{A title}
\author[1]{Name1\fnref{firstfoot}}
\author[2]{Name2\corref{aaa}\fnref{secondfoot}}
\author[3]{Name3\fnref{thirdfoot}}
\cortext[aaa]{Corresponding Author}
\address[1]{Mailing Address 1}
\address[2]{Mailing Address 2}
\address[3]{Mailing Address 3}
\fntext[firstfoot]{Affiliation1}
\fntext[secondfoot]{Affiliation2}
\fntext[thirdfoot]{Affiliation3}
\date{\today}
\setlength\textheight{5cm} % just for this example
\begin{document}
\maketitle
\end{document}
Best Answer
Although I agree that it is not clear from the documentation or the 8th entry in the FAQ pointed out by Werner, all the templates use
\title
,\author
,\ead
etc after\begin{document}
and\begin{frontmatter}
.The reason it does not work before
\begin{document}
is that (for some reason), it writes the email addresses to theaux
file (which means it needs two runs), and theaux
file doesn't get read and re-opened for writing until\begin{document}
(so in fact you see lines like\emailauthor{a1@myuniversity.edu}{Author 1}
appearing on the terminal instead of getting written to theaux
file).Note that the
frontmatter
environment does nothing except\maketitle
at the end (and some grouping), so I guess the supported syntax is to replace your\maketitle
with thefrontmatter
environment. I have also done this in the following modification of your example.I have also deleted the unwanted space between the author name and
\corref
.Remember that you need to compile twice to see the e-mail addresses.
Image of footer displaying the e-mail addresses (inspired by Gonzalo Medina's previous answer):