3

I have the following RMarkdown file:

---
title: "Test"
author: "Mr. Test"
date: "September 5, 2018"
output: pdf_document
urlcolor: red
---

[URL](www.google.com)

This produces the following:

enter image description here

The red link leads to www.google.com, as expected. Awesome. Now, say I wanted my URLs to be a nameless hexadecimal colour, say, #FF3300. I have tried various approaches to providing this colour without success. For example, #FF3300 is ignored as it is interpreted as a comment; "#FF3300" throws an error, as does "0xFF3300" and 0xFF3300. So, my question: what is the correct syntax when specifying hexadecimal colours in a YAML header?

Dan
  • 11,370
  • 4
  • 43
  • 68
  • 1
    I disagree that this is a dupe: that refers to markdown not YAML. That answer doesn't answer this question. – Dan Sep 05 '18 at 19:04
  • 2
    [The 68 standard colors](https://en.wikibooks.org/wiki/LaTeX/Colors#The_68_standard_colors_known_to_dvips) work by name. Haven't had success defining colors in the preamble. – missuse Sep 05 '18 at 19:21

1 Answers1

4

I can't seem to figure out how to properly escape the YAML header with urlcolor:, but you can explicitly include a header. You just need to encode the color value as three numbers 0-1 indicating the intensity of red, green, blue

title: "Test"
author: "Mr. Test"
date: "September 5, 2018"
output: "pdf_document"
header-includes:
    - \hypersetup{colorlinks=true, urlcolor = [rgb]{1,.2,0}}

Though #FF3300 is pretty close to red so it doesn't look much different in the output.

I don't think the problem is with YAML at all. The problem is that the color is done by hyperref and that'a LaTeX packaage that understands LaTeX colors rather than R color values. And the second problem is that rmakrdown or kniter or some combination is trying to escape the brackets and braces in those values such that it messed up the values when creating the LaTeX code via the urlcolor parameter.

MrFlick
  • 195,160
  • 17
  • 277
  • 295