fix: use makeEm() consistently to truncate long CSS decimals#4181
Conversation
Greptile SummaryThis PR fixes three locations where numeric values were concatenated directly with Confidence Score: 5/5Safe to merge — all three changes are correct, imports are already present, and no logic is altered beyond decimal truncation. The changes are tiny and mechanical: swap raw string concatenation for an already-imported helper that's used identically everywhere else in the codebase. makeEm already exists in all three files' import lists. The only behavioural delta in delimiter.ts (3→4 dp) is inconsequential because the inputs are always integers divided by 1000, giving at most 3 significant decimal digits. No new risk is introduced. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["Raw number\n(e.g. 0.11764999999...)"] -->|"old: + \"em\""| B["Long CSS string\n0.11764999999999999em"]
A -->|"new: makeEm(n)"| C["makeEm(n)\n+n.toFixed(4) + 'em'"]
C --> D["Clean CSS string\n0.1176em"]
subgraph "Call sites fixed"
E["domTree.ts\nSymbolNode.toMarkup()\nmargin-right: italic"]
F["delimiter.ts\nmakeStackedDelim()\nSVG width / height"]
G["enclose.ts\nmathmlBuilder()\nborder thickness thk"]
end
E --> A
F --> A
G --> A
Reviews (1): Last reviewed commit: "fix: use makeEm() consistently to trunca..." | Re-trigger Greptile |
src/functions/enclose.ts
Outdated
| options.minRuleThickness, // user override | ||
| ); | ||
| node.setAttribute("style", "border: " + thk + "em solid " + | ||
| node.setAttribute("style", "border: " + makeEm(thk) + " solid " + |
|
Could you please also update snapshots? |
Replace direct number + "em" concatenation with makeEm() which applies .toFixed(4) rounding. This avoids outputting values like "1.1764999999999999em" caused by floating-point arithmetic. Fixes KaTeX#897
Update snapshot to reflect the consistent use of makeEm() which rounds to 4 decimal places (e.g. 0.10903em → 0.109em).
Address review feedback: convert string concatenation to template literals in domTree.ts and enclose.ts.
a8da4f8 to
08c8746
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4181 +/- ##
==========================================
+ Coverage 93.15% 93.30% +0.14%
==========================================
Files 91 91
Lines 6795 6810 +15
Branches 1582 1582
==========================================
+ Hits 6330 6354 +24
- Misses 429 454 +25
+ Partials 36 2 -34
... and 13 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
|
Thanks for the review @grigoriy-reshetniak! I've updated the PR:
Let me know if anything else needs changing. |
|
Looks good, thank you! |
|
🎉 This PR is included in version 0.16.43 🎉 The release is available on: Your semantic-release bot 📦🚀 |
## [0.16.43](KaTeX/KaTeX@v0.16.42...v0.16.43) (2026-03-26) ### Bug Fixes * use makeEm() consistently to truncate long CSS decimals ([KaTeX#4181](KaTeX#4181)) ([0967dcc](KaTeX@0967dcc))
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.40` → `0.16.44`](https://renovatebot.com/diffs/npm/katex/0.16.40/0.16.44) |  |  | --- ### Release Notes <details> <summary>KaTeX/KaTeX (katex)</summary> ### [`v0.16.44`](https://github.com/KaTeX/KaTeX/blob/HEAD/CHANGELOG.md#01644-2026-03-27) [Compare Source](KaTeX/KaTeX@v0.16.43...v0.16.44) ##### Bug Fixes - remove extra \jot space at bottom of align/gather/etc. ([#​4184](KaTeX/KaTeX#4184)) ([3870ee9](KaTeX/KaTeX@3870ee9)) ### [`v0.16.43`](https://github.com/KaTeX/KaTeX/blob/HEAD/CHANGELOG.md#01643-2026-03-26) [Compare Source](KaTeX/KaTeX@v0.16.42...v0.16.43) ##### Bug Fixes - use makeEm() consistently to truncate long CSS decimals ([#​4181](KaTeX/KaTeX#4181)) ([0967dcc](KaTeX/KaTeX@0967dcc)) ### [`v0.16.42`](https://github.com/KaTeX/KaTeX/blob/HEAD/CHANGELOG.md#01642-2026-03-24) [Compare Source](KaTeX/KaTeX@v0.16.41...v0.16.42) ##### Features - \underbracket and \overbracket ([#​4147](KaTeX/KaTeX#4147)) ([5be9abb](KaTeX/KaTeX@5be9abb)) ### [`v0.16.41`](https://github.com/KaTeX/KaTeX/blob/HEAD/CHANGELOG.md#01641-2026-03-24) [Compare Source](KaTeX/KaTeX@v0.16.40...v0.16.41) ##### Bug Fixes - \sout in text mode ([#​4173](KaTeX/KaTeX#4173)) ([e748578](KaTeX/KaTeX@e748578)) </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:eyJjcmVhdGVkSW5WZXIiOiI0My44Ni4wIiwidXBkYXRlZEluVmVyIjoiNDMuOTkuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==--> Co-authored-by: Renovate Bot <renovate@zarantonello.dev> Co-committed-by: Renovate Bot <renovate@zarantonello.dev>
Summary
"em"instead of usingmakeEm(), producing unnecessarily long decimals like1.1764999999999999emdomTree.ts:SymbolNode.toMarkup()—this.italic + "em"→makeEm(this.italic)delimiter.ts:makeStackedDelim()—.toFixed(3) + "em"→makeEm()(also normalizes to.toFixed(4)for consistency)functions/enclose.ts:mathmlBuilder—thk + "em"→makeEm(thk)Fixes #897
Test plan
yarn testto verify snapshot tests pass (some may need updating with-u)\fcolorboxto verify CSS values are truncated to 4 decimal places