Skip to content

Embed environ.sty and trimspaces.sty: an abstract was losing its first LETTER - #482

Closed
tannevaled wants to merge 1 commit into
mainfrom
feat/embed-environ
Closed

tannevaled wants to merge 1 commit into
mainfrom
feat/embed-environ

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

acmart.cls:284 does \RequirePackage{environ} and builds five of its environments on \Collect@Body:

acmart.cls environment
:1661 abstract
:457 translatedabstract
:959 sidebar
:963 marginfigure
:974 margintable

Nine corpus papers bundle the real acmart.cls, so they run the class rather than this engine's acmart emulation, and for all nine \Collect@Body was undefined: 2301.08336, 2304.01951, 2304.11274, 2311.00921, 2311.07602, 2404.09749, 2405.20319, 2407.13726, 2407.15192.

⛔ The cost was one letter

\renewenvironment{abstract}{\Collect@Body\@saveabstract}{}

With \Collect@Body skipped, the \@saveabstract right after it grabbed the first token of the abstract as its own argument and discarded it. On 2311.00921:

ours, before

tructured dense matrices result from boundary integral problems in electrostatics …

reference

Structured dense matrices result from boundary integral problems in electrostatics …
Structured
before 0
after 1
reference 1

⭐ One character is exactly the size of defect Σ cannot see, and the channel census reported it as one undefined command — which reads as costing nothing.

No Go needed, and nothing new broke

\Collect@Body is 60 lines of \@envbody token-register work. Embedding the pair introduced no new undefined command on any paper — checked by diffing the entire -report-skipped list before and after: \Collect@Body left, nothing arrived.

Provenance: the bundle that built the references

Both files come from the tectonic bundle cache, bundle 6ffe055852f8faf66c0acbe1a7fb27f87b869a90bad1204f3bf4d9683f597c7c — the same files tectonic read when it produced refpdf/.

⛔ Not from a corpus paper's own directory, and here is the check that says why. 2606.19617 bundles both; its environ.sty is byte-identical to the bundle's and its trimspaces.sty is not — the paper's copy is missing a four-line filecontents header. Same version, same macros, different bytes. A .sty shipped inside a paper is whatever that author happened to have.

⛔ Named and deliberately not fixed: \trim@spaces and the leading space

\edef\x{\trim@spaces{ PADDED }}
result
tectonic [PADDED]
engine [ PADDED]

And the cause is not the obvious one. Every piece of the \romannumeral-\q` trick was checked against tectonic and they agree:

  • \romannumeral of a negative number expands to nothing
  • \number-\qis-113`
  • the optional space after a scanned number is skipped
  • a macro is expanded while the scanner looks for further digits
  • an expansion beginning with a space gives A[ Z] on both

The remaining suspects are the catcode-3 Q the package installs as its delimiter, and \newcommand's grab of an argument that begins with a space. acmart's abstract does not need it — that path is fixed and matches the reference — so it is left as its own change, written down in the test rather than asserted there, so the test stays green and the finding stays visible.

Testing

go test -count=1 ./... green. Break check built from HEAD^ with git archive and the new tests dropped in: both fail there, on \Collect@Body and \trim@spaces being undefined.

A/B measurement follows in a comment.

🤖 Generated with Claude Code

…t LETTER

acmart.cls:284 does \RequirePackage{environ} and builds five of its environments on
\Collect@Body — abstract (:1661), translatedabstract (:457), sidebar (:959),
marginfigure (:963), margintable (:974). NINE corpus papers bundle the real
acmart.cls, so they run the class rather than this engine's acmart emulation, and for
all nine \Collect@Body was undefined: 2301.08336, 2304.01951, 2304.11274, 2311.00921,
2311.07602, 2404.09749, 2405.20319, 2407.13726, 2407.15192.

⛔ The cost was not a missing environment. With \Collect@Body skipped, the
\@saveabstract right after it grabbed the FIRST TOKEN of the abstract as its own
argument and discarded it. On 2311.00921 the abstract began

    tructured dense matrices result from boundary integral problems in …

where the reference reads "Structured". Measured: "Structured" 0 -> 1, against the
reference's 1. ⭐ One character is exactly the size of defect that Σ cannot see and
that the channel census reports as one undefined command — which reads as costing
nothing at all.

Neither file needed a line of Go. \Collect@Body is 60 lines of \@envbody token-register
work, and embedding the pair introduced NO new undefined command on any paper (checked
by diffing the whole -report-skipped list before and after: \Collect@Body left, nothing
arrived).

