Skip to content

a paragraph shape lasts one paragraph: normal_paragraph - #796

Merged
tannevaled merged 1 commit into
mainfrom
normal-paragraph-resets-the-shape
Nov 15, 2026
Merged

tannevaled merged 1 commit into
mainfrom
normal-paragraph-resets-the-shape

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

A paragraph shape lasts exactly one paragraph. This engine kept it for ever — and that only became a defect twenty minutes ago, when \hangindent started working. Refs #792, which stays open. The change that made this load-bearing is the \hangindent PR merged earlier this evening.

tex.web:20756-20761, whole

procedure normal_paragraph;
begin if looseness<>0 then eq_word_define(int_base+looseness_code,0);
if hang_indent<>0 then eq_word_define(dimen_base+hang_indent_code,0);
if hang_after<>1 then eq_word_define(int_base+hang_after_code,1);
if par_shape_ptr<>null then eq_define(par_shape_loc,shape_ref,null);
end;

Called from nine places, vmode+par_end (:21152) among them — so every \par. This engine called it from none.

⛔⛔ The shape of this defect is worth more than the fix

While \hangindent was accept-and-ignore, never resetting it cost nothing, and no test could have noticed. The \hangindent PR made it shape the line breaker, and the same omission immediately began hanging every following paragraph.

A parameter's lifetime only matters once the parameter matters. I found this by asking, after that merge, what the change had just made load-bearing — not by re-reading the code.

Measured before this landed. Two documents identical except for what their FIRST paragraph asks; the comparison is their SECOND, which asks for nothing:

after a hung first paragraph:   "measure that is wrong" / "by a centimetre is wrong"
after a plain first paragraph:  "sure that is wrong by a cen-" / "timetre is wrong on every"

and the three parameters read back unchanged after \par:

\hangindent  1572864 sp   want 0   (:20758)
\hangafter   3            want 1   (:20759)
\looseness   2            want 0   (:20757)

Both tests fail on main and pass here.

⚠ Why most LaTeX survived it, and why the corpus says nothing

An assignment inside a group is restored by the save stack, and \@hangfrom and friends are grouped. Only a top-level assignment leaked, and no paper in the 154-paper list makes one:

scored            154 paper(s)
Σ|page deviation| 310 -> 310   (+0)
exact pagination   27 ->  27   (+0)
papers moved        0

⭐ That zero is the same zero the \hangindent PR's A/B produced, and it now has an explanation rather than two candidates: group restoration was already doing the work for every path the corpus uses. A document that writes \hangindent outside a group is the case that was broken, and it is not in this corpus.

The reset writes through the setters, deliberately

setCount/setDimen, not the register slices, so the assignment takes part in grouping exactly as eq_word_define does. A reset that escaped its own group would be a second bug of the same family as the one it fixes.

⚠ \parshape is absent because this engine has no such primitive; its reset belongs on the line below when it grows one. go-typeset/linebreak's ParShape is already released and waiting.

gofmt -l . prints nothing, go vet ./... clean, go test ./... green on all nine packages, 154 of 154 papers scored.

⚠ Not claimed

  • That nine call sites are covered. tex.web calls normal_paragraph from \par, the output group, \insert, \vadjust, \vcenter and -vmode among others; this lands it at the end of a paragraph, which is vmode+par_end. The others are not addressed and a shape could still outlive, say, a \vcenter here.
  • That \looseness does anything. It is reset because tex.web resets it; it remains unimplemented — finding 7 of go-typeset/linebreak's nine-divergence census, and 0 of 154 papers set it.

🤖 Generated with Claude Code

tex.web:20756-20761, called from nine places including vmode+par_end — every
\par:

    procedure normal_paragraph;
    begin if looseness<>0 then eq_word_define(int_base+looseness_code,0);
    if hang_indent<>0 then eq_word_define(dimen_base+hang_indent_code,0);
    if hang_after<>1 then eq_word_define(int_base+hang_after_code,1);
    if par_shape_ptr<>null then eq_define(par_shape_loc,shape_ref,null);
    end;

This engine kept the shape for ever.

⛔⛔ AND THAT BECAME A DEFECT THE MOMENT THE PARAMETER STARTED WORKING. While
\hangindent was accept-and-ignore, never resetting it cost nothing and no test
could have noticed. #795 made it shape the line breaker; the same omission then
hung every FOLLOWING paragraph. Measured before this landed, the same second
paragraph in two documents differing only in what their FIRST paragraph asked:

    after a hung first:   "measure that is wrong" / "by a centimetre is wrong"
    after a plain first:  "sure that is wrong by a cen-" / "timetre is wrong on every"

and the three parameters read back unchanged after \par — \hangindent 1572864
sp, \hangafter 3, \looseness 2, where TeX gives 0, 1 and 0.

