# Create a modified cite command that colors the number inside the square brackets

I was searching and couldn't find an answer. I'm using the cite{} command and its working nicely ofc. I would like to make a small modification. When my reference appears in the text, the reference number inside the square brackets should have a specified color. How can I achieve this (please see attached picture below)? Only the inner number should be colored and the outer brackets should stay black. Any help is appreciated, thank you very much.

EDIT: So far I'm using the following method to create my document.

% main tex-file
\documentclass[a4paper,11pt]{memoir}
\usepackage[style=numeric, backend=biber, backref, sorting=none]{biblatex}

\begin{document}
This is a test \cite{ref1}.

\printbibliography
\end{document}

% bib/bibfile.bib
@CONFERENCE{ref1,
author = {Hans Neumann},
title = {title},
booktitle = {book title},
year = {1998}
}

• Posibly duplicate of tex.stackexchange.com/questions/224568/… – user170109 May 16 '19 at 2:10
• I'm primarily interested in colouring the reference numbers in my text and not necessarily in my list. – H123321 May 16 '19 at 2:16
• Should the citation callouts also be made into hyperlinks to the associated bib entries? – Mico May 16 '19 at 2:35
• Can you please tell us which bibliography/citation package you are using? A solution for biblatex will be wildly different from a solution for natbib. The specific style you use also plays a role, so it would be great if you could show us a short example document (a so-called MWE: tex.meta.stackexchange.com/q/228) that reproduces the status quo. You may also want to clarify if you use hyperref. By default citations are usually linked with hyperref and if you give the correct options citations will automatically be coloured (though that colouring might not survive printing) – moewe May 16 '19 at 4:20
• It would be easier to understand what you wanted if you added minimal working example to show what you are using bibtex or biblatex etc. – Andrew May 16 '19 at 11:44

One way is to use hyperref, which has the added benefit of turning your citations etc into hyperlinks in the PDF file. By adding the lines

\usepackage{hyperref}


to the end of your preamble (hyperref likes being loaded last), your MWE produces:

although you pmight want a different shade of green:) Here is the full code:

% main tex-file
\documentclass[a4paper,11pt]{memoir}
\usepackage[style=numeric, backend=biber, backref, sorting=none]{biblatex}

% to generate the bibfile
\usepackage{filecontents}
\begin{filecontents}{bibfile.bib}
@CONFERENCE{ref1,
author = {Hans Neumann},
title = {title},
booktitle = {book title},
year = {1998}
}
\end{filecontents}

\usepackage{hyperref}

\begin{document}
This is a test \cite{ref1}.

\printbibliography
\end{document}


A big thank you to Andrew who posted an answer that solves my problem.

However, I also managed to get another solution as well (although Andrew's answer seems more elegant). This question helped me: Link

\documentclass[a4paper,11pt]{memoir}
\usepackage[style=numeric, backend=biber, backref, sorting=none, labelnumber]{biblatex}

% using labelnumber
\DeclareCiteCommand{\citenum}
{}
{\printfield{labelnumber}}
{}
{}

% defining a new custom command with desired color:
\newcommand\mycite[1]{[\textcolor{green}{\citenum{#1}}]}

\begin{document}
This is a test \mycite{ref1}.
% and i get the same output as Andrew! :D

\printbibliography
\end{document}


Just another possibility, if using cite.sty and not hyperref

\renewcommand\citeform[1]{\textcolor{green}{#1}}


which will set the color of the numbers, and nothing else.