[Tex/LaTex] How to get email to show in color when typed in text

colorhyperref

In LaTeX's article documentclass, how do I (using hyperref, if I understood right) get email links to show in color (say, red) when I type them in the middle of a paragraph?

Best Answer

Depending on your preference, you could do any one of the following:

  1. If you just want to typeset it in colour, without any linking capabilities, you could use

    \usepackage{xcolor}% http://ctan.org/pkg/xcolor
    ...
    My email address is {\color{red} who@cares.com}.
    

    Regular email in red

    Note the scoping of the \color{...} by putting it within { }, otherwise all the text following the command will be typeset in red. Compiling this may cause some unwanted linking of @cares.com, while leaving who unlinked.

  2. The hyperref package does allow linking through a number of commands. You're probably interested in using the \url{...} command, since it takes care of the tricky @ that has to be escaped in order to be typeset. It will also take care of breaking the email address (or url) across lines, if needed.

    \usepackage[%
      colorlinks=true,%
      urlcolor=red%
    ]{hyperref}% http://ctan.org/pkg/hyperref
    ...
    My email address is \url{who@cares.com}.
    

    Email address typeset using hyperref's url command

    This is also not entire accurate if you want to hyperlink to an email (via a mailto protocol).

  3. Using hyperref's \href{<url>}{<text>} provides the correct action:

    \usepackage[%
      colorlinks=true,%
      urlcolor=red%
    ]{hyperref}% http://ctan.org/pkg/hyperref
    ...
    My email address is \href{mailto:who@cares.com}{who@cares.com}.
    

    Email address using hyperref and mailto: protocol

    You can also typeset the email address in a different shape using, say, \texttt{who@cares.com}. Then it will be typeset similarly to that of option 2.