63

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
  • 4
    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. Feb 22, 2013 at 16:43
  • 1
    Here is the link to the pdf. tug.ctan.org/info/symbols/comprehensive/symbols-a4.pdf
    – quettabit
    Nov 5, 2018 at 3:53
  • 1
    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... Nov 5, 2018 at 9:58

7 Answers 7

82

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

2
  • for some reason this icon does not work when inserted in an \href
    – federico
    Mar 27, 2023 at 14:17
  • Strange, I just write: See Wikipedia \href{www.wikipedia.org}{\ExternalLink} for more information. And it works, with hyperref package loaded of course.
    – poch
    Mar 28, 2023 at 6:37
33

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

3
  • 1
    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, 2019 at 20:16
  • 1
    I have made a problem out of this answer at tex.stackexchange.com/q/539991/67761 The icons are double in the List of Figures.
    – O0123
    Apr 22, 2020 at 9:44
  • @PauloNey for xelatex \setfontfamily{\FA}{[FontAwesome.otf] fixed it for me
    – innisfree
    Feb 8, 2022 at 15:22
20

One can simply use the ExternalLink icon in the fontawesome package

\documentclass{article}
\usepackage{hyperref}
\RequirePackage{fontawesome}
\begin{document}
\href{https://stackexchange.com/}{Link to Home page \faExternalLink}
\end{document}

output:

faExternalLink_example

4

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

3

Maybe the following is useful.

Code

Either

\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}

will do the job.

Output (for the first MWE)

enter image description here

3

If somehow \faExternalLink is not working like in my case, use below syntax

\faIcon{external-link-alt}
1
  • 3
    Welcome to the TeX.SE. Please, can you add a minimal working example i.e. with a complete code with an output? Thank you very much.
    – Sebastiano
    Apr 6, 2021 at 21:22
2

All,

as you have been an inspiration in digging through tikz, I wanted to share my broken-chain design which in my opinion looks beautiful.

The inspiration behind the design can be found here: https://drive.google.com/file/d/1Bjpbn2b7SdziedfCWoDUPJ-w_AL5lVyq/view?usp=sharing

You can call the icon by the command \link. You can vary the thickness of the chain by setting \width accordingly:

\usepackage{tikz}
\usepackage{xfp}
\newcommand\fei{\fpeval{(sqrt(5)-1)/2}}
%define width - recommended values [0.4-0.8] or \fei
\newcommand{\width}{\fei}

\newcommand\feiplusone{\fpeval{\fei+1}}
\newcommand\twofei{\fpeval{2*\fei}}
\newcommand\twofeiplusone{{\fpeval{2*\fei+1}}}
\newcommand{\widthplusone}{\fpeval{\width+1}}
\newcommand{\offset}{\fpeval{4*\fei+1+\width/2}}
\newcommand{\offsetangle}{\fpeval{\offset/2*sqrt(2)}}
\newcommand{\distACx}{\fpeval{\fei+1+\width/2}}
\newcommand{\radius}{\fpeval{sqrt(\distACx^2 + 1)}}
\newcommand{\centerpoint}{\fpeval{2*\fei+1+\width/2}}
\newcommand{\pointBx}{\fpeval{\centerpoint - sqrt(\radius^2 - (1+\width)^2) }}
\newcommand{\distBCx}{\fpeval{\centerpoint - \pointBx}}
\newcommand{\angleOCB}{\fpeval{atand((1+\width) / \distBCx )}}
\newcommand{\angleOCA}{\fpeval{atand(1/\distACx)}}
\newcommand{\angleACB}{\fpeval{\angleOCB - \angleOCA}}
\newcommand{\angleI}{\fpeval{\angleOCA - 180}}
\newcommand{\angleII}{\fpeval{\angleACB + \angleI}}

\newcommand{\ring}{
(\fei,-1) -- (\fei,-1) arc [radius= \radius , start angle=\angleI, end angle=\angleII] -- (0,-\widthplusone) -- (0,-\widthplusone) arc [radius=\widthplusone, start angle=270, end angle= 90] -- (\twofei,\widthplusone) -- (\twofei,\widthplusone) arc [radius=\widthplusone, start angle=90, end angle= 0] -- (\twofeiplusone,0) -- (\twofeiplusone,0) arc [radius=1, start angle=0, end angle= 90] -- (0,1) -- (0,1) arc [radius=1, start angle=90, end angle=270] -- (\fei,-1);
}

\newcommand{\link}{
\tikz[x=0.26ex, y=0.26ex, line width = 0.1]{ 
\path[draw, fill=black, cm={cos(-45) ,-sin(-45) ,sin(-45) ,cos(-45) ,(0,0)}] \ring
\path[draw, fill=black, cm={cos(135) ,-sin(135) ,sin(135) ,cos(135) ,(\offsetangle , \offsetangle)}] \ring
}
}
4
  • I cannot compile your example, you should add some \documentclass to make it possible, would love to try it.
    – poch
    Dec 25, 2022 at 6:41
  • 1
    please check overleaf.com/read/nydydbfvfxcy for the compiled version
    – Dimitris
    Jan 11, 2023 at 16:50
  • Done, nice work, you should copy the code here and add the final symbol.
    – poch
    Jan 12, 2023 at 7:47
  • The command \link works when used as a normal text, but fails to compile when inside and \href{google.com/abc}{\link}. With the error message being Package xcolor Error: Undefined color model `'. Mar 27 at 5:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .