1
votes

With knit2html() from the knitr package, I can generate html pages that contain latex equations and R code. But on my system equations are not rendered when using RStudio's "knit html" button.

It is because I have modified the way the "knit html" button works. To include a table of content on my html pages, I followed the Rstudio advice on Customize Markdown Rendering. And created an .Rprofile file at the root of the project directory that overrides default markdown rendering options. My .Rprofile only contains a function that replaces the rstudio.markdownToHTML() function as such:

options(rstudio.markdownToHTML = 
  function(inputFile, outputFile) {      
    require(markdown)
    htmlOptions <- markdownHTMLOptions(defaults=TRUE)
    htmlOptions <- c(htmlOptions, "toc")
    markdownToHTML(inputFile, outputFile, options = htmlOptions) 
  }
) 

With this .Rprofile, I'm happy to have an automatic table of content generated on all my .RmD documents. But equations are not rendered any more! Equations appear as plain text.

  • If I delete .Rprofile, reload R and click the "knit HTML" button in R Studio. Equations are rendered correctly but I don't have a table of content.
  • If I run :

    knit2html("file.Rmd", "file.html", options = c(markdownHTMLOptions(defaults=TRUE), "toc")))

    Equations are rendered correctly and I have a table of content too.

Can you help me fix rstudio.markdownToHTML() so that it renders equations?

Edit 03 April 2014: Equations are visible if I open the html page in a web browser. They are not rendered in RStudio preview HTML pane. This might be an issue with the mathjax script not taken into account anymore by the Rstudio viewer?

1
It would be beneficial if you showed us what code you're currently using in your .Rprofile. - Dason
Can you post the output of sessionInfo() - Dason
Thanks Dason, all that's in my .Rprofile, is now copied above. - Paul Rougieux
R version 3.0.2 (2013-09-25) Platform: i386-w64-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=English_Ireland.1252 LC_CTYPE=English_Ireland.1252 LC_MONETARY=English_Ireland.1252 [4] LC_NUMERIC=C LC_TIME=English_Ireland.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] knitr_1.5.21 MASS_7.3-29 loaded via a namespace (and not attached): [1] evaluate_0.5.1 formatR_0.10 stringr_0.6.2 tools_3.0.2 - Paul Rougieux
You could probably move your edit to an answer since it does sort of answer the question of how to make this work. - Dason

1 Answers

0
votes

Dason suggested me to post this as an answer.

Equations are visible if I open the html page in a web browser.

Equations are not rendered in RStudio preview HTML pane. This might be an issue with the Rstudio viewer?