Repository navigation
Support all math rendering engines from Pandoc in HTML documents #1940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
ce99527
add math argument to html_document and _base
atusy f42112f
further generalization
atusy a5c6f38
doc
atusy d0b833c
fix mathjax:local not working
atusy 267a7f5
add NEWS
atusy de7e21b
remove a comment
atusy f8b1b5e
improve support for default templates
atusy 02005e8
fix math not working when non-default template is used
atusy 15c6cbc
Merge branch 'main' into math
cderv 3e0b728
Merge branch 'main' into math
cderv caf4eb1
Merge branch 'main' into atusy-math
cderv 41294e5
keep the trick for now to load mathajx using JS
cderv da30e77
Use the same katex script than the one inserted by pandoc
cderv 58abe7d
Refactoring of new math argument
cderv aef9e12
Re document
cderv bb3043c
Add some test for new math support
cderv fb49810
Missing test file
cderv 499f7d1
mathjax local only works in RStudio IDE
cderv 47523b4
Mathjax can also be NULL
cderv 19fa506
Better check supported math argument
cderv 847c68a
refactor to test backward compatibilaty
cderv d69bb7a
Transform math argument to list once in each format
cderv 84e2f64
Order of argument is really important
cderv bb6e515
document()
cderv 4bbaae3
Add Katex as a htmlDependency
cderv 48c9182
handle extras dependency for katex
cderv 1e92073
Remove KaTeX header from template as it should be included as HTML de…
cderv 6f7c1dd
Use the HTML dependency when inserting KaTeX
cderv d769b42
Try adding support in `slidy_presentation()`
cderv db94a31
Adapt test
cderv 043bb9a
Insure math is not set to something else than Mathjax in `ioslide_pre…
cderv 645c684
Same as 84e2f640091c4d818aafb8a7a448c7ae0f2f2801
cderv d3c16e1
Rename new argument to `math_method`
cderv 01c0784
re document()
cderv 1bf45fe
Update NEWS and bump version
cderv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| Type: Package | ||
| Package: rmarkdown | ||
| Title: Dynamic Documents for R | ||
| Version: 2.11.12 | ||
| Version: 2.11.13 | ||
| Authors@R: c( | ||
| person("JJ", "Allaire", , "[email protected]", role = "aut"), | ||
| person("Yihui", "Xie", , "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-0645-5666")), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -470,3 +470,39 @@ html_dependency_header_attrs <- function() { | |
| ) | ||
| } | ||
| } | ||
|
|
||
| # Store KaTeX as a html dependency to include in our template | ||
| html_dependency_katex <- function() { | ||
| cdn <- "https://cdn.jsdelivr.net/npm/[email protected]/dist/" | ||
| htmlDependency( | ||
| name = "katex", version = "0.15.2", | ||
| src = c(href = cdn), | ||
| script = list(src = "katex.min.js", | ||
| integrity = "sha256-bgI9WhLOPSUlPrdgHUg3rPIB2vq+D+mYkUTM3q0U8fw=", | ||
| crossorigin = 'anonymous', | ||
| 'data-external' = "1", | ||
| defer = NA), | ||
| # TODO: reactivate when we can set data-external = 1 in htmltools | ||
| # | ||
| # stylesheet = c("katex.min.css"), | ||
| # from Pandoc | ||
| # https://github.com/jgm/pandoc/blob/7ddb609aae48ec10ef9899b25c52a4abecfbc176/src/Text/Pandoc/Writers/HTML.hs#L313 | ||
| head = c( | ||
| '<script>document.addEventListener("DOMContentLoaded", function () {', | ||
| ' var mathElements = document.getElementsByClassName("math");', | ||
| ' var macros = [];', | ||
| ' for (var i = 0; i < mathElements.length; i++) {', | ||
| ' var texText = mathElements[i].firstChild;', | ||
| ' if (mathElements[i].tagName == "SPAN") {', | ||
| ' katex.render(texText.data, mathElements[i], {', | ||
| ' displayMode: mathElements[i].classList.contains("display"),', | ||
| ' throwOnError: false,', | ||
| ' macros: macros,', | ||
| ' fleqn: false', | ||
| ' });', | ||
| ' }}});', | ||
| '</script>"', | ||
| sprintf('<link rel="stylesheet" href="%skatex.min.css" data-external="1">', cdn) | ||
| ) | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,6 +89,30 @@ | |
| #' 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. | ||
| #'@param math_method Math rendering engine to use. This will define the math method to use with Pandoc. | ||
| #' | ||
| #' * It can be a string for the engine, one of | ||
| #' `r knitr::combine_words(pandoc_math_engines(), and = "or ", before = "'")`, | ||
| #' or `default` for `mathjax`. | ||
| #' * It can be a list of | ||
| #' * `engine`: one of | ||
| #' `r knitr::combine_words(pandoc_math_engines(), and = "or ", before = "'")`. | ||
| #' * `url`: A specific url to use with `mathjax`, `katex` or `webtex`. | ||
| #' Note that for `engine = "mathjax"`, `url = "local"` will use a local version of MathJax (which is | ||
| #' copied into the output directory). | ||
| #' | ||
| #' For example, | ||
| #' ```yaml | ||
| #' output: | ||
| #' html_document: | ||
| #' math_method: | ||
| #' engine: katex | ||
| #' url: https://cdn.jsdelivr.net/npm/[email protected]/dist | ||
| #' ``` | ||
| #' | ||
| #' See [Pandoc's Manual about Math in HTML](https://pandoc.org/MANUAL.html#math-rendering-in-html) for the details. | ||
| #' Note that `c(mathjax = "local")` is equivalent to specifying "local" to | ||
| #' `mathjax`. | ||
| #'@param section_divs Wrap sections in \code{<div>} tags, and attach identifiers to the | ||
| #' enclosing \code{<div>} rather than the header itself. | ||
| #'@param template Pandoc template to use for rendering. Pass "default" to use | ||
|
|
@@ -333,6 +357,7 @@ html_document <- function(toc = FALSE, | |
| theme = "default", | ||
| highlight = "default", | ||
| highlight_downlit = FALSE, | ||
| math_method = "default", | ||
| mathjax = "default", | ||
| template = "default", | ||
| extra_dependencies = NULL, | ||
|
|
@@ -612,7 +637,9 @@ html_document <- function(toc = FALSE, | |
| on_exit = on_exit, | ||
| base_format = html_document_base(theme = theme, | ||
| self_contained = self_contained, | ||
| lib_dir = lib_dir, mathjax = mathjax, | ||
| lib_dir = lib_dir, | ||
| math_method = math_method, | ||
| mathjax = mathjax, | ||
| template = template, | ||
| pandoc_args = pandoc_args, | ||
| extra_dependencies = extra_dependencies, | ||
|
|
@@ -673,15 +700,6 @@ html_highlighters <- function() { | |
| c(highlighters(), "textmate") | ||
| } | ||
|
|
||
| default_mathjax <- function() { | ||
| paste0("https://mathjax.rstudio.com/latest/", mathjax_config()) | ||
| } | ||
|
|
||
| mathjax_config <- function() { | ||
| "MathJax.js?config=TeX-AMS-MML_HTMLorMML" | ||
| } | ||
|
|
||
|
|
||
| navbar_html_from_yaml <- function(navbar_yaml) { | ||
|
|
||
| # parse the yaml | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.