6

I'm using the elsearticle class. At present the links (citations, equation references, etc) are put in coloured boxes and I'd rather have the links coloured without boxes. So I tried putting

\usepackage{hyperref}
\usepackage[hyperref]{xcolor}
\hypersetup{
  colorlinks   = true, %Colours links instead of ugly boxes
  urlcolor     = red, %Colour for external hyperlinks
  linkcolor    = red, %Colour of internal links
  citecolor   = red %Colour of citations
}

But this doesn't work, it turns the boxes off but turns the colour of all the links to blue. How can I make it work?

7

The class does

\AtBeginDocument{\@ifpackageloaded{hyperref}
  {\def\@linkcolor{blue}
   \def\@anchorcolor{blue}
   \def\@citecolor{blue}
   \def\@filecolor{blue}
   \def\@urlcolor{blue}
   \def\@menucolor{blue}
   \def\@pagecolor{blue}
\begingroup
  \@makeother\`%
  \@makeother\=%
  \edef\x{%
    \edef\noexpand\x{%
      \endgroup
      \noexpand\toks@{%
        \catcode 96=\noexpand\the\catcode`\noexpand\`\relax
        \catcode 61=\noexpand\the\catcode`\noexpand\=\relax
      }%
    }%
    \noexpand\x
  }%
\x
\@makeother\`
\@makeother\=
}{}}

so you need to override this:

\documentclass{elsarticle}
\usepackage{hyperref}
\usepackage[hyperref]{xcolor}

\makeatletter
\hypersetup{colorlinks=true}
\AtBeginDocument{\@ifpackageloaded{hyperref}
  {\def\@linkcolor{red}
   \def\@anchorcolor{red}
   \def\@citecolor{red}
   \def\@filecolor{red}
   \def\@urlcolor{red}
   \def\@menucolor{red}
   \def\@pagecolor{red}
\begingroup
  \@makeother\`%
  \@makeother\=%
  \edef\x{%
    \edef\noexpand\x{%
      \endgroup
      \noexpand\toks@{%
        \catcode 96=\noexpand\the\catcode`\noexpand\`\relax
        \catcode 61=\noexpand\the\catcode`\noexpand\=\relax
      }%
    }%
    \noexpand\x
  }%
\x
\@makeother\`
\@makeother\=
}{}}
\makeatother

\begin{document}

\tableofcontents

\section{Test section}
\href{www.tex.stackexchange.com}{TeX.sx} \cite{test}

\begin{thebibliography}{9}
\bibitem{test} Author, Title, 2015
\end{thebibliography}

\end{document}

Or shorter, doing colorlinks=true in the preamble and the change for colors

\hypersetup{
  linkcolor=red,
  urlcolor=red,
  citecolor=red
}

in the body of the document:

\documentclass{elsarticle}
\usepackage{hyperref}
\usepackage[hyperref]{xcolor}

\hypersetup{
  colorlinks=true,
}

\begin{document}
\hypersetup{
  linkcolor=red,
  urlcolor=red,
  citecolor=red
}
\tableofcontents

\section{Test section}
\href{www.tex.stackexchange.com}{TeX.sx} \cite{test}

\begin{thebibliography}{9}
\bibitem{test} Author, Title, 2015
\end{thebibliography}

\end{document}

The result, showing red colorized links:

enter image description here

  • Thanks. Any idea why they designed it like that? – C_Al Aug 27 '15 at 21:31
  • @C_Al Most probably they wanted to enforce the blue color as an editorial decision. – Gonzalo Medina Aug 27 '15 at 23:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.