Skip to content

fix: remove extra \jot space at bottom of align/gather/etc.#4184

Merged
edemaine merged 3 commits intomainfrom
jot-between
Mar 27, 2026
Merged

fix: remove extra \jot space at bottom of align/gather/etc.#4184
edemaine merged 3 commits intomainfrom
jot-between

Conversation

@edemaine
Copy link
Copy Markdown
Member

@edemaine edemaine commented Mar 27, 2026

What is the previous behavior before this PR?
aligned-like environments add \jot space after every row, thanks to old me in #725.

What is the new behavior after this PR?
aligned-like environments add \jot space between rows — no space after the last row — as past me investigated in #3142 (comment)

This is a recreation/rebasing of #4050, with extra comments and tests, as I investigated #2911 and it turned out to be this issue. I've marked @mvr as a coauthor on my commit.

Fixes #3142

Fixes #2911 which now looks like
image

Screenshot diffs show improved centering:

Equation-chrome-diff Gathered-chrome-diff

Fixes #3142
Fixes #2911

Co-authored-by: mvr <mitchell.v.riley@gmail.com>
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 27, 2026

Greptile Summary

This PR fixes a long-standing visual bug (#3142, #2911) where aligned, gathered, align, alignat, and similar AMS environments added an extra \jot (3 pt) of space after the last row, instead of only between rows. The fix is a one-line condition change in the HTML builder loop in src/environments/array.ts, and is accompanied by two targeted unit tests.

Key changes:

  • src/environments/array.ts: The addJot depth increment now only fires for rows where r < group.body.length - 1, i.e. all rows except the last. This matches the LaTeX \openup semantics which add space between lines.
  • test/katex-spec.ts: Two new tests verify the single-row case (with and without a trailing \\) and the two-row case against an equivalent matrix* baseline.

Notes:

  • The MathML builder (line 593) is unaffected — MathML's rowspacing attribute already applies only between rows, so it was already correct.
  • The existing screenshotter images for Align, Aligned, Alignedat, Gather, and Gathered will diverge from the new output; those baseline screenshots will need to be regenerated before screenshotter CI passes.

Confidence Score: 5/5

Safe to merge — the fix is minimal, correct, and well-tested; no logic regressions identified.

The core change is a single guard condition that is trivially correct for all row counts (0 jot on a single row, jot only between rows for N > 1). Both new tests validate the expected semantics. The only remaining items are a minor test-comment suggestion (P2) and the known need to regenerate screenshotter baselines, neither of which blocks correctness.

Screenshotter baseline images for Align, Aligned, Alignedat, Gather, and Gathered need regeneration after this change.

Important Files Changed

Filename Overview
src/environments/array.ts Minimal one-condition fix: adds r < group.body.length - 1 guard so \jot is only appended to rows that have a following row, correctly removing the extra spacing at the bottom of aligned/gather/etc.
test/katex-spec.ts Two new unit tests covering single-row (with and without trailing \) and two-row cases; tests compare height/depth against equivalent matrix* baselines.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["htmlBuilder loop\nfor r = 0 to body.length-1"] --> B["compute row height & depth\n(arstrut baseline)"]
    B --> C{"rowGap[r] set?"}
    C -- yes --> D["gap = calculateSize(rowGap)\nif gap > 0: depth = max(depth, arstrutDepth+gap)"]
    C -- no --> E["gap = 0"]
    D --> F
    E --> F{"group.addJot AND\nr < body.length - 1?"}
    F -- "yes (between rows)" --> G["depth += jot  ✅ space added"]
    F -- "no (last row)" --> H["depth unchanged  ✅ no extra space"]
    G --> I["totalHeight += height + depth + gap"]
    H --> I
Loading

Reviews (1): Last reviewed commit: "fix: remove extra \jot space at bottom o..." | Re-trigger Greptile

edemaine and others added 2 commits March 27, 2026 08:22
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@grigoriy-reshetniak
Copy link
Copy Markdown
Collaborator

Looks great!

@edemaine edemaine merged commit 3870ee9 into main Mar 27, 2026
10 of 11 checks passed
@edemaine edemaine deleted the jot-between branch March 27, 2026 13:49
@edemaine
Copy link
Copy Markdown
Member Author

🎉 This PR is included in version 0.16.44 🎉

The release is available on:

Your semantic-release bot 📦🚀

alexander-turner pushed a commit to alexander-turner/KaTeX that referenced this pull request Mar 27, 2026
## [0.16.44](KaTeX/KaTeX@v0.16.43...v0.16.44) (2026-03-27)

### Bug Fixes

* remove extra \jot space at bottom of align/gather/etc. ([KaTeX#4184](KaTeX#4184)) ([3870ee9](KaTeX@3870ee9))
dadezzz pushed a commit to dadezzz/ice-notes that referenced this pull request Mar 31, 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.40` → `0.16.44`](https://renovatebot.com/diffs/npm/katex/0.16.40/0.16.44) | ![age](https://developer.mend.io/api/mc/badges/age/npm/katex/0.16.44?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/katex/0.16.40/0.16.44?slim=true) |

---

### 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. ([#&#8203;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 ([#&#8203;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 ([#&#8203;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 ([#&#8203;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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unwanted vertical space after aligned environment Too much space above \frac bars

2 participants