6

I want to color my citations using biblatex alphabetic citation style. However, I do not to only color the "key" (as it is the case in this paper) but the whole block including :

  • opening bracket (or brace)
  • (possible) pre-note : for example 'cf.'
  • the "key" (depending on the citation style - 'Abc90' in my case)
  • (possible) post-note : for example 'p. 1337 sqq.'
  • closing bracket (or brace)

I succeed in colouring the key + the brackets around the citation (+ the colon in case of multiple keys cited).

However, I don't know how to color the postnote ('p. 43' in the MWE) and the key in the bibliography ('Joh73')

My MWE is :

\documentclass{article}

%== inclue bib file ==%
\usepackage{filecontents}

    \begin{filecontents}{referencia.bib}
    @misc{john-73,
        author = {John, S.},
        year = {1973},
        title = {The best book ever},
    }
    \end{filecontents}

%== use and define color ==%
\usepackage[dvipsnames]{xcolor} 
    \definecolor{bleu_cite}{RGB}{12,127,172}

%== use color in citations ==%
\usepackage[
            colorlinks=true,        
            allcolors = black,  
            citecolor=bleu_cite,        
        ]{hyperref} 

%== biblatex options ==%
\PassOptionsToPackage{
            natbib=true,
            backend=biber,      
            style=alphabetic,       
        }{biblatex}         
        \usepackage{biblatex}
    \addbibresource{referencia.bib}

    \makeatletter 
        \renewcommand*{\bibleftbracket}{\blx@postpunct\textcolor{bleu_cite}{[}}
        \renewcommand*{\bibrightbracket}{\blx@postpunct\textcolor{bleu_cite}{]}\midsentence} 
        \renewcommand*{\multicitedelim}{\textcolor{bleu_cite}{\addsemicolon\space}}
        \renewcommand*{\citesetup}{\textcolor{bleu_cite}}
    \makeatother


\begin{document}

``Some quotation'' \citep[43]{john-73}.
\printbibliography

 \end{document}
lockstep
  • 250,273
ebosi
  • 11,692
  • Do you want to colour the citations or do you also want the link to extend to all the parts you listed above – moewe Jul 10 '15 at 14:29
  • 2
    In case you want colour only, you need just one line: \AtEveryCite{\color{bleu_cite}}. – moewe Jul 10 '15 at 14:35

1 Answers1

8

To colour only specific cite commands it seems easiest to define a new coloured wrapper as replacement for \mkbibbrackets

\newcommand{\mkbibbracketscol}[1]{\textcolor{bleu_cite}{\mkbibbrackets{#1}}}

Then, all of the commands using \mkbibbrackets we want coloured need to use the new command, while those using nothing just get \textcolor{bleu_cite} in their wrapper. The definitions below are copied from the relevant .cbx file, in our case alphabetic.cbx, and them modified to use \mkbibbracketscol or \textcolor{bleu_cite} as appropriate.

\DeclareCiteCommand{\cite}[\mkbibbracketscol]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\parencite}[\mkbibbracketscol]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{postnote}}


\DeclareCiteCommand{\cbx@textcite}[\textcolor{bleu_cite}]
  {\usebibmacro{textcite:init}}
  {\usebibmacro{citeindex}%
   \usebibmacro{textcite}}
  {}
  {\usebibmacro{textcite:postnote}}

MWE

\documentclass{article}
\usepackage[dvipsnames]{xcolor} 
  \definecolor{bleu_cite}{RGB}{12,127,172}
\usepackage[
            colorlinks=true,        
            allcolors = black,  
            citecolor=bleu_cite,        
        ]{hyperref} 
\PassOptionsToPackage{
            natbib=true,
            backend=biber,      
            style=alphabetic,       
        }{biblatex}         
        \usepackage{biblatex}
    \addbibresource{biblatex-examples.bib}

%\AtEveryCite{\color{bleu_cite}}

\newcommand{\mkbibbracketscol}[1]{\textcolor{bleu_cite}{\mkbibbrackets{#1}}}

\DeclareCiteCommand{\cite}[\mkbibbracketscol]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\parencite}[\mkbibbracketscol]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{postnote}}


\DeclareCiteCommand{\cbx@textcite}[\textcolor{bleu_cite}]
  {\usebibmacro{textcite:init}}
  {\usebibmacro{citeindex}%
   \usebibmacro{textcite}}
  {}
  {\usebibmacro{textcite:postnote}}

\begin{document}
Lorem \citep[43]{geer} ipsum \citeauthor{worman} dolor \citet[43]{geer} sit \citetitle{worman} amet.
\printbibliography
\end{document}

enter image description here


If it is mere colouring for all citation commands you are after and not hyper-linking, you should be happy with

\AtEveryCite{\color{bleu_cite}}

which will turn the entire citation in a nice bleu hue; the link, however, will still be confined to the label.

enter image description here

moewe
  • 175,683
  • works well... maybe to well, because if I citeauthor{geer} or \citetitle{geer}, they also appear in blue.

    What I would like to do, is to make the link (here Gee85) and the rest of the tag (here "[" as prefix and ", p.43]" as suffix) appear in blue.

    To make only the link appear in blue, as you mentionned \usepackage[ colorlinks=true, allcolors = black, citecolor=bleu_cite, ]{hyperref} works well. But \AtEveryCite{\color{bleu_cite}} works "too much" for what I want to do...

    – ebosi Aug 14 '15 at 16:31
  • @ebo Well, that does complicate things quite a bit, see the updated answer, please. – moewe Aug 15 '15 at 05:31
  • didn't found alphabetic.cbx on my computer. I found an online version of this file, but where should I copy it ? – ebosi Aug 31 '15 at 14:55
  • 1
    @ebo If you have a working biblatex installation, you should be able to locate the file via kpsewhich alphabetic.cbx (on my system that is in C:\Program Files (x86)\MiKTeX 2.9\tex\latex\biblatex\cbx). For the answer it is not importand that you find alphebtic.cbx you do not need to change any of its contents (and you should not do it either). When I wrote that the definitions need to be copied I was just explaining where I got the base for the code from (and allowing people who might use a different style to find a way to do the same). – moewe Aug 31 '15 at 18:39
  • so what I do is just create a file in my *.tex files folder called alphabetic.cbx with only the parameters I want to change, and this file will overwrite default settings, right ? – ebosi Sep 02 '15 at 07:35
  • 1
    @ebo No, no no. You only need the code in the MWE above in your preamble (the \newcommand{\mkbibbracketscol} and the three \DeclareCiteCommands are enough), nothing more and nothing less. If you wish so, you can create an external file called, say colourcite.tex, add the modifications of the MWE to this file and call it in your preamble with \input{colourcite}. – moewe Sep 02 '15 at 07:43
  • 1
    @ebo If you were to create a file called alphabetic.cbx somewhere that takes precedence over the standard file you will overwrite the default, but the default of alphabetic.cbx would not even be loaded and then you would be missing lots of definitions. That is certainly not what you want. Did you run my example from above? – moewe Sep 02 '15 at 07:48
  • I had issues indeed, since the other definitions of alphabetic.cbx wasn't found. Your MWE works like a charm, thank you a lot. I'll continue to fiddle it, but it solves my issue ! – ebosi Sep 03 '15 at 14:44