在Shiny模式下的R Markdown中插入Latex方程式

时间:2022-06-03 19:10:18

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:

我想在R Markdown文档中插入Latex方程和Shiny apps。但是,使用以下行,Latex方程式无法正确显示:

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

降价文档中的两个Latex方程式在HTML文档中显示为\(x \)(如果我禁止行“runtime:shiny”,它们将在HTML文档中正确显示)。这可能是一个错误,或者Shiny和Latex之间是否存在任何不兼容性?我使用的是RStudio 0.98.981。

1 个解决方案

#1


4  

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.

有两种可能的解决方案。第一个是单击“在浏览器中打开”按钮在Web浏览器中打开页面,数学表达式将正确呈现。 RStudio窗口中的问题是默认使用MathJax的HTTPS链接(此处为文档),您可以将其替换为普通的http链接,例如:

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

但请注意,“无协议”//链接在某些情况下可能不起作用(了解更多)。

#1


4  

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.

有两种可能的解决方案。第一个是单击“在浏览器中打开”按钮在Web浏览器中打开页面,数学表达式将正确呈现。 RStudio窗口中的问题是默认使用MathJax的HTTPS链接(此处为文档),您可以将其替换为普通的http链接,例如:

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

但请注意,“无协议”//链接在某些情况下可能不起作用(了解更多)。