Ver código fonte

Mathjax works!

master
Garrick Aden-Buie 7 anos atrás
pai
commit
529b1b4fdf
3 arquivos alterados com 41 adições e 7 exclusões
  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 Ver arquivo

@@ -29,6 +29,7 @@
#' ---
#' ```
#'
#' @inheritParams rmarkdown::html_document_base
#' @inheritDotParams rmarkdown::html_document_base
#' @export
bulma_document <- function(
@@ -41,6 +42,7 @@ bulma_document <- function(
dev = "png",
toc = FALSE,
toc_depth = 3,
mathjax = "default",
pandoc_args = NULL,
extra_dependencies = NULL
) {
@@ -93,6 +95,25 @@ bulma_document <- function(

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(
knitr = rmarkdown::knitr_options_html(
fig_width, fig_height, fig_retina, keep_md, dev
@@ -112,6 +133,7 @@ bulma_document <- function(
base_format = rmarkdown::html_document_base(
self_contained = TRUE, template = NULL,
pandoc_args = pandoc_args,
mathjax = mathjax,
extra_dependencies = extra_dependencies
)
)

+ 6
- 6
inst/bulma/bulma.html Ver arquivo

@@ -173,12 +173,12 @@ $endif$
$if(mathjax-url)$
<!-- dynamically load mathjax for compatibility with self-contained -->
<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>
$endif$


+ 13
- 1
man/bulma_document.Rd Ver arquivo

@@ -6,9 +6,21 @@
\usage{
bulma_document(..., css = NULL, fig_width = 10, fig_height = 7,
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{
\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}
\describe{
\item{smart}{Produce typographically correct output, converting straight

Carregando…
Cancelar
Salvar