[Rd] Bundling MathJax

Ivan Krylov kry|ov@r00t @end|ng |rom gm@||@com
Mon Mar 14 21:59:53 CET 2022

On Sun, 13 Mar 2022 20:52:26 +0530
Deepayan Sarkar <deepayan.sarkar using gmail.com> wrote:

> Usually browser caching should avoid multiple downloads, shouldn't it?

True, but there's also the issue of download.file() called from Rd2HTML
spending time (or timing out) on round-trips to the server. The
cacheOK= option only controls the server-side caching, as far as my
understanding of src/modules/internet/libcurl.c goes, so the file is
always downloaded from the CDN.

If that's the way you would like to go, the TOCTOU problem can be
avoided by sending the HTML page to the client with plain text math
visible and LaTeX math invisible, a script performing
createElement()/appendChild() to actually download MathJax, and handling
the "load" event of the newly created <script> element to replace the
plain text math with its LaTeX rendering, when (if) the script actually

> Would it be reasonable to use the installation provided by mathjaxr
> instead, if it is available?

That's very reasonable. If this becomes a function used by Rd2HTML by
default, it could be a good idea to give Priority: recommended to
mathjax to ensure that most users don't have to hit the network when
browsing documentation. Although this may be harder to combine with my
previous idea; too many moving parts.

Best regards,

More information about the R-devel mailing list