7

I have an idea, and to be frank I don't have any kind of Start / MWE because I think this is actually quite a difficult problem, at least for me, but it might be an interesting kind of result if anyone is interested in having a go.

I want to change the link colour for inline citations (ie \citep{...}, \citet{...} type macros) based on the frequency of use of the particular reference.

So low frequency citations (ie a citation used only say once) might be rendered black, and the most popular citation (ie like a seminal review that contributes significantly to a literature review, and is cited say X times, X > 1) it would be rendered say in red. Everything else by amount that is proportionate to its relative popularity.

So when compiling the document, the first pass needs to count the respective frequencies for each bibliography key that is in use, and subsequent compilations needs to somehow dynamically allocate a colour, based on its ratio between 1 and the frequency of the most popular reference.

Why might you do this? Well the reader might get a sense of what is an important reference and what is not as they are reading the document based on the 'hotness' of the colour.

1

1 Answer 1

5

Here is a naive approach with biblatex. The main work of counting the number of citations per citation is done by citecounter as explained in Can I count the number of times each reference is cited?.

We just need a way to obtain the maximum number of citations (maybe that is worth a feature request https://github.com/plk/biblatex/issues/791). Then we can calculate the red channel of a citation easily as $255\frac{c}{m}$ where $c$ is the value of citecounter for the current citation and $m$ is maxcitecounter. (This is integer division, but I hope that multiplying with 255 and using the RGB model can cancel out the rounding errors for most intents and purposes.)

\documentclass{article}
\usepackage{xcolor}
\usepackage{biblatex}

\addbibresource{biblatex-examples.bib}

\makeatletter
\protected\def\blx@aux@count#1#2{%
  \csnumgdef{blx@count@#1@\detokenize{#2}}{\csuse{blx@count@#1@\detokenize{#2}}+1}%
  \ifnumgreater{\csuse{blx@count@#1@\detokenize{#2}}}{0\csuse{blx@maxcitecount@#1}}
    {\csnumgdef{blx@maxcitecount@#1}{\csuse{blx@count@#1@\detokenize{#2}}}}
    {}%
}

\ExecuteBibliographyOptions{citecounter=true}

\AtEveryCitekey{%
  \ifcsundef{blx@count@\therefsection @\strfield{entrykey}}
    {\edef\blx@cite@colour{0}}
    {\edef\blx@cite@colour{%
       \the\numexpr255*\csuse{blx@count@\therefsection @\strfield{entrykey}}/
          \csuse{blx@maxcitecount@\therefsection}\relax}}%
  \color[RGB]{\blx@cite@colour,0,0}%
}
\makeatletter

\begin{document}
Lorem\autocite{sigfridsson} ipsum\autocite{worman} dolor\autocite{nussbaum}

Lorem\autocite{sigfridsson} ipsum\autocite{worman} dolor\autocite{geer}

Lorem\autocite{sigfridsson} ipsum\autocite{worman} dolor\autocite{knuth:ct:b}

Lorem\autocite{sigfridsson} ipsum\autocite{knuth:ct:a} dolor\autocite{nussbaum}

\printbibliography
\end{document}

Citations with numbers in shades between red and black according to their cite count.

1
  • 1
    Great solution! Another possibility would be to show the frequency from blue to red by multiplying by 100 and then using \color{red!\blx@cite@colour!blue} for the color.
    – Jojo
    Aug 30, 2018 at 15:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .