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

linkbordercolor={1 0 0},

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

1 Answer 1


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.


  • 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


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


% change link style (color or border) per link type
  {\csname hyper@set@link@type@#1\endcsname}

% set link type to color

% set link type to border

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


% new \hypersetup options per link type
% usage: "citetype=[colorlinks|pdfborder]"
    \noexpand\define@key{Hyp}{\Hy@temp type}{%
      \noexpand\expandafter\expandafter\noexpand\csname hyper@set@link@type@\Hy@temp\endcsname
      \noexpand\csname hyper@use@##1\noexpand\endcsname%

% user setting
  % colorlinks, % option "colorlinks" now has no effects

Section~\ref{key}, article \cite{citekey}


enter image description here

  • 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, 2020 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, 2020 at 6:05
  • Another change: to make the patch work for all popular engines, \Hy@VerboseLinkStart is patched. Aug 14, 2020 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, 2020 at 14:38
  • 1
    @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, 2020 at 1:40

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.