bookdown
bookdown copied to clipboard
support katex
This is really a feature request, please adding Katex support as it is replacing all other math rendering these days, it's also very fast and easy to use.
Thanks! I'll consider it in the future. KaTeX is indeed very fast, but it only covers a subset of MathJax's LaTeX commands and environments: https://github.com/Khan/KaTeX/wiki/Function-Support-in-KaTeX For example, there is no equation environment.
I'd love this feature, too.
While I accept that KaTeX has some limitations, an option to switch between MathJax and KaTeX, similar to what is done by the prettydoc package would be great:
title: Nineteen Years Later
author: Harry Potter
date: July 31, 2016
output:
prettydoc::html_pretty:
theme: cayman
highlight: github
math: katex
Being able to add the bottom math: katex option, to a bookdown document or even html_notebook would be fantastic.
If you're wondering why I don't just use that package - it's because I'd prefer to be able to switch to KaTeX using arbitrary themes, but I don't seem to be able to - easily - get that package working in anything but the themes they've provided. Maybe I'm being dumb, but it's not as easy as deleting the theme and highlight lines, to revert back to the standard html output.
For example, there is no equation environment.
Just some news about this: Support has been added in August (https://github.com/KaTeX/KaTeX/pull/2369) but doc has not been updated in WIKI
Great - all the more reason to do it, then!
I opened PR rstudio/rmarkdown#1940 to solve this.
Is it already possible to use katex? Is it possible to pass math: katex to the YAML preamble?
No, not yet. When it becomes possible https://github.com/rstudio/rmarkdown/pull/1940 becomes merged and this issue becomes closed.
@prdm0 At least you can try with remotes::install_github("rstudio/rmarkdown#1940")
@atusy, thanks for the info. I will try it because I am writing material in bookdown that has many mathematical formulas and rendering with MathJax is a bit boring.
so is there currently a way to get Bookdown to build a Gitbook output with KaTeX instead of MathJax? I would even be happy with a way to entirely exclude MathJax so that I could just include a .js script that parses all the maths as KaTeX manually, but setting mathjax: null results in inline maths being rendered as unicode, without the LaTeX input being preserved in the tag data
Edit. For anybody looking to use KaTeX with the Gitbook output of Bookdown, the easiest way that I've found of doing so is to have
output:
bookdown::gitbook:
mathjax: null
pandoc_args: ["--gladtex"]
css: "katex.css"
includes:
after_body: "KaTeX.html"
where KaTeX.html loads the katex.js and then (using jQuery) renders all eq tags using KaTeX (as either display or inline, depending on the env attribute of the eq tag).
Just leaving this comment here in case other people find themselves in the same situation as me!
Sharing here that a new package by rOpenSci in on CRAN now : https://docs.ropensci.org/katex/reference/katex.html.
It enables server-side math-to-html rendering in R, such that no javascript library is needed in the html document.
rmarkdown now support KaTeX and other math method (rstudio/rmarkdown#1940)
For gitbook() to support it, we just need to change the way it is triggered. Currently it applies only when template = "default" in rmarkdown, which is not compatible with how this is set up in gitbook which uses a default template.
I think we need to change the way it is working or trick rmarkdown from bookdown so that it is activated.
Can we use katex in bookdown somehow? I found re-rendering math in live preview is very time-consuming and annoying.