Provenance: both taken from the tectonic bundle cache, bundle
6ffe055852f8faf66c0acbe1a7fb27f87b869a90bad1204f3bf4d9683f597c7c — the same files
tectonic read when it built refpdf/.

⛔ NOT from a corpus paper's directory, and the check that says why. 2606.19617 bundles
both; its environ.sty is byte-identical to the bundle's and its trimspaces.sty is NOT
(the paper's copy is missing a four-line filecontents header). Same version, same
macros, different bytes. A .sty shipped inside a paper is whatever that author had.

⛔ Named and not fixed: \trim@spaces does not trim the LEADING space.

    \edef\x{\trim@spaces{ PADDED }}   tectonic "[PADDED]"   engine "[ PADDED]"

and the cause is not the obvious one. Every piece of the \romannumeral-`\q trick was
checked against tectonic and AGREES: \romannumeral of a negative number expands to
nothing, \number-`\q is -113, the optional space after a scanned number is skipped, a
macro is expanded while the scanner looks for further digits, and an expansion
beginning with a space gives "A[ Z]" on both. The remaining suspects are the catcode-3
`Q` the package sets as its delimiter and \newcommand's grab of an argument that starts
with a space. acmart's abstract does not need it — that path is fixed and matches the
reference — so it is left as its own change, written down in the test rather than
asserted there.

Co-Authored-By: Claude Opus 5 <[email protected]>
@tannevaled
tannevaled marked this pull request as draft September 27, 2026 16:54
@tannevaled

Copy link
Copy Markdown
Contributor Author

⛔ NOT mergeable: this unmasks a larger loss. Moved to draft.

The one-letter fix is real and stands — Structured goes 0 → 1 on 2311.00921, matching the reference. But defining \Collect@Body puts acmart on a path it could not reach before, and four of the nine papers lose a thousand to two thousand words on it.

paper page 1 words whole document
2301.08336 585 → 624 11323 → 11324
2304.01951 13 → 12 11732 → 9553 (−2179)
2304.11274 150 → 0 7466 → 6325 (−1141)
2311.00921 188 → 24 7126 → 7127
2311.07602 511 → 510 14315 → 14314
2404.09749 143 → 16 6815 → 5860 (−955)
2405.20319 71 → 7 11215 → 9341 (−1874)
2407.13726 320 → 342 12234 → 12233
2407.15192 170 → 21 4462 → 4478

⛔ And Σ went DOWN

control treatment
Σ page error 330 329
glyphs 7 696 161 7 697 031 (+870)

Σ improved by one and the glyph total rose by 870 while four papers each lost over a thousand words. 2304.11274 went from 13 pages to 10 against a reference of 12 — it moved one page away while shedding 1141 words, and 2304.01951 went 14 → 11 against 10, which scores as a gain of three. Nothing in the channel census moved either: the full -report-skipped diff on 2304.11274 shows only \Collect@Body leaving and nothing arriving. The loss is entirely silent.

What is actually happening

Page 1 becomes blank on 2304.11274 — 0 words where the reference has 600 — and pages 7 and 10 come out at 1358 and 1251 words where the reference holds ~800 and ~520. Content is being overlaid rather than paginated, so pdftotext reads it once and the document ends three pages short.

The abstract itself is intact (151 words, geological/storage/long-term unchanged), and every \section heading is present in both renders. The mechanism is downstream of the collection: acmart stores the abstract and emits it separately —

\long\def\@saveabstract#1{… \long\gdef\@abstract{#1}}      % acmart.cls:1662
\def\@mkabstract{… \ignorespaces\@abstract\par …}          % acmart.cls:2801

— and \@mkabstract runs \phantomsection, \addcontentsline{toc} and \section*{\abstractname} inside the title block. That is the region to look at next.

What was ruled out

  • \Collect@Body itself is sound. Flat, nested (itemize inside the collected body) and two-in-a-row all collect correctly in the engine: [AAA middle ZZZ], [AAA • ITEM ZZZ], [AAA]TUSSEN[ZZZ].
  • trimspaces does not corrupt Q. It sets \catcode\Q=3and restores it;AVANT QUANTUM Q APRESrenders identically with and without\usepackage{environ}`.
  • No new undefined command anywhere. Diffing the entire -report-skipped output before and after: \Collect@Body left, nothing arrived.
  • No section and no bibliography section vanished — 22 → 19 bibliography entries is part of the same overlay, not a separate defect.

The embedded files, their provenance and the \trim@spaces note are all worth keeping, so this stays open as a draft rather than being closed.

🤖 Generated with Claude Code

tannevaled added a commit that referenced this pull request Sep 27, 2026
\twocolumn[span] appended a column region at the current end of the main vertical
list even when the region it thereby CLOSED held nothing that puts ink on a page.
Regions are page-aligned, so that empty region is a page.

⛔ All nine corpus papers that bundle the real acmart.cls lost page 1 to this. acmart's
\maketitle is \twocolumn[\box\mktitle@bx] (acmart.cls:2319-2343, once per format), and
at that moment the list held exactly three nodes: two pageStyleNode and a zero-width
glueNode. Reproduced in seven lines with the bundled class —

    \documentclass[sigplan,nonacm]{acmart}
    \begin{document}
    \title{TITREICI}
    \author{Alice Un}
    \affiliation{\institution{INSTITUTUN}\country{PAYSUN}}
    \maketitle
    \section{Intro}CORPSICI
    \end{document}

— gave 2 pages with a BLANK page 1 and the title on page 2, where [acmsmall] (one
column, no \twocolumn) was correct. With this change it is one page with the title on
it. TeX does not ship an empty page either, so this is the faithful behaviour and not
a special case: the spanning region now starts where the contentless material starts
and carries those marks along.

mvlHasContent lists the INVISIBLE node types explicitly and treats everything else as
content. A list of what does not count would inherit its own blind spot — a node type
added later would be silently invisible, and a page quietly dropped is a failure
nobody would go looking for. This way an unknown node keeps its page.

⛔ On its own this changes no corpus paper, and the commit does not pretend otherwise.
Those nine papers leak their abstract out BEFORE \maketitle (acmart stores it through
\Collect@Body, which needs environ.sty — see #482), so their list does hold ink at the
switch and this branch is not taken. It is the companion of that change: measured with
both, 2304.01951 lands EXACTLY on its reference's 10 pages with 812 words on page 1
against the reference's 827, and 2404.09749 reaches 952 against 951. #482 is still a
draft for an unrelated loss.

⛔ The test asserts the REGION LIST, not the page. A first version asserted that the
title is on page 1 and it PASSED against the unfixed engine: the witness cannot load
acmart.cls, and without acmart's geometry the pager happens to fit the empty region and
the span onto one page anyway. Two regions are the defect; a blank page is what they
cost a real document. The second test holds the other direction — material that does
put ink on the page must keep a region of its own — so the fix cannot over-reach.

Co-authored-by: Claude Opus 5 <[email protected]>
@tannevaled

Copy link
Copy Markdown
Contributor Author

Six hypotheses falsified, and where the search now stands

#484 has landed and is this PR's companion — with both, 2304.01951 reaches exactly its reference's 10 pages with 812 words on page 1 against the reference's 827, and 2404.09749 reaches 952 against 951. The word loss is a separate defect and is what still blocks this. Recording what it is not, so the next attempt does not re-walk this.

hypothesis how it was killed
acmart's \@mkabstract is the cause \AtBeginDocument{\def\@mkabstract{}} on the real paper: page 1 still blank, total only −132 words (the abstract)
\Collect@Body mis-collects flat, nested (itemize inside the body) and two-in-a-row all collect correctly: [AAA middle ZZZ], [AAA • ITEM ZZZ], [AAA]TUSSEN[ZZZ]. The real abstract of 2304.11274, 32 lines of comments and text, collects correctly in a minimal witness with APRESAPRES intact
trimspaces corrupts Q it sets \catcode\Q=3and restores it;AVANT QUANTUM Q APRESrenders identically with and without\usepackage{environ}`
a group is left open the engine's open-group channel reports nothing, before or after
acmart's \ClassError eats its \fi it does — \ClassError{\@classname}{…}\fi passes \fi as the third argument — but the error never fires: no Class … Error in the output
the span is taller than the page startRevtexBody guards that and startTwoColumn does not, so it looked promising. Instrumented: the tallest span is 21 879 540 against a vsize of 40 763 392 — 54% of the page. None exceeds it

What is established

Turning the collection off restores everything. \AtBeginDocument{\renewenvironment{abstract}{}{}} on 2304.11274 gives 150 words on page 1, 7465 words, 13 pages — identical to main. So the collection is the trigger, whatever the mechanism.

It is not uniform across the nine, and not by format either:

paper format span words
2301.08336 manuscript none +1
2311.07602 acmsmall none −1
2407.13726 acmsmall none −1
2311.00921 sigconf 13 565 681 +1
2407.15192 sigconf — +3
2304.11274 sigplan 12 608 210 −1139
2304.01951 sigconf 13 490 979 −2179
2404.09749 sigconf 9 040 495 −972
2405.20319 acmtog 21 879 540 −1874

⛔ 2311.00921 has a taller span than 2304.11274 and loses nothing, so height is not the discriminator and neither is the format. Every loser has a span; not every paper with a span loses.

The shape of the loss on 2304.11274, from wordpair.py:

p1   before=150    after=0      ref=600   ← PAGE VIDE
p7   before=459    after=1358   ref=814   ← DÉBORDE
p10  before=566    after=1251   ref=520   ← DÉBORDE
p11  before=305    after=0      ref=497   ← PAGE VIDE

The per-page counts sum to the total, so nothing is double-read: pages 7 and 10 genuinely carry ~1.7 pages of material and ~1141 words are never drawn. The first blank page is #484's defect and is now fixed; the overfull pages and the missing words are not.

Next place to look, given all of the above: the pager, not the collection. Something about a region whose span is placed makes findPageBreak overshoot on later pages of the same region. 2311.00921 vs 2304.11274 is the pair to bisect — same format family, similar span height, opposite outcome.

The embedded files, their provenance, the first-letter fix and the \trim@spaces note stay as they are. This remains a draft.

🤖 Generated with Claude Code

@tannevaled

Copy link
Copy Markdown
Contributor Author

Judged against the REFERENCE, not against our own previous build

The earlier numbers here compared the treatment to main. That answers "did content move" but not "is it right". Counting distinctive tokens (≥5 characters, not purely numeric) that the reference holds and we do not:

paper missing extra words
2304.11274 main 196 142 7464
with environ + #484 921 326 6325
reference — — 7756
2304.01951 main 1193 2493 11745
with environ + #484 2111 2200 9541
reference — — 10930

Missing content against the reference goes 196 → 921 and 1193 → 2111. The "extra" column does improve on 2304.01951 (2493 → 2200) — part of what main renders there is duplicated material that the collection removes, which is why the page count lands exactly on 10 — but that does not pay for the content that goes with it.

So the regression is real by the right judge, and this stays a draft. Two further discriminators ruled out since the last comment:

  • not the spanning bands: 2304.01951 loses 2179 words with zero figure*/table*, while 2311.00921 has four figure* and two table* and loses nothing.
  • not the format: both are sigconf.

🤖 Generated with Claude Code

@tannevaled

Copy link
Copy Markdown
Contributor Author

The A/B this PR promised, ten days late — and it says do not merge as it stands.

Rebased onto current main so there is one variable, both binaries from the same base, whole 154-paper corpus:

base with this PR
Σ page deviation 343 342
exact pagination 36 36
papers producing no PDF 0 0
papers whose pagination moves — 5, all downward

That looks neutral-to-good. The character counts do not:

paper reference base with this PR
2304.01951 57079 68423 (120%) 55995 (98%) closer — the base was duplicating
2404.09749 36563 40746 (111%) 34693 (95%) closer
2304.11274 42944 42675 (99%) 35414 (82%) further — content lost
2405.20319 69627 66232 (95%) 55874 (80%) further — content lost

So the change does two things at once. Where the base duplicated an abstract it now sets it once, which is the fix this PR is for — 2304.01951 has two \begin{abstract} and lands on the reference's page count exactly (15 → 10, reference 10). But on two other papers it drops ~7k and ~10k characters that were on the page before.

All four bundle the real acmart.cls and none ships environ.sty, so all four take the same path; the papers that lose and the papers that gain are not told apart by that. I have not isolated what does tell them apart, and I am not going to name a cause I have not measured.

The shape to suspect first is the one this repo has been bitten by before: \Collect@Body stores the body in a macro, and something downstream has to emit it — storing a body is not typesetting it. A body collected and never emitted would look exactly like this: pagination improves (the duplicate is gone, and so is the original) while the text count falls.

Leaving this open and unmerged. The next step is a witness on 2304.11274 or 2405.20319 that shows which environment's body goes missing — not another corpus sweep.

🤖 Generated with Claude Code

tannevaled added a commit that referenced this pull request Oct 17, 2026
…ad found (#618)

This reverts d9d2d2a (#616). The defect it fixes is real; what it costs is
larger, and I merged it on a measurement that could not see the cost.

WHAT #616 CLAIMED, AND WHY THE EVIDENCE WAS WRONG. It read the ink — the count
of glyph paths drawn — and found it RISING on the two papers whose page count
fell most: +959 and +1076 glyphs. I took that as proof that no content was lost
and that the shorter page counts were denser typesetting.

Ink cannot tell "drawn in different places" from "drawn on top of itself".
`measure pagedens` can, and on 2304.11274 against its reference it says:

    page   ours              reference        interline step
       1   742 / 65x2        630 / 51x2       9.31 / 11.96
       3   345 / 27x2        716 / 91x2      11.96 / 11.54
       4   220 / 18x2        648 / 48x2      11.96 / 11.96
       5   175 / 13x2        867 / 56x2      11.96 / 11.96
       6  1004 / 75x2        603 / 42x2       9.77 / 11.96

Three pages nearly empty, three overfull with the interline step CRUSHED to
9.31 and 9.77pt where every other page of the same document is at 11.96. That
is content overlaid, not paginated — exactly what #482 reported on 2026-09-27
and the reason it has stayed a draft for three weeks.

MEASURED BOTH WAYS, same binary base, same fonts:

    paper        with #616        reverted          reference
    2304.11274   10p /  6123w     13p /  7466w      12p / ~7756w
    2405.20319   10p /  9217w     15p / 11116w      14p
    2404.09749    6p /  5873w     10p /  6768w       8p
    2304.01951   10p /  9555w     15p / 11595w      10p / 10930w

Against the reference's word count, 2304.11274 goes from 79% to 96%.

ISOLATED, and reproducible in one line. Neutralising the collection restores
everything:

    \makeatletter\renewenvironment{abstract}{}{}\makeatother
    → 13 pages, 7406 words   (with the collection: 10 pages, 6123 words)

So the collection is the trigger and the mechanism is DOWNSTREAM of it: acmart
stores the abstract in \@abstract and emits it from \@mkabstract inside the
title block.

WHAT THIS COSTS TO REVERT, said plainly: 2304.01951 goes back to 15 pages
against a reference of 10. That paper has TWO \begin{abstract}, and the
collection removed the duplicate, which is how it landed exactly on 10. It also
had 11595 words against the reference's 10930 — 106%, i.e. too MUCH content —
so what the revert restores there is a duplication. Three papers keep their
content; one keeps a duplicate. That is the better trade, and it is the one #482
reached independently.

Nine hypotheses are now falsified between #482 and this session, including three
of mine today: teaserfigure (acmart.cls:2065 is a SIXTH \Collect@Body
environment #482 had not listed, and it correlates with the two biggest losers —
neutralising it changes 6123 words to 6065, so it is not the cause), the
re-splice-as-source reading, and the double group close. All of it goes back
into #615.

Co-authored-by: Claude Opus 5 <[email protected]>
@tannevaled

Copy link
Copy Markdown
Contributor Author

Closing: the defect this draft found is fixed, by a different route, in #639.

This PR embedded environ.sty and trimspaces.sty so the real \Collect@Body would
run. It stayed a draft for three weeks because it unmasked a larger loss — the one
reported in its comments — and that was the right call: #616 later shipped the same
capability without reading those comments, and had to be reverted (#618).

What the comments here were seeing has a name now. \twocolumn writes the column
measure \global (latex.ltx:15108-15115); we wrote it locally, and acmart calls
\twocolumn from inside \maketitle's \begingroup…\endgroup after setting
\hsize=\textwidth itself. The \endgroup gave the full width back, so both columns
were line-broken at 504pt and drawn one over the other. Nothing in \Collect@Body was
wrong; it was simply the only way to reach the other defect.

#639 implements \Collect@Body natively — the engine's own idiom, using
collectEnvBody and \@currenvir, rather than embedding two more .sty files — and
fixes the global measure in the same pull request, because neither is reachable
without the other.

The three weeks this spent as a draft are the reason the second attempt had somewhere
to start — and the reason #618 could name what it was reverting.

@tannevaled tannevaled closed this Oct 22, 2026
@tannevaled
tannevaled deleted the feat/embed-environ branch October 22, 2026 06:59
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.

1 participant