Skip to content

KaTeX: drop js script files, use build-time rendering instead#2276

Merged
chalin merged 5 commits intogoogle:mainfrom
deining:server-side-latex
Nov 22, 2025
Merged

KaTeX: drop js script files, use build-time rendering instead#2276
chalin merged 5 commits intogoogle:mainfrom
deining:server-side-latex

Conversation

@deining
Copy link
Copy Markdown
Contributor

@deining deining commented Jun 1, 2025

This PR fixes #2270.

With > 300 lines dropped (user guide + scripts), this PR significantly simplifies the documentation and the code base for KaTeX handling. This PR brings several advantages to the user:

  • faster page loading times through build time rendering
  • Autoactivation works in all cases now, also with inline formulae. Activation and configuration were dropped completely from the configuration file, everything is done behind the scenes now.
  • mhchem extension is included in Hugo's embedded KaTeX engine as of v.0.144.0. No need for activation or configuration of mhchem extension inside the config file any more.

Preview: https://deploy-preview-2276--docsydocs.netlify.app/docs/adding-content/diagrams-and-formulae/

@deining deining requested review from Copilot and geriom June 1, 2025 21:00
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR simplifies KaTeX handling by dropping the client‐side JavaScript files in favor of Hugo’s embedded, server‐side rendering engine, which improves performance and reduces configuration complexity.

  • Removed manual activation and configuration instructions from documentation
  • Eliminated JS script loading for KaTeX and its auto-render/mhchem extensions
  • Updated render templates for math and chemical code blocks to use transform.ToMath

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
userguide/content/en/docs/adding-content/diagrams-and-formulae/index.md Documentation updated to reflect server-side rendering and removal of manual activation.
layouts/_partials/scripts/katex.html Removed JS loading for KaTeX, now only loads stylesheet since rendering is done server side.
layouts/_partials/scripts.html Updated condition to load the KaTeX partial based on server-rendering flags.
layouts/_markup/render-passthrough.html Updated to use transform.ToMath for math rendering.
layouts/_markup/render-codeblock-math.html Simplified math block rendering using transform.ToMath.
layouts/_markup/render-codeblock-chem.html Simplified chemical rendering using transform.ToMath.
CHANGELOG.md Changelog updated to explain the new server side rendering behavior.

Comment thread layouts/_markup/render-codeblock-chem.html Outdated
@deining deining force-pushed the server-side-latex branch 4 times, most recently from baa3628 to 20e2b62 Compare June 1, 2025 21:20
Copy link
Copy Markdown
Collaborator

@chalin chalin left a comment

Choose a reason for hiding this comment

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

Great news about the simplification! Thanks.

Could you update the PR (including the title) to say that this is build-time rendering, not server-side.

In terms of code style for this repo, please favor tail-end whitespace globing using -}} and drop the {{- when it is unnecessary -- which is most of the time. Thanks.

I'll take a closer review as soon as I can.

@deining deining changed the title KaTeX: drop js script files, use server side rendering instead KaTeX: drop js script files, use build-time rendering instead Jun 2, 2025
@deining deining force-pushed the server-side-latex branch 2 times, most recently from 7d947c2 to 4d21a43 Compare June 2, 2025 08:03
@deining
Copy link
Copy Markdown
Contributor Author

deining commented Jun 2, 2025

Great news about the simplification! Thanks.

You are welcome!

Could you update the PR (including the title) to say that this is build-time rendering, not server-side.

Done.

In terms of code style for this repo, please favor tail-end whitespace globing using -}} and drop the {{- when it is unnecessary -- which is most of the time. Thanks.

Changed as requested.

I'll take a closer review as soon as I can.

Looking forward receiving your review soon!

@deining deining requested review from chalin and removed request for geriom June 2, 2025 08:09
Comment thread layouts/_partials/scripts.html Outdated
Comment thread layouts/_partials/scripts/katex.html
Comment thread layouts/_partials/scripts/katex.html
Comment thread userguide/content/en/docs/adding-content/diagrams-and-formulae/index.md Outdated
Comment thread layouts/_markup/render-passthrough.html
@deining deining marked this pull request as draft June 5, 2025 14:31
@deining deining force-pushed the server-side-latex branch 3 times, most recently from 4bfb912 to e1cbac5 Compare June 6, 2025 13:16
@deining deining marked this pull request as ready for review June 6, 2025 13:18
@deining
Copy link
Copy Markdown
Contributor Author

deining commented Jun 6, 2025

Thanks for your thorough review, all changes are incorporated, checkers are green.
While working on the review, I realized that the KaTex stylesheet helds several references to KateX font files. Since we are storing the stylesheet locally now, all these links were broken. This is corrected with this PR now, I'm downloading not only the css file but also the font files at build time now.
I realized that this defect is present in recently released version 12.0 too. I think this defect should be fixed there. We can either backport my changes into v12.0 or we make a new release v12.1 which helds my solution submitted with this PR. Sorry for the inconvenience.
@chalin: WDYT?

@deining deining requested a review from chalin June 6, 2025 13:31
@deining deining force-pushed the server-side-latex branch from e1cbac5 to 606aa26 Compare June 8, 2025 06:57
@chalin
Copy link
Copy Markdown
Collaborator

chalin commented Jun 10, 2025

Thanks for your thorough review, all changes are incorporated, checkers are green.

Great!

Will get back to you as soon as I can for the next round of review.

@wlbksy
Copy link
Copy Markdown
Contributor

wlbksy commented Jul 21, 2025

Marvelous

@chalin
Copy link
Copy Markdown
Collaborator

chalin commented Nov 22, 2025

We can either backport my changes into v12.0 or we make a new release v12.1

We'll be putting out a new release (0.13.0) soon.

Copy link
Copy Markdown
Collaborator

@chalin chalin left a comment

Choose a reason for hiding this comment

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

Rebased. Overall LGTM

@chalin chalin merged commit 5333387 into google:main Nov 22, 2025
11 checks passed
@chalin chalin added this to the 25Q4 milestone Nov 22, 2025
@deining deining deleted the server-side-latex branch November 24, 2025 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhancement: build-time rendering of math equations

4 participants