KaTeX / KaTeX/KaTeX

Inconsistent bounding box at different font sizes

Open
#3,965 0 comments 1 reaction 0 assignees View on GitHub
bug
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:
![image](https://github.com/KaTeX/KaTeX/assets/26196187/a5660b09-ea37-4e91-b7ac-8053a75bc236)
![image](https://github.com/KaTeX/KaTeX/assets/26196187/6d851eb8-9dfd-4181-852a-d394382b4a54)

In 100% and 80% zoom, the `\partial`'s are affected:
![image](https://github.com/KaTeX/KaTeX/assets/26196187/edec476e-6ac1-443a-8800-1330e757b906)
![image](https://github.com/KaTeX/KaTeX/assets/26196187/4647ed2f-e3d2-4757-b157-73d5ccc93f90)

In 90% zoom, the bottom serifs of the denominators are affected:
![image](https://github.com/KaTeX/KaTeX/assets/26196187/065ba848-d065-4f9b-b1f1-6eccce44d780)

In 75% zoom, both the `\partial`'s and the `\mathcal H`'s are affected:
![image](https://github.com/KaTeX/KaTeX/assets/26196187/6d11e0c4-042b-45e2-b803-60ceebc078ec)

**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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.