bookdown icon indicating copy to clipboard operation
bookdown copied to clipboard

support katex

Open laoshaw opened this issue 8 years ago • 13 comments

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.

laoshaw avatar May 29 '17 17:05 laoshaw

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.

yihui avatar May 31 '17 00:05 yihui

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.

py9mrg avatar Feb 25 '20 15:02 py9mrg

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

cderv avatar Oct 29 '20 11:10 cderv

Great - all the more reason to do it, then!

py9mrg avatar Oct 29 '20 11:10 py9mrg

I opened PR rstudio/rmarkdown#1940 to solve this.

atusy avatar Oct 31 '20 01:10 atusy

Is it already possible to use katex? Is it possible to pass math: katex to the YAML preamble?

prdm0 avatar Nov 16 '20 21:11 prdm0

No, not yet. When it becomes possible https://github.com/rstudio/rmarkdown/pull/1940 becomes merged and this issue becomes closed.

atusy avatar Nov 16 '20 23:11 atusy

@prdm0 At least you can try with remotes::install_github("rstudio/rmarkdown#1940")

atusy avatar Nov 16 '20 23:11 atusy

@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.

prdm0 avatar Nov 17 '20 11:11 prdm0

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!

thosgood avatar Jan 02 '21 00:01 thosgood

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.

cderv avatar Jul 07 '21 12:07 cderv

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.

cderv avatar Feb 03 '22 15:02 cderv

Can we use katex in bookdown somehow? I found re-rendering math in live preview is very time-consuming and annoying.

fecet avatar Dec 12 '22 13:12 fecet