MathJax script issue after customizing rstudio.markdownToHTML()

江枫思渺然 提交于 2019-12-11 05:33:30

问题


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:


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?



来源:https://stackoverflow.com/questions/22454492/mathjax-script-issue-after-customizing-rstudio-markdowntohtml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!