[Tex/LaTex] Extra “appendix” when referencing using cleveref in elsarticle

appendicescleverefcross-referencingelsarticle

How do I get rid of the extra "appendix" appearing when I cross-reference an appendix section? Example output is "…see appendix Appendix A". MWE as follows:

\documentclass[preprint,3p]{elsarticle}

\usepackage{cleveref}

\begin{document}

\begin{frontmatter}

\title{Title}

\author{Author}
\ead{email@uni.edu}

\address{Address Here}

\begin{abstract}
Abstract abstract abstract
\end{abstract}

\end{frontmatter}

\section{Section1}
We would like to reference \cref{sec:app}. And the same for \cref{sec:app2}.

\appendix
\section{Section One} \label{sec:app}
Something here

\section{Section Two} \label{sec:app2}

\end{document}

Best Answer

If you want to suppress the cross-reference name for a particular type, it's simpler to just use

\crefname{appendix}{}{}

Then all the formats get defined for you automatically, instead of having to redefine \crefformat, \crefmultiformat, \crefrangeformat, and \labelcrefformat separately. (These days, cleveref is clever enough to omit the usual non-breaking space after the cross-reference name if you define an empty name.)

However, this solution (and ach's too) will break cleveref's multi-reference features somewhat. E.g. \cref{apdx1,apdx2,apdx3,apdx5,apdx7} will produce "Appendix 1 to Appendix 3 and Appendix 4 and Appendix 5", instead of "Appendices 1 to 3, 4 and 5".

Luckily, elsarticle defines an \appendixname macro to hold the string used in appendix labels, no doubt to allow it to be customised easily. So the best solution is simply to get rid of elsarticle's \appendixname entirely, and let cleveref do its job as usual, by adding this to your preamble:

\def\appendixname{}