⚠ Most LaTeX survived it anyway: an assignment inside a group is restored by the
save stack, and \@hangfrom and friends are grouped. The top-level assignment is
the one that leaked.

It writes through setCount/setDimen rather than the register slices, so the reset
takes part in grouping exactly as eq_word_define does — a reset that escaped its
group would be a second bug of the same family.

\parshape is absent because this engine has no such primitive yet; its reset
belongs on the line below when it grows one.

Co-Authored-By: Claude Opus 5 <[email protected]>
@tannevaled
tannevaled merged commit cff3129 into main Nov 15, 2026
18 checks passed
@tannevaled
tannevaled deleted the normal-paragraph-resets-the-shape branch November 15, 2026 20:53
tannevaled added a commit that referenced this pull request Nov 16, 2026
…wrote down

The README describes the line breaker and never mentioned \hangindent,
\hangafter or \parshape, although #795 implemented the first two, #796 made
them last one paragraph, and this branch adds the third. A reader of the
README could not tell that a document's own per-line measure reaches the
breaker at all.

It now says so, with the three facts a reader would otherwise get wrong:

  - the parameters reach the BREAKER, not only the placement;
  - \parshape WINS over \hangindent (tex.web:16706 tests par_shape_ptr first
    and consults hang_indent only in the else branch);
  - and all of them last ONE paragraph (:20756-20761).

And it states the corpus result as what it is: \parshape set by 0 of the 154
measured papers and \hangindent by 3, so the A/B's Σ|page deviation| 306 ->
306 with 0 papers moved is the PREDICTED result and a no-regression check,
not a fidelity win. Anything else would have meant a bug.

Co-Authored-By: Claude Opus 5 <[email protected]>
tannevaled added a commit that referenced this pull request Nov 16, 2026
…reaker (#798)

* \parshape is a primitive, so a document's own line widths reach the breaker

tex.web:23275-23286 is the whole of the scanner: scan_optional_equals,
scan_int, then n pairs of (indent, width) read as normal dimens. The engine
had no \parshape at all, so a document asking for its own per-line measure
was silently set on the uniform one.

MEASURED, on a 120pt measure with \parindent=0pt:

  uniform              5 lines   "ofeverypaper,andamea-"  ...
  \parshape=2          7 lines   "ofeverypaper,"  "andameasure"  ...
    0pt 120pt 0pt 60pt

The words move, which is the observable that shows the shape reaching the
BREAKER rather than only the placement. Line 1 keeps the full measure and
is identical on both sides; every later line gets 60pt, because the last
pair repeats (:16680-16681).

TWO RULES THAT A MUTATION SETTLED RATHER THAN MY READING:

- \parshape WINS OVER \hangindent (:16706 tests par_shape_ptr first and
  consults hang_indent only in the else branch). Reading \hangindent first
  in paragraphShape makes the precedence test, and only that test, fail:
  "with both set the paragraph does not match the \parshape alone".
- the n<=0 early return is a PANIC GUARD, not an over-read guard. Removing
  it leaves \parshape=0 unharmed -- the pair loop is bounded by n and runs
  zero times either way -- while \parshape=-1 panics in make([]Shape, 0, n)
  on a negative capacity. An earlier draft of the comment claimed the guard
  stopped the scanner eating the document's next two dimensions; it cannot,
  and the mutation said so. The comment now records what was measured.

The shape lasts one paragraph: normal_paragraph clears par_shape_ptr
(:20756-20761), with the caveat, stated in the code, that parShape is not
on the save stack.

Also: the box WIDTH is the wrong observable for any of this, and the
witness says so -- a positive indent keeps the box at the full measure with
a rigid kern inside it, so every box is hsize wide either way. The text per
line is what moves.

Plan #792, item B3b.

Co-Authored-By: Claude Opus 5 <[email protected]>

* README: the per-line measure, which three merged pull requests never wrote down

The README describes the line breaker and never mentioned \hangindent,
\hangafter or \parshape, although #795 implemented the first two, #796 made
them last one paragraph, and this branch adds the third. A reader of the
README could not tell that a document's own per-line measure reaches the
breaker at all.

It now says so, with the three facts a reader would otherwise get wrong:

  - the parameters reach the BREAKER, not only the placement;
  - \parshape WINS over \hangindent (tex.web:16706 tests par_shape_ptr first
    and consults hang_indent only in the else branch);
  - and all of them last ONE paragraph (:20756-20761).

And it states the corpus result as what it is: \parshape set by 0 of the 154
measured papers and \hangindent by 3, so the A/B's Σ|page deviation| 306 ->
306 with 0 papers moved is the PREDICTED result and a no-regression check,
not a fidelity win. Anything else would have meant a bug.

Co-Authored-By: Claude Opus 5 <[email protected]>

---------

Co-authored-by: Claude Opus 5 <[email protected]>
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