3

I can include something like

<style>

code {
  font: 12px Monaco, "Courier New";
  color: #969699;
}

</style>

in a .css file to format my code in Rmarkdown. The problem is that the R output also inherits this font. Is there any way to give my code and the R output different fonts?

1 Answer 1

2

R source code in rmarkdown HTML output is placed between a <code> tag that lives inside a <pre> with class r. You want to apply the style to all instances of <code> that don't share this property. Here's an example using the :not() selector:

pre:not(.r) code {
  font: 12px Monaco, "Courier New";
  color: red;
}

For bookdown output formats you want to exlcude instances of <code> with class sourceCode:

code:not(.sourceCode) {
  font: 12px Monaco, "Courier New" !important;
  color: red !important;
}

Note that the use of !important is required here because the default styles have precedence.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.