Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting Latex equations in R Markdown in Shiny mode

I would like to insert Latex equations and Shiny apps in an R Markdown document. However, with the following lines the Latex equations are not displayed correctly:

---
title: "Untitled"
date: "Saturday, August 02, 2014"
output: html_document
runtime: shiny
---

Test 

* test 1 :  $x$
* test 2 : \(x\)

Both Latex equations in the markdown document appear as \(x\) in the HTML document (if I suppress the line "runtime: shiny", they are displayed correctly in the HTML document). Would this possibly be a bug, or is there any incompatibility between Shiny and Latex? I am using RStudio 0.98.981.

like image 679
polmath Avatar asked Aug 02 '14 22:08

polmath


1 Answers

There are two possible solutions. The first one is to click the button Open in Browser to open the page in your web browser, and the math expression will render correctly. The problem in the RStudio window is that the HTTPS link to MathJax is used by default (documentation here), and you can replace it with a normal http link, e.g.

---
title: "Untitled"
date: "Saturday, August 02, 2014"
output:
  html_document:
    mathjax: "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
runtime: shiny
---

Test 

* test 1 :  $x$
* test 2 : \(x\)

Or to make it even more portable, use

mathjax: "//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"

But please note the "protocol-less" //... link may not work in certain cases (read more).

like image 115
Yihui Xie Avatar answered Oct 19 '22 14:10

Yihui Xie