How to add custom css Xaringan into a package

Hi I created a custom CSS file for my xaringan presentation template. How do I include that?

I created inst/rmarkdown/templates/rmhstyles/

Do I place it in:

  • resources
  • skeleton

Neither seems to work.

Error: "rmhstyle" is not a valid xaringan theme. Usexaringan:::list_css()to view all built-in themes.

can you share how you try to use it ?

xaringan won't be able to find itself your css file. you need to provide the whole path to your css.

I think having a custom theme in it own package, you would need to create a custom format in your package that is calling xaringan from your package and linking to the css file.

Otherwise, your package can offer a function to copy a css file in local folder, or offer a template that would create a folder with all assets.

If you share more on how you are currently working, I can try to give examples.

Great questions and I will try to explain.
I want to add a xaringan template with a small tweak in the css to a package.
Thanks to your tip I found out that a complete path (including .css) does indeed work.
But that is not very portable.
Is there an easy way to place the css and link to that?

If I set the template.yaml to this:

name: RMH style Xaringan presentation
description: >
  Create a presentation using the xaringan package based on remark.js.
create_dir: true

It wil create a folder and place the requested css files in there. but not the custom one.
When I place the css in the /inst/rmarkdown/templates/NAME/skeleton folder
the css is placed next to the rmarkdown file. But how can we tell xaringan that it should look locally?

I think if you just refer to local file it will find it. If the file is in same folder as your rmd file, Just with the name mycustom.css or explicit relative ./mycustom.css Otherwise full path would also work. As you already saw, You need to add .css so that xaringan know you are not trying to use a built in theme.

For function Inside a package, you can use system.files() to refer to files inside the package to get full path from where the package is installed. Only work for custom format you create in a package.

For template , what you have done should work.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.