此处提供了一种在线显示 LaTeX 方程的解决方案,并带有一个工作现场演示
上面提到的在线显示方程的解决方案是(剪切几行代码):
ui.R:
library(shiny)
shinyUI(fluidPage(
title = 'MathJax Examples with in-line equations',
withMathJax(),
# section below allows in-line LaTeX via $ in mathjax. Replace less-than-sign with <
# and grater-than-sign with >
tags$div(HTML("less-than-sign script type='text/x-mathjax-config' greater-than-sign
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
less-than-sign /script greater-than-sign
")),
helpText('An irrational number $\\sqrt{2}$
and a fraction $1-\\frac{1}{2}$'),
helpText('and a fact about $\\pi$:$\\frac2\\pi = \\frac{\\sqrt2}2 \\cdot
\\frac{\\sqrt{2+\\sqrt2}}2 \\cdot
\\frac{\\sqrt{2+\\sqrt{2+\\sqrt2}}}2 \\cdots$'),
uiOutput('ex1')
))
服务器.R:
shinyServer(function(input, output, session) {
output$ex1 <- renderUI({
withMathJax(helpText('Dynamic output 1: $\\alpha^2$'))
})
})
我在 macOS 上运行 R 版本 3.5.2 和闪亮的 1.2。应用程序输出是一些逐字文本,而不是预期的文本和内联方程的混合:
less-than-sign script type='text/x-mathjax-config' greater-than-sign MathJax.Hub.Config({ tex2jax: {inlineMath: [['$','$'], ['′,′
']]} }); less-than-sign /script greater-than-sign
and a fact about $\pi$:$\frac2\pi = \frac{\sqrt2}2 \cdot \frac{\sqrt{2+\sqrt2}}2 \cdot \frac{\sqrt{2+\sqrt{2+\sqrt2}}}2 \cdots$
Dynamic output 1: $\alpha^2$
可能是因为我的 R 环境吗?