5

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.

Andre Silva
  • 4,782
  • 9
  • 52
  • 65
polmath
  • 335
  • 2
  • 13

1 Answers1

5

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).

Community
  • 1
  • 1
Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
  • Thank you very much, in my web browser the latex equations are displayed correctly. – polmath Aug 06 '14 at 08:38
  • Unfortunately, the second solution you propose does not work for me (neither with "mathjax: 'http://...'" nor with "mathjax: '//...'"). – polmath Aug 06 '14 at 08:54
  • Note from the future: cdn.mathjax.org is nearing its end-of-life, check https://www.mathjax.org/cdn-shutting-down/ for migration tips. – Peter Krautzberger Apr 12 '17 at 09:06