28

I'm using the hyperref package in my document to provide hyperlinks to external documents. However, I don't want to have the links coloured or underlined, because I find this usually ugly and distracting. What I would rather like is a little symbol beside the link text to provide a small hint for the reader that there is something clickable. What I have in mind is something like the little symbol constisting of a small square and an arrow you can find e.g. in Wikipedia for external links. Is there any package or font that provides such a symbol or do I have to brew one myself?

  • 3
    Have a look at symbols_a4.pdf if you can find a suitable symbol and define your own command which prints the symbol and the hyperlink. If you don't find a symbol you need to define your own symbol, e.g. with TikZ. – Uwe Ziegenhagen Feb 22 '13 at 16:43
  • Here is the link to the pdf. tug.ctan.org/info/symbols/comprehensive/symbols-a4.pdf – yottabytt Nov 5 '18 at 3:53
  • Yeah, now there seems to be a symbol in there, namely \faExternalLink from the fontawesome package (page 189). But I guess, it wasn't in there back in 2013, when I posted the question. Anyway, posting the link made me look into it again... – Elmar Zander Nov 5 '18 at 9:58
28

I'm using TikZ to draw the symbol:

\documentclass{article}
\usepackage{tikz}

\newcommand{\ExternalLink}{%
    \tikz[x=1.2ex, y=1.2ex, baseline=-0.05ex]{% 
        \begin{scope}[x=1ex, y=1ex]
            \clip (-0.1,-0.1) 
                --++ (-0, 1.2) 
                --++ (0.6, 0) 
                --++ (0, -0.6) 
                --++ (0.6, 0) 
                --++ (0, -1);
            \path[draw, 
                line width = 0.5, 
                rounded corners=0.5] 
                (0,0) rectangle (1,1);
        \end{scope}
        \path[draw, line width = 0.5] (0.5, 0.5) 
            -- (1, 1);
        \path[draw, line width = 0.5] (0.6, 1) 
            -- (1, 1) -- (1, 0.6);
        }
    }

\begin{document}
See Wikipedia \ExternalLink for more information.
\end{document}

enter image description here

22

In addition to Svend Mortensen’s answer, too long for a comment.

For Xe(La)TeX or Lua(La)TeX see also update below.

If you already set a document with a lot of \hrefin it, you also can redefine the hrefcommand by copying the original macro to a new one with \let (works here, but not in every case!), see my example.

Note, that I used a dedicated hyperref option for hiding the links. I also show some symbols from two dingbat fonts. Fonts of this type should be in general the most useful for your need.

\documentclass{article}

\usepackage{bbding,pifont} % two dingbat fonts

\usepackage{graphicx} % "graphics" would be enough for the minimal example

\usepackage[hidelinks]{hyperref}

% Redefinition:
\let\orighref\href
\renewcommand{\href}[2]{\orighref{#1}{#2}\,\ArrowBoldUpRight} %bbding
% the same with symbol included in link:
% \renewcommand{\href}[2]{\orighref{#1}{#2\,\ArrowBoldUpRight}}

% Examples:
\newcommand{\hrefa}[1]{\orighref{http://example.com/}{#1}\,\scalebox{0.75}{\ArrowBoldUpRight}} %bbding
\newcommand{\hrefb}[1]{\orighref{http://example.com/}{#1}\,\ding{230}} %pifont
\newcommand{\hrefc}[1]{\raisebox{-0.4ex}{\HandRight}\,\orighref{http://example.com/}{#1}} %bbding
\newcommand{\hrefd}[1]{\scalebox{1.3}{\raisebox{-0.3ex}{\ding{43}}}\,\orighref{http://example.com/}{#1}} %pifont
\newcommand{\hrefe}[1]{\scalebox{0.8}{\raisebox{-0.5ex}{\HandRightUp}}\,\orighref{http://example.com/}{#1}} %bbding
\newcommand{\hreff}[1]{\ding{226}\,\orighref{http://example.com/}{#1}} %pifont
\newcommand{\hrefg}[1]{\ding{238}\,\orighref{http://example.com/}{#1}} %pifont
% the last with symbol included in link:
% \newcommand{\hrefg}[1]{\orighref{http://example.com/}{\ding{238}\,#1}} %pifont

\begin{document}

\hrefa{link A}, \hrefb{link B},

\hrefc{link C}, \hrefd{link D}, \hrefe{link E}, \hreff{link F}, \hrefg{link G}

\end{document}

LaTeX example output


Update:

Bad timing – shortly after writing of this answer a new package fontawesome was released. For Xe(La)TeX or Lua(La)TeX users this package “grants access to 249 web-related icons provided by the included Font Awesome free font” (cite from documentation abstract). One of them is the symbol for external links accessible with \faicon{external-link} or \faExternalLink:

% Compile with LuaLaTeX or XeLaTeX
\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}

LuaLaTeX/XeLaTeX output example

  • Works under LuaLaTeX but not in XeLaTeX. In XeLaTeX I get: xdvipdfmx:fatal: pdf_ref_obj(): passed invalid object. and no PDF is written. – Paulo Ney Jan 13 at 20:16
2

Maybe thw following is useful.

Code

\documentclass{article}

\usepackage{bbding}
\usepackage[pdfborder={0 0 0}]{hyperref}

\newcommand*\link[2]{%
  \href{#1}{#2}\,\raisebox{-1pt}{\footnotesize\FourStarOpen}%
}

\begin{document}

Click \link{http://www.latex-project.org/}{here} to go to the webpage.

\end{document}

or

\documentclass{article}

\usepackage{bbding}
\usepackage[pdfborder={0 0 0}]{hyperref}

\newcommand*\link[2]{%
  \href{#1}{#2}\,{\scriptsize\FourStarOpen}%
}

\begin{document}

Click \link{http://www.latex-project.org/}{here} to go to the webpage.

\end{document}

Output (for the first MWE)

enter image description here

2

Another idea:

\documentclass{standalone}
\usepackage{txfonts}
\usepackage{graphicx}
\def\xLink{$\!\vcenter{\hbox{\rotatebox{45}{$\DiamondRight$}}}\!\!$}
\begin{document}
See Wikipedia\xLink\ for details about this logo.
\end{document}

Result

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.