Skip to content

fix(typst): deduplicate cell-level line entries in hlines/vlines - #665

Merged
vincentarelbundock merged 1 commit into
vincentarelbundock:mainfrom
EinMaulwurf:fix/typst-hlines-dedup
Jul 11, 2026
Merged

fix(typst): deduplicate cell-level line entries in hlines/vlines#665
vincentarelbundock merged 1 commit into
vincentarelbundock:mainfrom
EinMaulwurf:fix/typst-hlines-dedup

Conversation

@EinMaulwurf

Copy link
Copy Markdown
Contributor

NOTE: This PR and the code changes are entirely "vibe coded" using GLM-5.2.


typst_hlines() and typst_vlines() emitted fragmented chains of table.hline()/table.vline() segments covering the same span whenever @style_lines contained duplicate (i, j, line, color, width) tuples.

These duplicates arise routinely: theme_tinytable() adds style_tt(i = 0, line = "b", ...) and so does the user; the lazy style system records both calls and expands them to identical per-cell entries in @style_lines. typst_split_chunks() then saw phantom breaks in diff(x) != 1 and produced one chunk per duplicated j value.

Minimal repro before the fix:

tt(mtcars[1:5, 1:5]) |>
  style_tt(i = 0, line = "b", line_color = "black", line_width = 0.05) |>
  save_tt("typst")

emitted 6 fragmented table.hline(y: 1, ...) segments covering sub-ranges of [0, 5). After the fix, it emits a single
table.hline(y: 1, start: 0, end: 5, ...).

Also visible in test-typst.R's typst-issue592.typ snapshot, where the x:0 vline was previously split into 5 overlapping fragments (0-1, 0-2, 1-7, 6-12, 11-16). The snapshot is regenerated to reflect the correct single-segment output.

Fix: deduplicate identical rows of k inside the lapply() bodies of typst_hlines() and typst_vlines(), after the split() grouping. Other backends (html, latex/tabularray, markdown/grid) are unaffected — they either aggregate per cell (html) or build ranges that absorb duplicates (tabularray).

Tests:

  • Regenerate inst/tinytest/_tinysnapshot/typst-issue592.typ
  • Add regression tests in inst/tinytest/test-bugfix.R covering both "user re-declares theme line" and "user adds the same line twice"

typst_hlines() and typst_vlines() emitted fragmented chains of
table.hline()/table.vline() segments covering the same span whenever
@style_lines contained duplicate (i, j, line, color, width) tuples.

These duplicates arise routinely: theme_tinytable() adds
style_tt(i = 0, line = "b", ...) and so does the user; the lazy style
system records both calls and expands them to identical per-cell entries
in @style_lines. typst_split_chunks() then saw phantom breaks in
diff(x) != 1 and produced one chunk per duplicated j value.

Minimal repro before the fix:

    tt(mtcars[1:5, 1:5]) |>
      style_tt(i = 0, line = "b", line_color = "black", line_width = 0.05) |>
      save_tt("typst")

emitted 6 fragmented table.hline(y: 1, ...) segments covering sub-ranges
of [0, 5). After the fix, it emits a single
table.hline(y: 1, start: 0, end: 5, ...).

Also visible in test-typst.R's typst-issue592.typ snapshot, where the
x:0 vline was previously split into 5 overlapping fragments
(0-1, 0-2, 1-7, 6-12, 11-16). The snapshot is regenerated to reflect
the correct single-segment output.

Fix: deduplicate identical rows of k inside the lapply() bodies of
typst_hlines() and typst_vlines(), after the split() grouping. Other
backends (html, latex/tabularray, markdown/grid) are unaffected —
they either aggregate per cell (html) or build ranges that absorb
duplicates (tabularray).

Tests:
- Regenerate inst/tinytest/_tinysnapshot/typst-issue592.typ
- Add regression tests in inst/tinytest/test-bugfix.R covering both
  "user re-declares theme line" and "user adds the same line twice"
@vincentarelbundock

Copy link
Copy Markdown
Owner

Does this maintain visible "gutters" between lines under spanning Colum headers?

@EinMaulwurf

EinMaulwurf commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Yes it does:

Bildschirmfoto 2026-07-08 um 19 09 17
x <- tt(mtcars[1:10, 1:8]) |>
  group_tt(j = list("Engine" = 1:4, "Trans" = 5:8)) |>
  group_tt(j = list("Cars" = 1:8))
cat(save_tt(x, "typst"))

@vincentarelbundock
vincentarelbundock merged commit c6702c6 into vincentarelbundock:main Jul 11, 2026
2 of 3 checks passed
@vincentarelbundock

Copy link
Copy Markdown
Owner

thanks, got a chance to check it out and it's a nice improvement. merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants