Skip to content

a paragraph is broken on its own shape, so \hangindent is honoured - #795

Merged
tannevaled merged 1 commit into
mainfrom
hangindent-reaches-the-breaker
Nov 15, 2026
Merged

tannevaled merged 1 commit into
mainfrom
hangindent-reaches-the-breaker

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

\hangindent is honoured: the paragraph is broken on its own shape, not set on one measure and indented afterwards. The corpus A/B moves NOTHING — zero papers — which makes this safe to land and is also the weakest possible support for the hypothesis that this mechanism explains #381. Closes #757. Refs #792, #754, #381 — all three stay open.

What TeX does, and what this engine did

tex.web §847-850 recomputes line_width per line from hang_indent and hang_after. The width is an input to the badness of every candidate break, so a shape is a line-breaking parameter and not a placement one.

This engine declared \hangindent, made it settable, read it back — and consulted it nowhere. It even cached which \dimen register the name finally resolved to (engine.go, because classkernel.go rebinds it after texparams.go declares it) purely so it could report the drop.

go-typeset/linebreak v1.10.0 grew the Measure that expresses a per-line width. So:

  • paragraphShape builds HangIndent(lineWidth, indent, hangafter) from that register;
  • breakSegment passes it to all three passes;
  • each line is packed to its own width with a rigid kern of its margin in front.

⛔ Both halves of the placement are needed, and a negative \hangindent is why. There the margin is zero and the line is still shorter by |indent| (:16729-16730) — it indents from the right. A kern alone would leave the pack target at the full measure and the \rightskip glue would stretch the text back across it, so the indent would vanish into the justification. Reducing the target instead leaves the slack as empty page, which is what indenting from the right means.

The unit witness: the words move, and the hyphenation changes

120pt measure, \hangindent=24pt \hangafter=1:

uniform  "Typography affects every line" / "of every paper, and a mea-" / "sure that is wrong by a cen-" / …
hung     "Typography affects every line" / "of every paper, and a"      / "measure that is wrong"       / …

Line 1 is untouched, which is \hangafter=1. And the narrower lines no longer need the hyphens the uniform setting took — so this is the breaker changing its mind, not a paragraph being shifted.

⚠ My first version of that test measured the wrong thing and I nearly reported the feature broken. It compared line-box WIDTHS, which are identical either way: a positive \hangindent keeps the box at the full measure with the kern inside it, because a line box here carries no shift_amount. A throwaway probe showed the register did hold 24pt at paragraph time. The right observable is the text per line.

⚠ The corpus A/B: zero

base origin/main d4206584   head 087bb0c0   154 papers

scored            154 paper(s)
Σ|page deviation| 310 -> 310   (+0)
exact pagination   27 ->  27   (+0)
papers moved        0   (0 toward the reference, 0 away, 0 sideways)

154 of 154 scored, so nothing was decided by the clock.

This contradicted my own prediction. amssubstrate.go's \@hangfrom does \hangindent\wd\@tempboxa\noindent\box\@tempboxa, so I expected every \bibitem and every hanging heading in a real class to move. Two explanations fit the zero and I cannot separate them from here:

  1. the effect really is nil on this corpus — plausible if \@hangfrom only ever shapes section headings, which run to one or two lines, and a hanging indent changes nothing until there are lines after the first;
  2. or the shape is not reaching corpus paragraphs at all, in which case the unit witness passes and the real wiring does not.

⭐ The measurement that separates them, and it is not in this PR: count the paragraphs broken with a non-Uniform measure across the corpus, and how many of those have more than one line. Until that is run, neither explanation is established.

⚠ What the zero does and does not license

And the dropped-shape census is gone with the drop

It reported every non-zero \hangindent, under the rule that a feature silently dropped is worse than one refused — which was right while it was true. Now that the engine honours the parameter, that entry would be a false statement about our own behaviour, which is worse than either the drop or the silence. droppedshape_test.go is inverted accordingly, and its register-cache tests are kept and strengthened: that cache fed a report and now feeds the feature, so a stale value no longer means a census that never fires but every hanging indent silently ignored again.

⭐ A repository gate caught a real mistake here: TestDocCommentNamesItsOwnFunction told me, by name, that I had inserted paragraphShape between breakSegment's doc comment and its body.

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

⚠ Not claimed

  • \parshape. It is not a primitive in this engine at all, so a document writing it gets an undefined command rather than a silently dropped shape. linebreak's ParShape is ready for it; adding the primitive is separate work.
  • That the margin is placed to a thousandth of a point. The geometry is built from a kern plus a reduced pack target rather than TeX's shift_amount; it is equivalent for the cases above, and I have not diffed a rendered line against the reference.
  • Anything about \hangafter scanning. It was already an integer parameter with its own test, and this reads it through namedInt for that reason.

🤖 Generated with Claude Code

tex.web §847-850 recomputes line_width per line from hang_indent and hang_after.
The width is an input to the badness of every candidate break, so a shape is a
line-breaking parameter and not a placement one: a paragraph asking for
\hangindent is not the uniform paragraph moved over, it BREAKS somewhere else.

go-typeset/linebreak v1.10.0 grew the Measure that expresses it. paragraphShape
builds HangIndent from the register the engine already cached, breakSegment
passes it to all three passes, and each line is packed to its own width with a
rigid kern of its margin in front.

⛔ BOTH HALVES OF THE PLACEMENT ARE NEEDED, and a negative \hangindent is why:
there the margin is ZERO and the line is still shorter by |indent|, so a kern
alone would leave the target at the full measure and the rightskip glue would
stretch the text back across it. Reducing the target leaves the slack as empty
page, which is what indenting from the right means.

The witness, on a 120pt measure with \hangindent=24pt \hangafter=1 — note that
line 1 is untouched and the hyphenation CHANGES, because the narrower lines no
longer need it:

    uniform  "of every paper, and a mea-" "sure that is wrong by a cen-"
    hung     "of every paper, and a"      "measure that is wrong"

And the dropped-shape census is gone with the drop. It reported every non-zero
\hangindent under the rule that a feature silently dropped is worse than one
refused; now that the engine honours the parameter, that report would be a false
statement about our own behaviour. hangIndentReg stays and matters MORE: it fed
a census, and now it feeds the feature, so a stale value no longer means a
report that never fires but every hanging indent ignored again.

Co-Authored-By: Claude Opus 5 <[email protected]>
@tannevaled
tannevaled merged commit 0006414 into main Nov 15, 2026
18 checks passed
@tannevaled
tannevaled deleted the hangindent-reaches-the-breaker branch November 15, 2026 20:11
tannevaled added a commit that referenced this pull request Nov 15, 2026
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 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.

\hangindent is declared and never read: every bibliography entry is set four ems too wide

1 participant