Use KaTeX for pkgdown math rendering #437
Merged
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.
What's in this PR
This PR brings back fabulous math rendering to the pkgdown vignettes by switching the math rendering engine to KaTeX supported in pkgdown 2.1.0.
Before and after
This is what an example vignette section looks like before, current, and after this patch.
pkgdown 2.0.9 (old default, MathJax)
Click to expand screenshot
pkgdown 2.1.0 (new default, MathML)
Click to expand screenshot
pkgdown 2.1.0 + KaTeX
Click to expand screenshot
Method
To make this work, I did two things:
\hbox
with\text
, which is better supported by KaTeX and other engines.pkgdown/extra.css
andpkgdown/assets/fonts/
. This is because pkgdown 2.1.0 did not bundle them (not sure why) and the default math font rendering is subpar.Alternative paths
Apparently, MathML doesn't render very well for our formulas. Although we can choose the old default MathJaX, the font bundling situation is a bit more challenging to fix using the same customization approach as the fonts were defining in JS (I successfully converted them to CSS). Considering that KaTeX is faster and simpler, I think it's the optimal choice.
xref: keaven/gsDesign#161