Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to use \cancel with Shiny MathJax

I’m writing a shiny app that includes \cancel in the MathJax. I can’t figure out how to get it to work. Based on the link below, I guess I have to load the cancel TeX extension but I can’t figure out how.

library(shiny)

ui <- fluidPage(
  withMathJax(),
  div("$$1+2=3$$"), #Works
  div("$$\\cancel{10a}$$") #Doesnt work
)

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

shinyApp(ui, server)

Link
Problem

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

library(shiny)

js <- "
window.MathJax = {
  loader: {load: ['[tex]/cancel']},
  tex: {packages: {'[+]': ['cancel']}}
};
"

ui <- fluidPage(
  tags$head(
    tags$script(async="", src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"),
    tags$script(HTML(js))
  ),
  div("$$1+2=3$$"), 
  div("$$\\cancel{10a}$$") 
)

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

shinyApp(ui, server)

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading