jekyll-theme-chirpy
jekyll-theme-chirpy copied to clipboard
feat(maths): add KaTeX support for server-side math rendering
Type of change
- [X] New feature (non-breaking change which adds functionality)
Description
This PR adds support for KaTeX as an alternative math rendering engine to the existing MathJax implementation. Users can now choose between client-side rendering (MathJax) or server-side rendering (KaTeX) for mathematical expressions.
This can improve performance as KaTeX renders math expressions at build time, eliminating the need for client-side JavaScript processing and resulting in faster page loads. The changes maintain full backward compatibility, as it defaults back to MathJax if the user does no config changes.
KaTex does have some LaTeX missing features, such as \label is not supported.
Changes
Configuration
- Added
math.enginesetting to _config.yml with options:mathjax(default) orkatex - Added
jektexconfiguration block for KaTeX rendering options (cache directory, ignore patterns, macros) - Added
jektex ~> 0.1.1gem dependency to jekyll-theme-chirpy.gemspec
Template Logic
- Modified js-selector.html to conditionally load MathJax based on engine selection
- Modified head.html to conditionally load KaTeX CSS when using KaTeX engine
- Updated asset paths in basic.yml and cors.yml to include KaTeX CSS
Styling
- Added overflow handling for
.katex-displayin _base.scss to prevent layout issues with wide equations
Documentation
- Updated 2019-08-08-write-a-new-post.md with comprehensive documentation on:
- How to choose between MathJax and KaTeX
- Comparison of features and trade-offs
- Configuration examples
- Known limitations (KaTeX doesn't support
\labeland\eqref)
- Simplified math examples in 2019-08-08-text-and-typography.md (removed equation references for KaTeX compatibility)
- Added feature entry to CHANGELOG.md
Usage
Using MathJax (default, no changes required):
math:
engine: # empty or 'mathjax'
Using KaTeX:
math:
engine: katex
jektex:
ignore: ["*.xml"] # Process markdown files, ignore feed.xml
Then add jektex to your Gemfile and run bundle install.