# How to colour just one link with hyperref package?

I'm using the hyperref package with the hidelinks option, but there is one link I would like to be coloured and I'm trying to do this with an overriding hypersetup command in an environment which only contains that particular link. Why doesn't this work?

\documentclass{minimal}

\begin{document}

\end{document}


Result:

The method works just as intended the other way round:

\documentclass{minimal}
\usepackage{hyperref}

\begin{document}

\end{document}


• please consider accepting one of the answers (most likely Ulrike's straightforward answer tex.stackexchange.com/a/636731) if it solved your problem. Mar 16 at 15:31
• @marquinho Done. Mar 17 at 16:09

colorlinks is currently a preamble only option (this changes if you use the new pdfmanagement). If you want only one link in color I suggest to use simply \color:

\documentclass{article}
\usepackage{xcolor}
\begin{document}

\end{document}

• Thank you, that makes sense of course. What if I want no different font colour, but just a coloured box around the link, as in my above example? Mar 11 at 16:28
• \hypersetup{pdfborder={1 1 1}} Mar 11 at 16:32

I believe that \hypersetup is actually intended only for the preamble, and I'm somewhat surprised that your first example (where you invoked \hypersetup in the document body) worked at all.

[EDIT: As Ulrike Fischer points out, \hypersetup does work in the document body, but not for all options; f.i., colorlinks works only in the preamble.]

Under my assumption that \hypersetup{colorlinks} is not expected to work in the document body, I propose the following workaround:

(1) Save the current text color using pkg xcolor under a custom name (saved), in order to retrieve it later. Normally, the text color will be black, but we are going for a flexible enough solution;

(2) In the preamble, set the color of all links to said default text color (allcolors=saved), effectively mimicking the option hidelinks of hyperref;

(3) In the document, set locally (within a group) the color for all links to the desired color (similarly to your own approach).

\documentclass{article}

\usepackage{xcolor}

\colorlet{saved}{.}  % saves the current text color as "saved"

\hypersetup{allcolors=saved}

\begin{document}


And this is with a default text color other than black (setting \color{blue} in the preamble):