Case study: the KaTeX fix that updated six screenshots and still shipped a bug

· Nathan Broadbent

KaTeX renders maths on the web. It's fast and it's everywhere: the katex package had about 45.7 million npm downloads in the week to 2 December 2026. And it already does visual testing. Its screenshotter renders 125 test cases in Chrome, Firefox and Safari and compares each with a checked-in PNG.

The bug

On 22 February 2026, ef51f18 ("fix: \*frac sizing") changed how \dfrac, \tfrac and \cfrac set their size. It was a real fix, and it came with new unit tests and six updated screenshot baselines (FractionTest and Raisebox, in all three browsers). It was released the same day as v0.16.31.

It also stopped font commands from reaching into those fractions. Write \mathbf{\dfrac{\partial f}{\partial x}} and the fraction comes out in plain math italic instead of bold. The same goes for \mathsf, \mathrm and \boldsymbol. Plain \frac was unaffected, which makes it easy to miss: \mathsf{\frac{ABC}{xyz}} was still sans-serif, and \mathsf{\dfrac{ABC}{xyz}} right next to it wasn't.

This is ordinary notation: bold vectors and matrices, sans-serif units, an upright "d" in d/dt. It was reported on 13 May as present since v0.16.31 and still present in v0.16.45. The fix, e9ee046 ("fix: preserve math font in some styling commands"), shipped in v0.16.46 that day. That's 15 releases and almost 12 weeks.

Why the existing screenshots didn't catch it

The commit's author did look at screenshots: six of them changed, and the new versions were checked in with the fix. But none of the 125 test cases puts a font command around \dfrac, \tfrac or \cfrac. FractionTest has every kind of fraction, all in the default font. The screenshots that existed were right; nothing in them could show this bug.

The replay

Our fork (visualcihq/KaTeX) has one page of ten formulas, written the way people write them:

  • five with a font command around a fraction (a bold Jacobian entry, sans-serif units, a roman d/dt, a bold ½mv² and a bold continued fraction), plus the reported example;
  • four without (the quadratic formula, Bayes' theorem, nested \tfracs and a binomial sum) as a control.

A GitHub Actions job builds KaTeX from the commit, renders the page in Chromium and sends the screenshot to VisualCI. We pushed ef51f18's parent as a baseline and opened a pull request with ef51f18 on top.

VisualCI's build for that pull request, build #2, marked seven regions, all in the font-command rows. The Jacobian, the units, the d/dt and the inner fractions of the continued fraction have all gone back to math italic, and the ½ in ½mv² is no longer bold. In the reported example, the \dfracs lost their font and the \fracs kept theirs. The four control formulas didn't change by a pixel. We rejected the build.

Before ef51f18: the font-command rows in bold, sans-serif and roman

With ef51f18: the fractions inside those font commands back in math italic

The seven regions VisualCI marked on build #2

What it takes

One HTML page, a 20-line Playwright script and the KaTeX build the project already runs. The job took 79 seconds on GitHub's free runners. KaTeX's screenshot tests check that its rendering matches TeX, case by case. A page of formulas as people really write them, compared on every pull request, checks something different: that a change made for one case leaves everyone else's maths alone.

Try it

Screenshots · GitHub Actions