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
This commit is contained in:
Yihui Xie
2014-03-18 14:24:23 -05:00
parent 4415bf31d2
commit 07c8f0c4b7

View File

@@ -153,9 +153,14 @@ includeScript <- function(path, ...) {
withMathJax <- function(...) {
path <- 'https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'
tagList(
tags$head(singleton(tags$script(src = path, type = 'text/javascript'))),
tags$head(
singleton(tags$script(HTML('window.MathJax = {skipStartupTypeset: true};'))),
singleton(tags$script(src = path, type = 'text/javascript'))
),
...,
tags$script(HTML('MathJax.Hub.Typeset();'))
tags$script(HTML('$(function() {
setTimeout(function() {MathJax.Hub.Typeset();}, 200);
});'))
)
}