Search code examples
htmlcssshinymathjax

Mathjax alignment in Shiny


I've found ways to left-align ALL of the Mathjax equations in my shiny app, but I want to center a couple of equations. Is there a way to differentially apply this CSS?

tags$style(HTML("div.MathJax_Display{text-align: left !important;}"))),

Is there a way to specify "text-align: center" when I send the equation to output?

withMathJax(tags$p(equation))

Solution

  • You can use CSS classes as follows:

    library(shiny)
    
    ui <- fluidPage(
      withMathJax(),
      tags$style(HTML(
        "p.mjleft div.MathJax_Display{text-align: left !important;}",
        "p.mjcenter div.MathJax_Display{text-align: center !important;}"
      )),
      br(),
      tags$p("$$\\int_0^1$$", class = "mjleft"),
      tags$p("$$\\int_0^1$$", class = "mjcenter")
    )
    
    server <- function(input, output) {}
    
    shinyApp(ui, server)
    

    enter image description here