4

I want to change the default style sheet for the KnitHTML function in RStudio 0.96.331.

I follow the instructions in this post.

First I copy past the original markdown.css from here . As a test I change the first few lines from:

body, td {
font-family: sans-serif;
background-color: white;
font-size: 12px;
margin: 8px;
}

to red background

body, td {
font-family: sans-serif;
background-color: red;
font-size: 12px;
margin: 8px;
}

and save it as mymd.css in my working directory. I then create a style.R file as follows:

options(rstudio.markdownToHTML =
  function(inputFile, outputFile) {     
    require(markdown)
    markdownToHTML(inputFile, outputFile, stylesheet='mymd.css')  
  }
)

Finally, I source the style.R file by clicking source and then go back to the .Rmd file and knit it to HTML. I get the red background, but the math is not compiled e.g. $\alpha$

Fred
  • 1,833
  • 3
  • 24
  • 29

3 Answers3

1

AFAIK,MathJax service was down yesterday due to the GoDaddy outage. Can you confirm the math problem was not due to that?

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
  • tried again and still no math rendering. You can replicate it I'm sure. – Fred Sep 14 '12 at 16:23
  • @Fred OK, I can reproduce it. I think this is a bug of the `markdown` package, and you need to report it to the package author or RStudio developers. – Yihui Xie Sep 14 '12 at 18:25
  • Has this bug been addressed? – StevieP May 12 '14 at 19:48
  • 1
    @StevieP I'm not sure if it has been fixed, and you can try the latest version (v0.7) on CRAN. Anyway, we are moving towards the rmarkdown package now: http://rmarkdown.rstudio.com – Yihui Xie May 13 '14 at 05:31
0

So I may have a work around for you, but it involves using pandoc:

Suppose your style sheet is called style.css

Source the following code:

options(rstudio.markdownToHTML = function(inputFile, outputFile) {
        system(paste("pandoc -c style.css", shQuote(inputFile),
                     "-o", shQuote(outputFile)))
          }
        )  
StevieP
  • 1,569
  • 12
  • 23
  • 1
    Just FYI, this has been made very easy with the rmarkdown package: http://rmarkdown.rstudio.com – Yihui Xie May 13 '14 at 05:32
  • *edit* finally got it to work. As a note to future self/others: if Ubuntu's software center won't let you install a .deb, right click and try the deb package manager. – StevieP May 14 '14 at 14:31
0

This is maybe a new feature that was not available at the time the question was asked. However, there is a simple solution I found here:

https://bookdown.org/yihui/rmarkdown/html-document.html#appearance-and-style

In the preamble of your .Rmd, just write this:

---
title: "Your title"
output: 
  html_document:
    css: yourstylefile.css
---
Tom
  • 834
  • 1
  • 14
  • 24