Skip to content

Commit 07c8f0c

Browse files
committed
use skipStartupTypeset: true for MathJax config, and call MathJax.Hub.Typeset() later
setTimeout() is necessary for uiOutput(); we need to wait for a short while before typesetting math, otherwise two bad things can happen: 1. a math expression may be rendered twice (static output) 2. it is not rendered at all (dynamic ui output) so the compromise is to typeset math after a short while when the document is ready; 200 ms is an arbitrary choice here
1 parent 4415bf3 commit 07c8f0c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

R/shinyui.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,14 @@ includeScript <- function(path, ...) {
153153
withMathJax <- function(...) {
154154
path <- 'https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'
155155
tagList(
156-
tags$head(singleton(tags$script(src = path, type = 'text/javascript'))),
156+
tags$head(
157+
singleton(tags$script(HTML('window.MathJax = {skipStartupTypeset: true};'))),
158+
singleton(tags$script(src = path, type = 'text/javascript'))
159+
),
157160
...,
158-
tags$script(HTML('MathJax.Hub.Typeset();'))
161+
tags$script(HTML('$(function() {
162+
setTimeout(function() {MathJax.Hub.Typeset();}, 200);
163+
});'))
159164
)
160165
}
161166

0 commit comments

Comments
 (0)