diff --git a/R/markdown.R b/R/markdown.R
index 6de9962fc..b5dabba5b 100644
--- a/R/markdown.R
+++ b/R/markdown.R
@@ -121,12 +121,7 @@ convert_markdown_to_html <- function(pkg, in_path, out_path, ...) {
"--indented-code-classes=R",
"--section-divs",
"--wrap=none",
- ifelse(
- # katex is handled separately
- config_math_rendering(pkg) == "katex",
- "",
- paste0("--", config_math_rendering(pkg))
- ),
+ paste0("--", config_math_rendering(pkg)),
...
))
)
diff --git a/inst/BS5/assets/katex-auto.js b/inst/BS5/assets/katex-auto.js
new file mode 100644
index 000000000..20651d9fd
--- /dev/null
+++ b/inst/BS5/assets/katex-auto.js
@@ -0,0 +1,14 @@
+// https://github.com/jgm/pandoc/blob/29fa97ab96b8e2d62d48326e1b949a71dc41f47a/src/Text/Pandoc/Writers/HTML.hs#L332-L345
+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
+ });
+ }}});
diff --git a/inst/BS5/templates/head.html b/inst/BS5/templates/head.html
index b67467099..ba3541467 100644
--- a/inst/BS5/templates/head.html
+++ b/inst/BS5/templates/head.html
@@ -17,6 +17,7 @@
+
{{/uses_katex}}
{{#lightswitch}}{{/lightswitch}}