3

I am having troubles when changing the color of inline citations in a pdf output from RMarkdown. Let's start with the YAML:

---
title: MY TITLE
author: "Mario Modesto-Mata"
date: "20 September 2018"
output:
  pdf_document:
    highlight: espresso
    number_sections: yes
    toc: yes
    toc_depth: 4
bibliography: references.bib
csl: ajpa.csl
---

As you can see, I have my bibliography specified (references.bib) and the citation style (ajpa.csl). I must say it works pretty nice.

However, I am writing a long manuscript and I would like inline citations to be colored to allow readers distinguish what is text and what are citations.

Before changing color

This is my example where you can see the inline citations.

Cada diente se forma en un momento concreto bajo una fuerte regulación genética. Por lo tanto, presentan cada uno su propia trayectoria de crecimiento, desarrollo, tasa de formación y momento de erupción, que son relativamente independientes del resto de piezas dentales. Por este motivo, cada especie posee un patrón de desarrollo dental particular y bien definido en función de las trayectorias de crecimiento concretas de cada diente o clase de dientes [@BermudezdeCastrochicoGranDolina2002; @SmithDentaldevelopmentevolution1991; @SmithDentaldevelopmentmeasure1989; @SmithPatternsdentaldevelopment1994]. El desarrollo dental es altamente heredable y relativamente resistente a los procesos de malnutrición y enfermedad, existiendo menos variación en su patrón de desarrollo respecto a los parámetros de maduración esqueléticos [@Lewisrelationshiptoothformation1960].

When I convert it into a PDF using RMarkdown, I get correct inline citations: enter image description here

After changing color

I searched on this forum and found a potential solution, as you can read in the original question.

However, when I implement those tips, as seen in this code:

Cada diente se forma en un momento concreto bajo una fuerte regulación genética. Por lo tanto, presentan cada uno su propia trayectoria de crecimiento, desarrollo, tasa de formación y momento de erupción, que son relativamente independientes del resto de piezas dentales. Por este motivo, cada especie posee un patrón de desarrollo dental particular y bien definido en función de las trayectorias de crecimiento concretas de cada diente o clase de dientes \textcolor{blue}{[@BermudezdeCastrochicoGranDolina2002; @SmithDentaldevelopmentevolution1991; @SmithDentaldevelopmentmeasure1989; @SmithPatternsdentaldevelopment1994]}. El desarrollo dental es altamente heredable y relativamente resistente a los procesos de malnutrición y enfermedad, existiendo menos variación en su patrón de desarrollo respecto a los parámetros de maduración esqueléticos \textcolor{blue}{[@Lewisrelationshiptoothformation1960]}.

I get this output:

enter image description here

As you can see, the bracked text has turned blue, but I lost the correct inline citations.

Question

  1. How can I change the color of the inline citations without losing the citations themselves? Maybe there is an option to add in the YAML (which would be fantastic) instead of customizing every single citation along the whole manuscript?

UPDATE

You can download a ZIP file with part of my Rmd file, ajpa.csl and references.bib.

antecessor
  • 2,688
  • 6
  • 29
  • 61
  • 1
    Try with `\begingroup\color{blue}[@X; @Y; ... ]\endgroup`. – Werner Nov 23 '18 at 18:09
  • It works nice. However, is there any possibility to include that style in the YAML? I have hundreds of citations in my manuscript and it becomes a hard task... – antecessor Nov 24 '18 at 19:54
  • I'll attempt to provide some guidance here if you can supply a comprehensive, complete minimal example that includes an entire Rmarkdown document, together with `reference.bib` and a link to `ajpa.csl`. Of course, just use on reference and a small document... – Werner Nov 25 '18 at 07:27
  • @Werner I updated my question with a link to download a ZIP file by the end. Thanks in advance. – antecessor Nov 25 '18 at 09:37

1 Answers1

5

We can set YAML options link-citations: yes and linkcolor: blue.

---
title: MY TITLE
author: "Mario Modesto-Mata"
date: "20 September 2018"
output:
  pdf_document:
    highlight: espresso
    number_sections: yes
    toc: yes
    toc_depth: 4
# bibliography: references.bib
# csl: ajpa.csl
references:
- id: hawking_thermodynamics_1983
  author:
  - family: Hawking
    given: S. W.
  - family: Page
    given: Don. N.
  publisher: Communications in Mathematical Physics
  title: Thermodynamics of Black Holes in Anti-de Sitter Space.
  volume: 87
  type: article-journal
  issued:
    year: 1983
link-citations: yes
linkcolor: blue
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## Header

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod 
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua 
[@hawking_thermodynamics_1983].

# Bibliography

Yielding

enter image description here

Note: This also works with bibliography: ... instead of references: ....

Is this what you want?

jay.sf
  • 60,139
  • 8
  • 53
  • 110
  • Partially. I would like all the citations to be colored in blue. So in the example `Hawking and Page 1963` would be in blue, not only the year. We are getting closer @jay.sf – antecessor Nov 26 '18 at 15:39
  • I'm not sure that's even possible. `rmarkdown` has its limits, consider to use LaTeX instead, or try to get an answer on [TeX-Stackexchange](https://tex.stackexchange.com/help/on-topic). Anyway, why do you want to do that at all? Do you really like to read such blueish papers: [https://doi.org/10.1016/j.annals.2014.12.001](https://doi.org/10.1016/j.annals.2014.12.001)? If you look at p. 145 of the quote from "Gursoy, Chi, & Dyer, 2009, 2010". Did you find it easily? What would you like that should happen if you click on the different years? – jay.sf Nov 26 '18 at 16:25
  • 1
    Thank you. linkcolor: blue also works for referencing tables and figures – Yacine Hajji Nov 25 '21 at 17:14