6

I need to link my R Markdown to a css file. If the css file is in the same directory as the .Rmd file, it works without problems. If the css is in a different directory, it does not work.

How do I include a file path in the css field of my YAML?

This does not work

---
title: "MY TITLE"
author: "MY NAME"
output:
  xaringan::moon_reader:
    lib_dir: libs
    css: path/to/xaringan_themer.css
    nature:
      highlightStyle: tomorrow-night-bright
      highlightLines: true
      countIncrementalSlides: false
      titleSlideClass: ["center","top"]
---
Brigadeiro
  • 2,649
  • 13
  • 30
  • Not sure if this is recommended. In Rmarkdown, when your document renders, it looks immediately in the root directory for the necessary files, This is just how Rmarkdown works by default. Suggesting you keep the CSS in the same directory as the .Rmd file. – Daniel_j_iii May 29 '21 at 14:02
  • After tests, this works when the path you provide belongs to the **subdirectories** of the root folder where the `.Rmd` is located – Waldi Jun 14 '21 at 05:42
  • Perhaps this [discussion](https://github.com/jdblischak/workflowr/issues/95#issuecomment-359953292) helps – Waldi Jun 14 '21 at 07:52

1 Answers1

3

So I explore this topic which is a "hot" one for years.
The last news is a new issue which pointing out all previous one and offers a solution https://github.com/rstudio/rmarkdown/issues/1859. Author stating that his branches https://github.com/jonathan-g/rmarkdown/tree/jg-devel and https://github.com/jonathan-g/rmarkdown/tree/minimal-tree-fix (this last one is pruning my changes down to a minimal patch to keep the PR small) offers a solution for this problem. The PR is still not exists at this point, with the last update a few months ago.

Other solution (which i like) might be usage of symlinks, presented here: https://github.com/jdblischak/workflowr/issues/95#issuecomment-360138007 What is important, symlinks are supported by git. Example at https://github.com/stephenslab/wflow-divvy/tree/dev under organized dir.

polkas
  • 3,797
  • 1
  • 12
  • 25