1

I am using Overleaf to write a report, with the biblatex package for citation management.

I would like to have superscripted citations inside of square brackets. The entire citation (both text and brackets) should be colorized, as shown in the picture.

Example of desired citation format.

Based on code from elsewhere, I have obtained superscipted citations in brackets, but I am only able to colorize the text, not the brackets. See image below.

enter image description here

A MWE is shown below:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[svgnames]{xcolor}
\usepackage{hyperref}
\hypersetup
{
colorlinks=true,
citecolor={blue},
citebordercolor={blue}
}
\usepackage[
backend=biber,
style=nature]{biblatex}

%This part is to colorize the brackets%
\DeclareCiteCommand{\cite}[\color{blue}\mkbibbrackets]
  {\usebibmacro{cite:init}%
   \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:comp}}
  {}
  {\usebibmacro{cite:dump}%
   \usebibmacro{postnote}}

%This part is to put brackets around the supercitation%   
\DeclareCiteCommand{\supercite}[\mkbibsuperscript]
  {\usebibmacro{cite:init}%
   \let\multicitedelim=\supercitedelim
   \iffieldundef{prenote}
     {}
     {\BibliographyWarning{Ignoring prenote argument}}%
   \iffieldundef{postnote}
     {}
     {\BibliographyWarning{Ignoring postnote argument}}%
  \bibopenbracket}%
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:comp}}
  {}
  {\usebibmacro{cite:dump}\bibclosebracket}

\addbibresource{sample.bib}


\begin{document}

\section{First section}

Normal cite has colorized text and brackets.\cite{einstein} Supercite only has colorized text.\supercite{dirac}

\printbibliography[
heading=bibintoc,
title={Bibliography}
]

\end{document}

I am a newcomer to LaTeX, so any suggestions are welcome.

1

The citations are coloured because they are linked. For the brackets around the citation it is not quite clear what they should link to if there are multiple citations in the bracket. It would be possible to link the brackets to the following or previous citation, but since the underlying citation style numeric-comp is quite complex, that would require a lot of code. So I'll stick to colouring the brackets without linking them.

The idea is to insert a \color{blue} in some way via the wrapper around the citation (the command in the square brackets in \DeclareCiteCommand).

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[svgnames]{xcolor}

\usepackage[
backend=biber,
style=nature]{biblatex}

\usepackage{hyperref}

\hypersetup{
  colorlinks=true,
  citecolor={blue},
  citebordercolor={blue},
}

%This part is to colorize the brackets%
\DeclareCiteCommand{\cite}[\color{blue}\mkbibbrackets]
  {\usebibmacro{cite:init}%
   \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:comp}}
  {}
  {\usebibmacro{cite:dump}%
   \usebibmacro{postnote}}

\newrobustcmd{\mkbibcoloursuperscript}[2]{%
  \unspace\allowhyphens\textsuperscript{%
    \begingroup
    \protected\long\def\mkbibsuperscript##1{%
      \blx@warning{Nested superscript}%
      \mkbibbrackets{##1}}%
    \color{#1}%
    #2\endgroup}}

%This part is to put brackets around the supercitation%   
\DeclareCiteCommand{\supercite}[\mkbibcoloursuperscript{blue}]
  {\usebibmacro{cite:init}%
   \let\multicitedelim=\supercitedelim
   \iffieldundef{prenote}
     {}
     {\BibliographyWarning{Ignoring prenote argument}}%
   \iffieldundef{postnote}
     {}
     {\BibliographyWarning{Ignoring postnote argument}}%
  \bibopenbracket}%
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:comp}}
  {}
  {\usebibmacro{cite:dump}\bibclosebracket}

\addbibresource{biblatex-examples.bib}


\begin{document}

Normal cite has colorized text and brackets.\cite{sigfridsson}

Supercite only has colorized text.\supercite{nussbaum}

\printbibliography[
heading=bibintoc,
title={Bibliography}
]
\end{document}

Fully coloured citations.

| improve this answer | |

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.