I am writing my thesis,
and my university provides a neat template that I am currently using.
Among the customised options the template has,
there is also a specific color that is used for titles, caption and so on.
At some point during the drafting I thought it would be nice
to be able to also see the citations in said color instead of a dull black,
so I started messing around with the hyperref
package:
\definecolor{bluepoli}{cmyk}{0.4,0.1,0,0.4} % University colour definition for context
\usepackage[colorlinks=true, linkcolor=black, anchorcolor=black, citecolor=bluepoli,%
filecolor=black, menucolor=black, runcolor=black, urlcolor=black]{hyperref}
The result though did not satisfy me, it actually looked worse,
because with this only the numbers inside the square brackets are coloured
(I am using biber
with a numeric-comp
style).
I took a look at the biblatex
package then to see
whether it offered any colouring options, but I remained dissatisfied.
I could just drop this whim,
but I couldn't wrap my head around the fact even books and papers
that use coloured links have the same, to my eyes, problem.
I thought about changing the text colour before and after invoking \cite{}
using \renewcommand{}{}
,
but I am not very experienced with the mechanisms underneath LaTeX.
After a quick search I found this answer:
renewcommand cite with one or two arguments,
and now my code looks like this:
\newcommand{\blup}[1]{\textcolor{bluepoli}{#1}} % Quick colour-setting command
\makeatletter
\let\@citexOld\@citex
\def\@citex[#1]#2{\blup{\@citexOld[#1]{#2}}}
\makeatother
\let\citeOld\cite % renew cite
\renewcommand{\cite}[1]{{\blup{\citeOld{#1}}}}
\let\citetOld\citet % renew cite
\renewcommand{\citet}[1]{{\blup{\citetOld{#1}}}}
Which works, but it feels clumsy to do so for every citing command I might need.
I also did not realise that
what I defined changes also the colour of explicit authors citations.
Is there a less clunky way to have only square brackets
and citations coloured? Is this actually heresy from a typographic standpoint?
Notes: yes I am aware that \citet{}
is a command from natbib
,
which only uses bibtex
.
Originally the template used this package, but after increasing frustrations
I switched to biber
Edit(1): I provide here a minimal reproducible example
of the source code.
\documentclass[12pt, twoside]{book}
\usepackage{color}
\usepackage[autostyle,italian=guillemets]{csquotes}
\usepackage[natbib=true,style=numeric-comp,sorting=none,backend=biber]{biblatex}
\usepackage[colorlinks=true,citecolor=bluepoli]{hyperref}
\begin{filecontents}{test.bib}
@article{knuth74,
author = {Knuth, Donald E.},
title = {Computer Programming As an Art},
journal = {Commun. ACM},
year = {1974},
pages = {667--673},
}
@book{peterson93,
author = {Peter Peterson},
title = {The title of the work},
publisher = {The name of the publisher},
year = {1993},
}
\end{filecontents}
\addbibresource{test.bib}
\definecolor{bluepoli}{cmyk}{0.4,0.1,0,0.4} % Define colour of citations and
\newcommand{\blup}[1]{\textcolor{bluepoli}{#1}} % its shortcut
\makeatletter % Redefine the macro of citex
\let\@citexOld\@citex
\def\@citex[#1]#2{\blup{\@citexOld[#1]{#2}}}
\makeatother
\let\citeOld\cite % Renew cite
\renewcommand{\cite}[1]{{\blup{\citeOld{#1}}}}
\let\citetOld\citet % Renew citet
\renewcommand{\citet}[1]{{\blup{\citetOld{#1}}}}
\begin{document}
\section*{Section}
This is a test~\cite{knuth74}.\\
\citet{peterson93} also reports a test.
\printbibliography
\end{document}
Edit(2): Thanks to @Accácio
for giving insight into the documentation
to refer to for the solution.
I decided to tidy up a bit this question.
The package extension biblatex-ext
has a function
that is specifically designed to change the style
of the delimiters (in this case, their color).
It is necessary to change the style of citation in the
options of the biblatex
first:
\usepackage[style=ext-numeric-comp,sorting=none,backend=biber]{biblatex}
% the style is changed to 'ext-numeric-comp'
\DeclareOuterCiteDelims{cite} % for the cite command
{\textcolor{bluepoli}{\bibopenbracket}} % left bracket
{\textcolor{bluepoli}{\bibclosebracket}} % right bracket
At the moment I did not find a way
to change the brackets of ALL cite commands,
partly because the result I seek concerns in some cases
the outer delimiter, in others the inner delimiter,
like the author citation
\DeclareInnerCiteDelims{textcite} % for the textcite command
{\textcolor{bluepoli}{\bibopenbracket}} % left INNER bracket
{\textcolor{bluepoli}{\bibclosebracket}} % right INNER bracket
Which in the previous code produces the correct result.
Instead, the modification of the external delimiters concerns
the wrapping of the entire citation, author included.
Best Answer
We can use a solution similar to https://stackoverflow.com/a/69727169/9781176 by using biblatex-ext and the
\DeclareOuterCiteDelims
function:resulting in
N.B: The citation style is changed to ext-numeric-comp