【问题标题】:R shiny with mathjax: How to avoid parentheses being automatically placed in math mode?R Shiny with mathjax:如何避免括号自动置于数学模式?
【发布时间】:2020-06-23 14:51:45
【问题描述】:

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

在MWE,第一个Hello!应该打印为 (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)

【问题讨论】:

    标签: r shiny mathjax


    【解决方案1】:

    解决方案 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

    在 HTML 中使用&lt;span class='tex2jax_ignore'&gt; 直接转义“()”。将您的 h4 替换为:

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

    这甚至可以让您转义“$”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-07
      • 1970-01-01
      • 2018-07-05
      • 2018-10-24
      • 1970-01-01
      • 2016-10-27
      • 2020-11-28
      • 1970-01-01
      相关资源
      最近更新 更多