It has already been possible to set the text colors with custom css classes and change the color of code with the flair package. I haven’t been able to see anyone else being able to extend this to work with the LaTeX equations in xaringan, let alone unifying the color specification across all 3.
You start with using
setup_colors() to specify the colors you want to use along with the name to want to reference them as
library(xaringancolor) setup_colors( yellow = "#ffcc29", orange = "#f58634", green = "#007965" )
Calling this function (preferably in the console, you won’t need to keep it) copies a section of text into your clipboard that you will have to include in the beginning of your xaringan document.
And that is all the setup you need to do to have color support across your document.
xaringancolor sets up a css class for each of the colors you specify with the sole purpose of changing the color. So In our example, writing
.orange[hello] would produce a orange hello
Code highlighting using flair is done the same as you normally would, see this article for more examples.
You now just use
color = green in
flair() instead of supplying a hex-color and it will match the color used in the css classes. Furthermore since we have the the
green variable, you can use it to specify colors in charts as well for maximum effect!
To use the colors in LaTeX equations you need to use LaTeX macros/functions. So you have a green X you would write