# Both text and border colors for ref

My first question on this StackExchange and I hope it seems reasonable and hasn't been asked before here (I tried looking).

I'm a beginner trying to write my thesis in LaTeX. I like the idea of having bibliographic references as coloured text but would like to have borders for internal references. But when I try the following code with hyperref

\hypersetup{pdfpagemode={UseOutlines},
bookmarksopen=true,
bookmarksopenlevel=0,
hypertexnames=false,
citecolor=blue,
urlcolor=red,
pdfstartview={FitV},
unicode,
}


I believe colorlinks=true is blocking the border colours from coming in. Can I do this?

By default, hyperref has

• three global and exclusive types of link styles: pdfborder (by default), colorlinks, and pdfborderstyle, and
• six link types: cite (bibliographic references), file, link (internal references), menu, run, and url.

Here is a crude implementation that allows user to set one of the first two link styles per link type.

Update:

• Patch lower macro \Hy@VerboseLinkStart instead of \hyper@link@.

(In places like biblatex and \contentsline, \hyper@linkstart and \hyper@link are used directly. These two macros has dependencies in hxetex.def, the hyperref driver for xetex engine, but not in hpdftex.def and hluatex.def. Therefore \Hy@VerboseLinkStart, the common internal of \hyper@link[|start] in each of drivers, is patched.)

In the following example, I use

\hypersetup{
}


to set link style color for all cites, and border for all links.

\documentclass{article}
\usepackage{xcolor}
\usepackage{hyperref}
\usepackage{xpatch}

\makeatletter
% change link style (color or border) per link type
{}{\fail}

% set link type to color
\let\@pdfborder\@pdfborder@plain
}

% set link type to border
\def\hyper@use@pdfborder{%
\let\@pdfborder\@pdfborder@normal
\else
\fi
}

\let\@pdfborder@normal\@pdfborder
\def\@pdfborder@plain{0 0 0}

% new \hypersetup options per link type
\@for\Hy@temp:=\Hy@ColorList\do{%
\edef\Hy@temp{%
\noexpand\define@key{Hyp}{\Hy@temp type}{%
\noexpand\expandafter\noexpand\let
\noexpand\csname hyper@use@##1\noexpand\endcsname%
}%
}%
\Hy@temp
}
\makeatother

% user setting
\hypersetup{
% colorlinks, % option "colorlinks" now has no effects
}

\begin{document}
Section~\ref{key}, article \cite{citekey}
\section{title}\label{key}

\begin{thebibliography}{00}
\bibitem{citekey}
\end{thebibliography}
\end{document}


• I tried to implement this but it seems to just remove all colours (text and border) from cites and link references. My Overleaf project can be viewed at overleaf.com/read/jwthpgnjwtbg (I put the xpatch part of your code in main.tex under "References with xpatch" and the user setting bit is in MastersDoctoralThesis.cls). The compiler also has a problem with your {}{\fail} command? Your solution looks kind of advanced but it's definitely useful both to me and I suppose anyone else who might want to do this Aug 13 '20 at 14:30
• @MobeusZoom In your linked overleaf project, the template loads hyperref package by \AtEndPreamble, which is very later than the patch to \hyper@link@, hence the patch code raises an error. You can manually load hyperref before patching to avoid that error. Also, to support biblatex, I updated answer to patch \hyper@linkstart instead of \hyper@link@. Aug 14 '20 at 6:05
• Another change: to make the patch work for all popular engines, \Hy@VerboseLinkStart is patched. Aug 14 '20 at 10:23
• Thank you! I've updated the Overleaf project accordingly. Now it compiles without error. However, while citation color is correctly controlled by citecolor=blue (see MastersDoctoralThesis.cls), my attempts to set linkbordercolor=red seem to be ignored (see Figure 1.1, Table 1.1 or Equation 1.1 in the compiled PDF) Aug 14 '20 at 14:38
• @MobeusZoom The link borders do exists, but the pdf viewer of overleaf refuses to show them. You can download the pdf from overleaf and check those borders. Aug 15 '20 at 1:40