2

When using (see aswer https://tex.stackexchange.com/a/102724/67761 from the question "Symbol for external links"):

\documentclass{article}
\usepackage{fontawesome}
\usepackage[hidelinks]{hyperref}

% Redefinition, symbol included in link:
\let\orighref\href
\renewcommand{\href}[2]{\orighref{#1}{#2\,\faExternalLink}}

\begin{document}
\href{http://example.com}{example web site}
\end{document}

To achieve a special symbol after an external URL, everything works fine. I can compile this with simple LaTeX.

An external URL in a \captionof{figure}{ABC. See \href{https://DEF}{GHI}.} also works fine and shows the symbol.

Works fine:

Works fine

The problem is when you add

\tableofcontents*
\listoffigures

Then suddenly in the List of Figures, the symbols are double!

See here the problem:

Double icons

O0123
  • 1,773
  • Don't redefine \href, that is a rather complicated command which has to sanitize its argument first. – Ulrike Fischer Apr 22 '20 at 10:14
  • Then what is a better way to avoid these problems? How to add an external link symbol i side a \href but have it as part of the link, not completely after or before it? – O0123 Apr 22 '20 at 10:50

1 Answers1

2

Don't redefine hyperref commands like this. At first they should be robust (so that you don't end with doublettes like with your redefinition), and at second hyperref tries hard to handle special symbols in the url and you are deactivating this.

You can define your own href command like this:

\documentclass{article}
\usepackage{fontawesome}
\usepackage{caption}
\usepackage[hidelinks]{hyperref}

% Redefinition, symbol included in link:
\makeatletter
\DeclareRobustCommand*{\newhref}{\hyper@normalise\newhref@}
\newcommand\newhref@[2]{\hyper@linkurl{#2\,\faExternalLink}{#1}}
\makeatother
\begin{document}
\listoffigures

\captionof{figure}{ABC. See \newhref{https://DEF}{GHI}.}

\newhref{http://example.com}{example web site}

\end{document}

enter image description here

Ulrike Fischer
  • 327,261