# Make hyperref links only show up if they're external links?

I am trying to make a document, but I do not need hyperref to label links that are internal (since the document is only a few pages long). I would, however, like for links to show up that point outside of the document, e.g. urls and external files. I do not want equations, page number references, footnotes, etc. showing up.

I am referring specifically to the colored borders that appear around links (but don't print).

\documentclass{article}
\usepackage{hyperref}

\begin{document}
Here's some test text with a footnote\footnote{Some text, but the footnote shouldn't show up as a link.}.

\url{http://www.google.com} %this should show up as a link.

\href{http://www.google.com}{Go to Google} %this should also show up as a link.
\end{document}


I can't set hidelinks in the options and then set urlbordercolor it seems, and I have no idea how to set a border color to be transparent (or else I could try setting each border color type to transparent). I also don't know what color that blue is for the urlbordercolor by default, and I really like it, so I'd rather not change it if possible. I did find from this post that the urlbordercolor is {0 1 1} by default; I just typed it in wrong originally, so I thought I had it wrong.

I can't change the link borders to all white because it causes some clipping issues:

So I think if I wanted to change that, the links would need to be made transparent.

Thanks!

• What does "I do not want equations, page number references, footnotes, etc. showing up." refer to exactly? Does this sentence refer to the colored boxes, hyperref adds around links? – leandriis Aug 23 at 14:48
• Please also make your code compilable. Currently it results in quite a number of error messages. Probably you wanted to use \hyperlink{www.google.com}{Go to Google} instead of \hyperref{www.google.com}{Go to Google}? – leandriis Aug 23 at 14:49
• @leandriis Fixed. Typed \hyperref instead of \href. Sorry about that. I am not sure what the difference is between \href and \hyperlink? – Publius Aug 23 at 14:50
• no \hyperlink is wrong too, you probably mean \href, and you should add the protocol: www ... – Ulrike Fischer Aug 23 at 14:52
• Probably \usepackage[colorlinks,linkcolor=black,citecolor=black]{hyperref} results in the desired output? – leandriis Aug 23 at 14:55

In the hyperref bundle there is an additional package called nohyperref that defines all commands of hyperref but makes them do nothing. This package is intended to disable hyperlinks completely without causing errors if documents use any of the commands defined by hyperref (for example \hyperref or \phantomsection or any of the bookmark commands).

After loading hyperref normally, you can use some of the code from this package to selectively disable only the parts that you don't want, i.e., internal links, and leave the other commands untouched.

Edit: as noted in comments you may want to keep the anchors in the pdf to allow for external linking. This applies to links in the pdf only (for example http://mirrors.ctan.org/macros/latex/contrib/hyperref/doc/manual.pdf#subsection.3.8 that directly links to subsection 3.8 of the hyperref pdf manual), whereas 'external' references within LaTeX (such as with \input or \include or the xr-hyper package) are not affected with this code.

MWE for this approach:

\documentclass{article}
\usepackage{hyperref}
\makeatletter
% first six lines of nohyperref.sty
% keep anchors
%\let\hyper@@anchor\@gobble
%\let\hyper@anchorstart\@gobble
%\let\hyper@anchorend\@empty
\makeatother

\begin{document}
\section{A section}
\label{mysec}
Here's some test text with a footnote\footnote{Some text, but the
footnote shouldn't show up as a link.}
in Section~\ref{mysec} on page~\pageref{mysec}.

\url{http://www.google.com} %this should show up as a link.

\href{http://www.google.com}{Go to Google} %this should also show up as a link.
\end{document}


Result:

Note that the inserted code may disable too much or too little functionality, check carefully if you observe any unintended effects.

• You probably wish to keep anchors/named destinations/targets so within external resources, e.g., websites or other .pdf-files, you can link to specific sections of the document. – Ulrich Diez Aug 23 at 20:05
• @UlrichDiez Does this answer prevent linking other documents into this one? I am still able to reference, for example, Equation 4 in my working document, although the link to Equation 4 is no longer active. – Publius Aug 24 at 13:46
• @Publius LaTeX's cross-referencing-mechanism which serves the purpose of obtaining textual phrases denoting sectioning-numbers or equation-numbers and the like is not affected. That mechanism is in effect only while the LaTeX-compiler is running and creating the .pdf-file. The hyperref-package adds things which are in effect while the .pdf-file is displayed by a pdf-viewing-program: It turns equation-numbers and section-headings into named destinations/targets/anchors.And it turns cross-references created via \ref/\pageref etc into hyperlinks to the named destinations/targets/anchors. – Ulrich Diez Aug 24 at 14:08
• @Publius So with this answer within the pdf both hyperlinks (which is desired) and named destinations/targets/anchors (which could be also linked from other documents/websites) don't come into being. In the answer six commands are modified. If the three ...@anchor...-commands are not modified, links will not be created but named destinations/targets/anchors for linking will be created. In any case the names of these named destinations/targets/anchors will not be these of the corresponding referencing-labels. Because hyperref uses its own algorithms for assigning names to ... – Ulrich Diez Aug 24 at 14:25
• @UlrichDiez thanks for the comment, I have edited my answer to address the issue. – Marijn Aug 24 at 14:44

The following crude hack seems to work with

• pdflatex — This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2019/dev/Debian) (preloaded format=pdflatex)...LaTeX2e <2018-12-01>
• xelatex — This is XeTeX, Version 3.14159265-2.6-0.99999 (TeX Live 2019/dev/Debian) (preloaded format=xelatex)...LaTeX2e <2018-12-01>
• lualatex — This is LuaTeX, Version 1.07.0 (TeX Live 2019/dev/Debian)...LaTeX2e <2018-12-01>

But I give no warranties as

• I did not really delve into studying the hyperref-driver-files.

• evaluating things like pdfborder and pdfborderstyle is is not just a matter of pdf-version and pdf-specification but is also a matter of how the program used for viewing/displaying the pdf-file in question works:

Table 164 — Entries common to all annotation dictionaries of the Portable Document Format (PDF) 1.7 specification says that border-specification (the pdfborder=...-thingie with hyperref) is of pattern

[⟨horizontal corner radius⟩ ⟨vertical corner radius⟩ ⟨border width⟩[⟨length of dashes⟩ ⟨length of gap between dashes⟩]]
; specifications for dashes being optional; everything specified in "default user space units"; section 8.3.2.3 User Space of the Portable Document Format (PDF) 1.7 specification says that by default a user space unit is (1/72) inch, i.e., is 1bp (=1 big point) according to what is said in Chapter 10: Dimensions of the TeXbook. (1bp = 1 big point = (1/72) inch; 1pt = 1 printer's point = (1/72.27) inch.)

If I specify pdfborder={5 5 1 [3 2]}, then this means dashed lines; dashes of length 3bp; gap between dashes of length 2bp; thickness of dashes 1bp; round corners of corner radius 5bp both vertical and horizontal.

When displaying the resulting pdf-file with Chromium Version 76.0.3809.100 (Developer-Build), then no borders at all are shown.

When displaying the resulting pdf-file with Firefox Quantum 69.0.2, then solid lines with round corners are shown.

When displaying the resulting pdf-file with Okular 1.3.2 and Adobe Acrobat Reader DC Version 2020.012.20043, then dashed lines, no round corners but squared corners are shown.

Be aware that the footnote is still a link, but not surrounded by colored borders.

\documentclass{article}
\usepackage{iftex}
%allbordercolors={},
%citebordercolor={0 1 0},
%filebordercolor={0 .5 .5},
%urlbordercolor={0 1 1},
%runbordercolor={0 .7 .7},
%pdfborder={0 0 1},
%pdfborderstyle={/S/S/W 1}
]{hyperref}
\makeatletter
\Hy@AtBeginDocument{%
\ifxetex
\fi
\ifluatex\ifpdf
\fi\fi
\ifPDFTeX\ifpdf
\fi\fi
}%
\makeatother

\begin{document}

Here's some test text with a footnote\footnote{Some text, but the footnote shouldn't show up as a link.}.

\url{http://www.google.com} %this should show up as a link.

\href{http://www.google.com}{Go to Google} %this should also show up as a link.

\end{document}


• This is a really involved answer- apologies, but I will have to read it in a little while. – Publius Aug 24 at 13:47