Browse Source

Mathjax works!

master
Garrick Aden-Buie 7 years ago
parent
commit
529b1b4fdf
3 changed files with 41 additions and 7 deletions
  1. +22
    -0
      R/bulma_document.R
  2. +6
    -6
      inst/bulma/bulma.html
  3. +13
    -1
      man/bulma_document.Rd

+ 22
- 0
R/bulma_document.R View File

#' --- #' ---
#' ``` #' ```
#' #'
#' @inheritParams rmarkdown::html_document_base
#' @inheritDotParams rmarkdown::html_document_base #' @inheritDotParams rmarkdown::html_document_base
#' @export #' @export
bulma_document <- function( bulma_document <- function(
dev = "png", dev = "png",
toc = FALSE, toc = FALSE,
toc_depth = 3, toc_depth = 3,
mathjax = "default",
pandoc_args = NULL, pandoc_args = NULL,
extra_dependencies = NULL extra_dependencies = NULL
) { ) {


pandoc_args <- c(pandoc_args, rmarkdown::pandoc_toc_args(toc, toc_depth)) pandoc_args <- c(pandoc_args, rmarkdown::pandoc_toc_args(toc, toc_depth))


mathjax_url <- if (mathjax %in% c("default", "local")) {
mathjax_local <- Sys.getenv("RMARKDOWN_MATHJAX_PATH", unset = NA)
if (mathjax == "local" && is.na(mathjax_local)) {
rlang::warn(
glue("Please use `Sys.setenv('RMARKDOWN_MATHJAX_PATH')` to set local mathjax location.",
"Falling back to online mathjax from https://mathjax.rstudio.com")
)
}
mathjax_path <- ifelse(mathjax == "default" || is.na(mathjax_local),
"https://mathjax.rstudio.com/latest",
mathjax_local)
file.path(mathjax_path, "MathJax.js?config=TeX-AMS-MML_HTMLorMML")
} else mathjax

if (!is.null(mathjax_url)) {
pandoc_args <- c(pandoc_args, "--mathjax", "--variable",
paste0("mathjax-url:", mathjax_url))
}

rmarkdown::output_format( rmarkdown::output_format(
knitr = rmarkdown::knitr_options_html( knitr = rmarkdown::knitr_options_html(
fig_width, fig_height, fig_retina, keep_md, dev fig_width, fig_height, fig_retina, keep_md, dev
base_format = rmarkdown::html_document_base( base_format = rmarkdown::html_document_base(
self_contained = TRUE, template = NULL, self_contained = TRUE, template = NULL,
pandoc_args = pandoc_args, pandoc_args = pandoc_args,
mathjax = mathjax,
extra_dependencies = extra_dependencies extra_dependencies = extra_dependencies
) )
) )

+ 6
- 6
inst/bulma/bulma.html View File

$if(mathjax-url)$ $if(mathjax-url)$
<!-- dynamically load mathjax for compatibility with self-contained --> <!-- dynamically load mathjax for compatibility with self-contained -->
<script> <script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "$mathjax-url$";
document.getElementsByTagName("head")[0].appendChild(script);
})();
document.addEventListener("DOMContentLoaded", function(event) {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "$mathjax-url$";
document.getElementsByTagName("head")[0].appendChild(script);
});
</script> </script>
$endif$ $endif$



+ 13
- 1
man/bulma_document.Rd View File

\usage{ \usage{
bulma_document(..., css = NULL, fig_width = 10, fig_height = 7, bulma_document(..., css = NULL, fig_width = 10, fig_height = 7,
fig_retina = 2, keep_md = FALSE, dev = "png", toc = FALSE, fig_retina = 2, keep_md = FALSE, dev = "png", toc = FALSE,
toc_depth = 3, pandoc_args = NULL, extra_dependencies = NULL)
toc_depth = 3, mathjax = "default", pandoc_args = NULL,
extra_dependencies = NULL)
} }
\arguments{ \arguments{
\item{...}{Ignored}

\item{mathjax}{Include mathjax. The "default" option uses an https URL from a
MathJax CDN. The "local" option uses a local version of MathJax (which is
copied into the output directory). You can pass an alternate URL or pass
\code{NULL} to exclude MathJax entirely.}

\item{pandoc_args}{Additional command line options to pass to pandoc}

\item{extra_dependencies}{Extra dependencies}

\item{...}{Arguments passed on to \code{rmarkdown::html_document_base} \item{...}{Arguments passed on to \code{rmarkdown::html_document_base}
\describe{ \describe{
\item{smart}{Produce typographically correct output, converting straight \item{smart}{Produce typographically correct output, converting straight

Loading…
Cancel
Save