fix(css): specify position: relative for .katex#4170
Merged
grigoriy-reshetniak merged 2 commits intoKaTeX:mainfrom Mar 20, 2026
Merged
fix(css): specify position: relative for .katex#4170grigoriy-reshetniak merged 2 commits intoKaTeX:mainfrom
grigoriy-reshetniak merged 2 commits intoKaTeX:mainfrom
Conversation
Contributor
Greptile SummaryThis PR fixes a long-standing CSS layout bug (#2796) where Key changes:
Impact:
Confidence Score: 5/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
subgraph Before["Before (Bug)"]
A1["nearest positioned ancestor\n(position: relative/absolute/fixed)"] -->|".katex-mathml positioned\nrelative to this"| B1[".katex\n(position: static — default)"]
B1 --> C1[".katex-mathml\n(position: absolute)\n⚠️ escapes .katex container"]
B1 --> D1[".katex-html\n(visible math)"]
end
subgraph After["After (Fix)"]
A2["nearest positioned ancestor"] --> B2[".katex\n(position: relative) ✅"]
B2 -->|".katex-mathml now\ncontained here"| C2[".katex-mathml\n(position: absolute)\n✅ correctly clipped inside .katex"]
B2 --> D2[".katex-html\n(visible math)"]
end
Last reviewed commit: "fix(css): specify po..." |
Collaborator
|
I checked #3970 (comment) and haven't seen any issues with |
grigoriy-reshetniak
approved these changes
Mar 20, 2026
Collaborator
|
Thank you! |
Member
|
🎉 This PR is included in version 0.16.40 🎉 The release is available on: Your semantic-release bot 📦🚀 |
alexander-turner
pushed a commit
to alexander-turner/KaTeX
that referenced
this pull request
Mar 20, 2026
## [0.16.40](KaTeX/KaTeX@v0.16.39...v0.16.40) (2026-03-20) ### Bug Fixes * **css:** specify position: relative for .katex ([KaTeX#4170](KaTeX#4170)) ([020f0d8](KaTeX@020f0d8))
dadezzz
pushed a commit
to dadezzz/ice-notes
that referenced
this pull request
Mar 25, 2026
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [katex](https://katex.org) ([source](https://github.com/KaTeX/KaTeX)) | [`0.16.39` → `0.16.40`](https://renovatebot.com/diffs/npm/katex/0.16.39/0.16.40) |  |  | --- ### Release Notes <details> <summary>KaTeX/KaTeX (katex)</summary> ### [`v0.16.40`](https://github.com/KaTeX/KaTeX/blob/HEAD/CHANGELOG.md#01640-2026-03-20) [Compare Source](KaTeX/KaTeX@v0.16.39...v0.16.40) ##### Bug Fixes - **css:** specify position: relative for .katex ([#​4170](KaTeX/KaTeX#4170)) ([020f0d8](KaTeX/KaTeX@020f0d8)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My44Ni4wIiwidXBkYXRlZEluVmVyIjoiNDMuODYuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==--> Co-authored-by: Renovate Bot <renovate@zarantonello.dev> Co-committed-by: Renovate Bot <renovate@zarantonello.dev>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the previous behavior before this PR?
Elements with the
.katex-mathmlclass are positioned much lower than expected.As a result, when there are many KaTeX-rendered elements on a page, unexpected whitespace appears at the bottom of the page.
demo: https://gist.github.com/egawata/fe28a58324c470ed100349e352d22471
The cause is that the
.katex-mathmlclass hasposition: absolute, but its immediate parent.katexdoes not haveposition: relative.This issue appears to be the same as the one reported in #2796.
Also, PR #3859 was intended to fix this, but it seems unable to be merged into the current latest master.
What is the new behavior after this PR?
The
.katex-mathmlelements are correctly positioned within the.katexelements, eliminating the layout displacement.Fixes #2796