# Highlighting Text Inline in Rmarkdown Or Bookdown PDF

HI,

I am trying to change the colour of a font in RMarkdown. I would like to be able to highlight in the document when i use a package. For example this seems to work for simple colours $\color{blue}{\text{readxl}}$ but I would like to set it up in such a way that the colour can use an RGB code for maybe something like steel blue (#003766). Using my previous method causes my document to crash with an unrecognizable colour error

! Illegal parameter number in definition of .

0
l.140 ...reation of this section (\color{#003766}
{\text{knitr}}), (\color...

My second question if someone has the time is to be able to format the colour behind the text, highlighting it like an inline code chunk for example library(rstudio).In essence i want to be able to highlight any packages I use in my analysis

Hi,

Could you give some more defined example, preferably the file with code so we can better understand the issue?

Thanks!

Hi,

A working example can be found here

Unfortunately it doesn't seem to work for something like book-down

An example of the shading of a word I was thinking of can be found here but its only for HTML

Thanks

Hi,

I found a way to do it for PDF, using LaTeX commands:

---
title: "RCommunityForum"
author: "PJ"
date: "13/07/2019"
output:
word_document: default
pdf_document:
extra_dependencies: xcolor
html_document:
df_print: paged
---

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

## R Markdown

\definecolor{fancyTextColor}{HTML}{4284f5}
\definecolor{hightlightColor}{HTML}{FFFF66}

This is an R Markdown document. \colorbox{hightlightColor}{Markdown} is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button \textcolor{fancyTextColor}{a document will be generated} that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

{r cars}
summary(cars)
\


* Careful if you copy paste this in markdown since I had to use \ to format the code as it uses  as well

Here are some websites for extra info

Grtz
PJ

Thank you very much for the reply PJ.
It works but when i try and integrate it into bookdown it seems to come unstuck

I am using the thesisdown package and i put the extra dependency in the YAML header as

---
output:
thesisdown::thesis_pdf: default
extra_dependencies: xcolor
---


I get the error

! LaTeX Error: Undefined color model HTML'.

Error: Failed to compile test_document.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips. See test_document.log for more info.
Execution halted

Hi,

Try using other color models and see if it produces the same error. It's possible that the HEX color values is not implemented by that package

\definecolor{fancyTextColor}{HTML}{4284f5}
\definecolor{fancyTextColor}{RGB}{66, 132, 245}
\definecolor{fancyTextColor}{rgb}{0.258, 0.517, 0.960}


If this doesn't help it's probably related to the package and not to LaTeX

PJ

1 Like

That's the one

Thank you very much....I was banging my head against the wall for this