Inconsistent bounding box at different font sizes
- Dominant language
- TypeScript
- Stars
- 20.4k
- Forks
- 1.3k
- Avg merge
- 14h 37m
- Merged PRs (30d)
- 7
Description
> Before reporting a bug
- [x] Check [common issues](https://katex.org/docs/issues.html).
- [x] Check the bug is reproducible in [the demo](https://katex.org). If not, check KaTeX is up-to-date and installed correctly.
- [x] Search for [existing issues](https://github.com/KaTeX/KaTeX/issues).
**Describe the bug:**
Sometimes, part of the equation is outside the bound, and this is dependent on the font size (zoom ratio). This is not normally noticeable because of the 1em margin.
**Reproduction and screenshots:**
Render this on katex.org:
```tex
\frac{\mathrm d\mathbf q}{\mathrm dt}=\frac{\partial\mathcal H}{\partial\mathbf q},\quad\frac{\mathrm d\mathbf p}{\mathrm dt}=\frac{\partial\mathcal H}{\partial\mathbf p}
```
**In devtools, set `overflow: hidden` for `.katex-display` to make this bug easily spotted.** This way, when part of the equation is outside the bounding box, it is hidden so you can notice. Alternatively, overlay your mouse cursor on the `span.katex-display` element and see whether the blue box is correctly enclosing the whole equation.
In 110% and 50% zoom, everything looks perfect:


In 100% and 80% zoom, the `\partial`'s are affected:


In 90% zoom, the bottom serifs of the denominators are affected:

In 75% zoom, both the `\partial`'s and the `\mathcal H`'s are affected:

**Expected behavior:**
The bounding box should enclose the whole equation.
**Environment (please complete the following information):**
- KaTeX Version: 0.16.10
- Device: Desktop (screen size 15.6", 1920x1080)
- OS: NixOS 24.05 (GNOME, X11, proprietary NVIDIA driver)
- Browser: Brave
- Version: 1.66.118 Chromium: 125.0.6422.147 (Official Build) (64-bit)
**Additional context:**
Reproducible on Firefox though behaviors are not exactly the same for all zoom ratios.
Contributor guide
Research direction
Start by rendering the supplied TeX on katex.org and inspecting the .katex-display bounding box at the reported zoom levels, including with overflow: hidden. Compare the affected glyphs and verify that the bounding box encloses the complete equation consistently across the listed zoom ratios and browsers.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100