xaringancolor announcement

Announcement post for the xaringancolor package.

xaringan
Published

February 4, 2021

I’m happy to announce a small new package of mine: xaringancolor. xaringancolor allows you to specify shared text colors in the text, equations and code sections of xaringan slides.

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.

Setup

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.

HTML

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

Source Code

Code highlighting

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!

Source Code

Equations

To use the colors in LaTeX equations you need to use LaTeX macros/functions. So you have a green X you would write \green{X}.

Source Code

Advanced Examples

Last example is a re-implementation of Andrew Heiss absolutely amazing colorful slide

Source Code