Skip to content

compiler: \pagebreak right after \noindent, \indent or \textbf{ is horizontal (GH-PAGEBREAK-MIDPARAGRAPH; stacked on #583) - #616

Merged
GoKubar merged 12 commits into
mainfrom
agent/daniel-parent/pagebreak-midparagraph
Sep 15, 2026
Merged

GoKubar merged 12 commits into
mainfrom
agent/daniel-parent/pagebreak-midparagraph

Conversation

@d-q222

@d-q222 d-q222 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

What

A \pagebreak or \nopagebreak right after \noindent, \indent or a text font command (\textbf{, \emph{, ...) is now horizontal. The compiler emits Inline::PagePenalty (latex.ltx \@no@pgbk's \vadjust), not a Block::Penalty before the paragraph. A \pagebreak after only \label{..} stays vertical. Task GH-PAGEBREAK-MIDPARAGRAPH. Stacked on #583, which is stacked on #568.

  • parser.rs: a new P::paragraph_started flag. \noindent, \indent and the style_command arm set it (\hmode@bgroup is \leavevmode\bgroup). It is cleared in finish_block_dependencies, which runs after every block push, and in flush_list_item.
  • The pagebreak | nopagebreak arm is horizontal when that flag is set or when the paragraph holds any inline other than Inline::Label.
  • A unit test pins the parse for all of the above.

Why

The original report in #599/#608 was that First. \pagebreak Second. splits the paragraph. That comes from main's pinned vendor/compiler, not from this stack. With #583's compiler swapped into #599, a mid-paragraph \pagebreak already matches pdflatex everywhere I probed: inline, on its own line, {}, [1] to [4], \nopagebreak, and 72 positions near the page foot. The stacked pipeline PR pins that.

Probing did turn up one real divergence, at the start of a paragraph. The arm decided the mode from para.is_empty():

probe (pdflatex, TeX Live 2026, article 10pt) pdflatex #583 + #599 this PR
\noindent\pagebreak <2-line par> page 1 = line 1, page 2 = line 2 1 page (vertical penalty at the page top is discarded) match
Before. \indent\pagebreak <par> page 1 = Before. + line 1 break before the paragraph match
Before. \textbf{\pagebreak Bold} <par> page 1 = Before. + line 1 break before the paragraph match
\noindent\mbox{}\pagebreak <par> page 1 = line 1 1 page match
Before. \label{a}\pagebreak <par> page 1 = Before. break after line 1 match
\section{\textbf{Head}}\pagebreak, \textbf{Bold para.} + blank + \pagebreak, \begin{center}\noindent ..\end{center}\pagebreak, \itemize with \textbf then \pagebreak, \noindent + blank line + \pagebreak (flag leak checks) as source match match

Lines were read with PyMuPDF from the pdflatex PDF and from our v2 display list (flashtex-render --v2), comparing page and text per line. Baselines agree within 0.01bp.

Overlap check

Test results

  • cargo test (crates/compiler, CARGO_BUILD_JOBS=4): 57 test result: ok lines, 680 passed, 0 failed.
  • cargo test --lib -- pagebreak: test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 344 filtered out.
  • Pipeline suite, from a scratch export of the stacked pipeline branch with this crates/compiler/src as vendor/compiler: test result: ok. 23 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out. With compiler: vertical \pagebreak is a bare penalty, amsmath \nobreakdash (#64; stacked on #568) #583's parser.rs it gives FAILED. 22 passed; 1 failed (pagebreak_right_after_a_paragraph_starts_is_horizontal).

Not done

  • \leavevmode\pagebreak still breaks before the paragraph. \leavevmode is an unsupported command in this compiler (it is diagnosed), so it does not start the paragraph.
  • A \pagebreak inside \parbox/minipage still breaks the page. pdflatex keeps a \vadjust inside the box. Both constructs are unsupported and diagnosed (their bodies are flattened into the paragraph). Separately, a minipage after \noindent prints its 5cm width argument as text.
  • A [h] figure followed by a vertical \pagebreak stays on one page, while pdflatex ends the page after the float. This is pre-existing on main too, and it is float placement rather than this path.
  • The vendor/compiler re-pin is an integrator action.

🤖 Generated with Claude Code

https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

…ry and parameter nodes (#64)

What changed:
- New AST: Inline::Penalty {value, unskip} (\penalty, \nobreak, \allowbreak,
  \linebreak[n], \nolinebreak[n]), Inline::PagePenalty (\pagebreak[n] and
  \nopagebreak[n] inside a paragraph: \vadjust, the paragraph is not broken),
  Inline::Discretionary (\-, \discretionary{}{}{}), Block::Penalty {value, fil}
  (vertical-mode \penalty/\nobreak, \pagebreak[n<4], \nopagebreak[n],
  \goodbreak, \filbreak). Values are latex.ltx's \@getpen 0/51/151/301/10000.
- Parsed::parameters: \tolerance, \pretolerance, \looseness, \widowpenalty,
  \clubpenalty, \interlinepenalty, \emergencystretch (also \setlength),
  \sloppy, \fussy, sloppypar, \samepage (and its environment), \raggedbottom,
  \flushbottom, \enlargethispage(*), each with the group end that restores it.
  Parsed::hyphenation: \hyphenation words.
- \- is a command in the lexer and the expansion pass, so it is never typeset
  as a hyphen; \penalty's number and parameter values no longer leak as text.
- Core 14 layout: forced penalties break lines/pages; \pagebreak in a paragraph
  ends the page after its line (FlowState carries the pending eject).
- Inventory, vocabulary and generated supported-LaTeX artefacts regenerated.

What was run:
- cargo test (crates/compiler): 573 passed; 0 failed before the inventory move,
  then --lib: test result: ok. 347 passed; 0 failed
- --test supported_latex: test result: ok. 8 passed; 0 failed
- --test hw1_preamble/hw2_gate/corpus_gate/pinned_fixtures/incremental_json_identity/
  local_recovery/preamble_page_commands/line_break_skip: all ok
- pdflatex \showlists / \showthe oracle for every value (in the PR body).

Next step: render-pipeline consumes the nodes after vendor/compiler is re-pinned.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
#64)

What changed:
- Inline::Penalty/PagePenalty spans now include `[n]` and `\penalty`'s number,
  so a consumer reading the source after a node starts past them (the
  pipeline decides whether LaTeX ate the blanks after the command from this).

What was run:
- cargo test --lib (crates/compiler): test result: ok. 347 passed; 0 failed

Next step: open the compiler PR and the render-pipeline draft.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
…alty, \nobreakdash (#64)

What changed:
- \include{file} emits latex.ltx \@include's \clearpage before the file and
  after it (expansion.rs: the closing one precedes the first token read once
  the engine has left the file). A file \includeonly skips keeps only the
  first; a missing file keeps both. \input is unchanged.
- A vertical-mode \pagebreak (priority 4) is Block::Penalty { value: -10000 }
  instead of Block::PageBreak: latex.ltx has no \vfil before it, unlike
  \newpage, so a \flushbottom page it ends is stretched.
- amsmath \nobreakdash: the following -, -- or --- as text, then
  Inline::Penalty 10000 (\setboxz@h{--\nobreak}\unhbox\z@). Supported-LaTeX
  artefacts regenerated.

What was run:
- cargo test --lib: test result: ok. 349 passed; 0 failed
- cargo test --no-fail-fast (whole crate): every target ok after
  render_supported_latex.sh (supported_latex: ok. 8 passed; includeonly: ok. 10 passed)
- pdflatex probes with the render pipeline (scratch export): include 3/3 pages,
  include-para, include-two 4, include-last 2, includeonly-excluded 2: all match.

Next step: render-pipeline draft consumes the bare penalty (flushbottom) and
\nobreakdash's hyphenation; vendor re-pin past #568 and this PR.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
What changed:
- Reverted the \include \clearpage emission in expansion.rs and the
  includeonly test changes from the previous commit: #578 (render pipeline,
  agent/daniel-parent/include-float-numbering) already clears the page before
  and after an \include'd file, and the coordinator moved that item there.
  The vertical \pagebreak penalty and \nobreakdash stay.

What was run:
- cargo test --lib: test result: ok. 349 passed; 0 failed
- cargo test --test includeonly: test result: ok. 9 passed; 0 failed
- cargo test --test supported_latex: test result: ok. 8 passed; 0 failed

Next step: render-pipeline draft for \pagebreak under \flushbottom,
\nobreakdash hyphenation, \enlargethispage and the \clearpage float flush.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
…rizontal (GH-PAGEBREAK-MIDPARAGRAPH)

What changed:
- The `\pagebreak`/`\nopagebreak` arm decided the mode from whether the
  paragraph had collected any inline. `\noindent`, `\indent` and the text
  font commands (`\hmode@bgroup` = `\leavevmode\bgroup`) start the
  paragraph without adding one, so `\noindent\pagebreak text` was a
  vertical penalty before the paragraph (on an empty page it was dropped
  entirely). A new parser flag `paragraph_started` is set by those
  commands and cleared when a block is pushed or the paragraph is flushed;
  with it set the command is `Inline::PagePenalty` (latex.ltx `\@no@pgbk`'s
  `\vadjust`).
- A paragraph holding only `\label`s is still vertical:
  `\label{a}\pagebreak text` is a `Block::Penalty` again.

pdflatex (TeX Live 2026, article): `\noindent\pagebreak`, `\indent\pagebreak`
and `\textbf{\pagebreak Bold}` before a two-line paragraph end page 1 after
the paragraph's first line; `\label{a}\pagebreak` ends it before the
paragraph. A mid-paragraph `\pagebreak` (inline, on its own line, `[1]`,
`[2]`, `\nopagebreak`) was already right on this stack.

What was run:
- cargo test --lib -- pagebreak: test result: ok. 6 passed; 0 failed
- cargo test (crates/compiler): see the PR

Next step: re-pin vendor/compiler for the pipeline tests in the stacked
pipeline PR.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
@d-q222

d-q222 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

daniel-parent independent review (subagent)
Verdict: APPROVE

  1. Horizontal case confirmed by direct inspection of the parse tree (built PR head bcee6e9 in a fresh worktree, ran compiler::parser::parse from a scratch integration test). \noindent\pagebreak First. parses to a single Block::Paragraph whose first element is Inline::PagePenalty { value: -10000 } followed by the Text("First.") — a real Inline::PagePenalty, not a Block::Penalty.
  2. Vertical label-only case confirmed the same way: Before.\n\n\label{x}\pagebreak First. produces Block::Penalty { value: -10000 } between two Block::Paragraphs, and the following paragraph (Label, then Text("First.")) contains no Inline::PagePenalty at all — matches the claimed pdflatex behavior exactly.
  3. No flag leak, checked concretely both ways:
    • Section boundary: \noindent Text.\n\n\section{Next}\n\pagebreak more text parses to Paragraph("Text."), Heading, then Block::Penalty{-10000}, then Paragraph("more text") — the \pagebreak after \section{Next} is vertical, not leaked from the earlier \noindent. This works because \section calls flush_paragraph→flush_list_item, which unconditionally clears paragraph_started at the top of the function (before the empty-paragraph early return), so it clears even on a flush with nothing pending.
    • List boundary: \begin{itemize}\item text\end{itemize}\n\n\pagebreak more text → ListItem, Block::Penalty{-10000}, Paragraph("more text") — correctly vertical after \end{itemize} (which also runs through flush_list_item). \begin{itemize}\item\noindent text \pagebreak\end{itemize} keeps the PagePenalty inside the item's content list with no incorrect Block::Penalty leaking out (this case already had non-empty para text before \pagebreak, so it doesn't independently exercise the flag, but confirms no crash/mishandling inside a list item).
    • Also checked the PR's own edge case \noindent\n\n\pagebreak\nFirst. (blank line right after \noindent with nothing typeset): produces Block::Penalty{-10000} then a clean Paragraph("First."), i.e. the flag is cleared by the empty flush before the next paragraph starts — matches the PR's own pinned unit-test expectation.
  4. PR's own unit tests pass: cargo test --lib -- pagebreak → 6 passed, 0 failed (including the new pagebreak_right_after_a_paragraph_starts_is_horizontal). Full crate suite: cargo test --lib → 350 passed, 0 failed.

All three behavioral claims and the unit tests hold with direct evidence, not just "it compiled." No issues found.

Kept both sides of the supported.rs inventory (main's \xspace entry plus this
branch's penalty-based page/paragraph-control entries) and regenerated
docs/user/compiler.md, supported-latex.json, coverage.md and the Mac bundled
copy via render_supported_latex.sh.

Implementation-Agent: fable-rebase-c
Commit-Executor: fable-rebase-c (direct; Cursor usage limit)
…followups

Brings in origin/main via the parent PR #568 branch's merge commit; regenerated
docs/user/compiler.md and the supported-latex inventories.

Implementation-Agent: fable-rebase-c
Commit-Executor: fable-rebase-c (direct; Cursor usage limit)
Kept main's \fnsymbol dispatch arm alongside this stack's penalty-based
\linebreak/\nolinebreak arms in parser.rs; regenerated docs/user/compiler.md
and the supported-latex inventories.

Implementation-Agent: fable-rebase-c
Commit-Executor: fable-rebase-c (direct; Cursor usage limit)
Kept main's \fnsymbol dispatch arm alongside this branch's penalty-based
\linebreak/\nolinebreak arms; regenerated the supported-latex artefacts.

Implementation-Agent: fable-rebase-c
Commit-Executor: fable-rebase-c (direct; Cursor usage limit)
…wups

Records the parent PR #568 branch's own origin/main merge; no tree changes.

Implementation-Agent: fable-rebase-c
Commit-Executor: fable-rebase-c (direct; Cursor usage limit)
…ded)

Clean merge, no conflicts.

Implementation-Agent: fable-rebase-c
Commit-Executor: fable-rebase-c (direct; Cursor usage limit)
Parents #568/#583 are squashed on main; kept this branch's own mode-based
horizontal-\pagebreak logic, comment and test over the squash state, and took
main's #587 parser state fields (length_scopes, pending_global,
latin_modern, preamble_latin_modern). Regenerated supported-latex artefacts.

Implementation-Agent: fable-rebase-c
Commit-Executor: fable-rebase-c (direct; Cursor usage limit)
@GoKubar
GoKubar merged commit bcaf68f into main Sep 15, 2026
10 of 21 checks passed
GoKubar added a commit that referenced this pull request Sep 15, 2026
/#635 grew the inventory

docs/user/compiler.md (generated) conflicted again; took main's copy and
regenerated via render_supported_latex.sh so \underbar and main's
additions both appear, sync --check clean.

Implementation-Agent: fable-rebase-a
Commit-Executor: fable-rebase-a (direct; Cursor usage limit)
@GoKubar
GoKubar deleted the agent/daniel-parent/pagebreak-midparagraph branch September 16, 2026 04:16
ItsAkilesh pushed a commit to ItsAkilesh/flashtex that referenced this pull request Sep 18, 2026
What changed:
- `crates/render-pipeline/Cargo.toml` declares a new off-by-default feature
  `compiler-node-surface`. It carries no behaviour of its own: every arm it
  adds is the inert answer the pipeline already gave for a compiler node the
  current pin (`c95977d6`) cannot produce.
- The pipeline's exhaustive matches and node constructors now cover main's
  compiler surface behind that feature: `parser::Block::Penalty`/`Tabbing`,
  `parser::Inline::ThePage`/`PageNumbering`/`TabStop`/`TabJump`/`Marginpar`/
  `Penalty`/`PagePenalty`/`Discretionary`, `VSpace`/`HSpace` glue components,
  `math::Nucleus::TextRun`/`SideSet`/`Lap` and `math::Accent::Mathring`
  (compiler flash-tex#549, flash-tex#551, flash-tex#555, flash-tex#568, flash-tex#581, flash-tex#583, flash-tex#587, flash-tex#606, flash-tex#616).
  `adapter::vspace_block` is a new cfg'd constructor beside the existing
  `line_break_inline`; the one open-coded `Inline::LineBreak { .. }` left in
  the `\opening` lowering now goes through `line_break_inline` too.
- `tabbing` is lowered to flush-left paragraphs with one `unsupported_block`
  limitation, the way `LetterBlock` is, so no row is dropped by the re-pin.
- `docs/integration/repin-runbook.md`: the exact re-pin commands, the three
  vendor directories that must move (`compiler`, `tex-expansion`, and a new
  `bibliography`), the lockfile and `#[ignore]` edits `--locked` CI needs, the
  measured test deltas and the PRs the pin unblocks.

No file under `vendor/` is touched: the vendor swap used to measure all of
this was scratch-only and reverted. `git diff --stat origin/main...HEAD`
contains zero `vendor/` paths.

What was run:
Whole `crates/render-pipeline` suite, CARGO_BUILD_JOBS=4, --no-fail-fast:
  origin/main, pinned vendor, feature off:   469 passed, 13 failed
  this branch, pinned vendor, feature off:   469 passed, 13 failed (same 13)
  this branch, vendor re-pinned, feature on: 485 passed, 0 failed
The 13 red-on-main tests (letter_class_geometry x5, frame_env, underline_sout
x4, uline x2, xcolor_oracle) all pass after the re-pin.
Two re-pin-gated #[ignore]s also pass against the re-pinned vendor:
  test frame_draws_a_rule_border_around_its_content ... ok
  test coloneqq_decomposes_like_mathtools ... ok
crates/flashtex-cli against the same re-pinned vendor:
  test result: ok. 58 passed; 0 failed
cargo check --all-targets on this branch at the current pin: 0 errors.

Next step:
The integration lane applies docs/integration/repin-runbook.md section 3 --
swap the three vendor trees, move `compiler-node-surface` (and
`linebreak-skip`) into `default`, refresh both Cargo.locks, drop the two
`#[ignore]`s, update vendor/VENDORING.md.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
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