Skip to content
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

Use KaTeX for pkgdown math rendering #437

Merged
merged 3 commits into from
Jul 23, 2024
Merged

Use KaTeX for pkgdown math rendering #437

merged 3 commits into from
Jul 23, 2024

Conversation

nanxstats
Copy link
Collaborator

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 old-mathjax

pkgdown 2.1.0 (new default, MathML)

Click to expand screenshot current-mathml

pkgdown 2.1.0 + KaTeX

Click to expand screenshot after-katex

Method

To make this work, I did two things:

  • In vignettes, Replaced \hbox with \text, which is better supported by KaTeX and other engines.
  • Shipped the KaTeX math fonts using the pkgdown customization mechanism pkgdown/extra.css and pkgdown/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

@nanxstats nanxstats added the documentation Improvements or additions to documentation label Jul 23, 2024
@nanxstats nanxstats self-assigned this Jul 23, 2024
Copy link
Collaborator

@LittleBeannie LittleBeannie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @nanxstats !

@LittleBeannie LittleBeannie merged commit e68d4c8 into main Jul 23, 2024
7 checks passed
@LittleBeannie LittleBeannie deleted the katex branch July 23, 2024 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants