R shiny with mathjax:如何避免括号自动置于数学模式?

R shiny with mathjax: How to avoid parentheses being automatically placed in math mode?

我有一个使用 MathJax 的闪亮应用程序。在我的普通文本中,MathJax 会自动将括号中的文本转换为数学模式。哪个设置允许我为括号这样简单的东西转义数学模式?

在MWE,第一个你好!应该打印为 (Hello!) 而不是数学模式。如何做到这一点?

MWE:

library(shiny)

server <- shinyServer(function(input, output) {
 })

ui <- shinyUI(fluidPage( 
  withMathJax(),
  tags$div(HTML("<script type='text/x-mathjax-config'>
                MathJax.Hub.Config({
                tex2jax: {inlineMath: [['$','$'], ['\(','\)']]}
                });
                </script>
                ")),

  titlePanel("Minimal application"),
    sidebarLayout(  
    sidebarPanel( 
      fluidRow(h4("(Hello!)"))),
    mainPanel(
      fluidRow(h4("Hello!")))
    )
   ))

shinyApp(ui=ui, server=server)

解决方案 1

最简单的解决方法是删除脚本中的 ['\(','\)']。这告诉数学引擎“(”和“)”之间将被视为数学模式。如果你想使用数学模式,你仍然可以使用“$xxx$”。

library(shiny)

server <- shinyServer(function(input, output) {
})

ui <- shinyUI(fluidPage( 
    withMathJax(),
    tags$div(HTML("<script type='text/x-mathjax-config'>
                MathJax.Hub.Config({
                tex2jax: {inlineMath: [['$','$']]}
                });
                </script>
                ")),

    titlePanel("Minimal application"),
    sidebarLayout(  
        sidebarPanel( 
            fluidRow(h4("(Hello!)"))),
        mainPanel(
            fluidRow(h4("Hello!")))
    )
))

shinyApp(ui=ui, server=server)

解决方案 2

直接使用<span class='tex2jax_ignore'>转义HTML中的“()”。将您的 h4 替换为:

fluidRow(HTML("<h4><span class='tex2jax_ignore'>(Hello!)</span></h4>"))),

这样你甚至可以转义“$”。