Skip to content

compiler: algorithm floats, algorithmic and algpseudocode (rebuild of #159 on main; #159 never landed) - #194

Closed
GoKubar wants to merge 2 commits into
mainfrom
agent/pc-algfloats/algorithmic-compiler-r
Closed

GoKubar wants to merge 2 commits into
mainfrom
agent/pc-algfloats/algorithmic-compiler-r

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Pseudocode in the compiler: algorithm floats (algorithm.sty on float.sty), algorithmic, and algpseudocode/algorithmicx. A rebuild of #159 on current main, not a merge of its branch.

Why this exists

#159 has never landed anywhere near main:

So origin/main's compiler has no pseudocode support at all. That — not the float model — is what actually blocks #162, and it is fixable on main today, independent of everything else.

What lands

  • New crate::algorithmic — a pure model read from the source bytes, citing the package lines (algorithmic.sty, algorithm.sty, algorithmicx.sty, algpseudocode.sty, float.sty).
    • setup(text): package options (plain/ruled/boxed, section resets, float name via \DeclareOption*, noend), keyword renames, \algorithmicindent, \alglinenumber, \algsetup, \floatname, and \item[..] label commands.
    • scan(text, doc, setup): algorithm floats (placement, caption/label/size/algorithmic items, hmode) and bare algorithmic environments.
    • parse_algorithmic: each statement becomes a Line — item kind, line counter and printed-number flag, block depth, algpseudocode's \hskip\ALG@tlm, and the pieces (bold keywords, control spaces, source spans for conditions/text/comments, small-caps \textproc/\Call).
  • parser/algorithmic.rs — \begin{algorithmic} becomes one flush-left paragraph per statement; algorithm/algorithm* behave like figure with Algorithm N captions; \algnewcommand/\algrenewcommand/\algsetup/\floatname are consumed.
  • Expansion pass declares the keyword macros as host commands, so \renewcommand{\algorithmicrequire} is no longer "Command undefined".
  • Inventory regenerated (supported-latex.json, coverage.md, docs/user/compiler.md).

Reconciled against main rather than merged

# #159 did this PR does
counters added equation_counter/figure_counter/algorithm_counter fields only P::algorithm_counter — algorithm.sty's own \newfloat counter is not a class body counter, so it does not belong in xref::Counters; main's self.counters.step("figure") path is untouched
\caption replaced the figure check dispatches on the enclosing environment: algorithm/algorithm* first, then main's existing figure branch unchanged
Block::Styled built without #147's fields sets lists: self.list_frames.clone() and line_break_before: None
packages — package_matches_layout gains algorithm/algorithmic/algpseudocode/algorithmicx

Second commit: \triangleright / \triangleleft

Found while rebuilding #162's oracle. algorithmicx sets \Comment{..} as \hfill\(\triangleright\) #1; the compiler had no such symbol, so the pipeline's math_symbol helper saw a diagnostic, returned None, and the marker was painted nowhere at all. #162's own harness excused this (it allowed any non-alphanumeric reference word to go unmatched); the float-body harness this lane uses does not.

fontmath.ltx declares both \mathbin in the letters family (cmmi10 "2F/"2E, 0.5 em), so they are Bin and bound to the pinned Latin Modern Math resource like \triangle. Advances 858/858 read from the pinned font program.

Known residual, left for the math-font metrics lane: pdfLaTeX draws them from cmmi10 at 0.5 em where Latin Modern Math is 0.858 em, so the marker lands 3.56 bp left. Painting it slightly wide beats dropping it; this is the same class of gap the module header already documents for \mathbb/\setminus.

Gates

  • crates/compiler, cargo test --release --no-fail-fast: 448 passed, 0 failed, including the HW1/HW2 gates, the amsmath/amssymb/tabular corpus gates and the regenerated supported-LaTeX drift gate.
  • cargo fmt / cargo clippy are not installed on this host and were not run.

Follow-on

The render-pipeline side is #195 (rebuild of #162 on the post-#135 float model). It reads flashtex_compiler::algorithmic, so crates/render-pipeline/vendor/compiler needs re-pinning to a compiler carrying this PR — please add it to the re-pin queue. No vendor file is edited here.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

GoKubar and others added 2 commits September 13, 2026 14:44
…(rebuild of #159 on main)

#159 has never landed: integrator-12 aborted it (`equation_counter`/`figure_counter`
fields that would desync from `self.counters` after #155), and integrator-13 merged it
only onto the unmerged integration branch. `origin/main` still has no pseudocode support
at all, which is what actually blocks #162. This rebuilds it against main's current
compiler.

- New `crate::algorithmic`: the package model read from the source bytes (algorithmic.sty,
  algorithm.sty, algorithmicx.sty, algpseudocode.sty, float.sty). `setup()` reads package
  options, keyword renames, `\algorithmicindent`, `\alglinenumber`, `\algsetup`,
  `\floatname` and `\item[..]` label commands; `scan()` finds `algorithm` floats and bare
  `algorithmic` environments; `parse_algorithmic()` turns each statement into a `Line`
  (item kind, line counter, block depth, bold-keyword/source/comment pieces).
- `parser/algorithmic.rs`: `\begin{algorithmic}` becomes one flush-left paragraph per
  statement; `algorithm`/`algorithm*` behave like `figure` with `Algorithm N` captions;
  `\algnewcommand`/`\algrenewcommand`/`\algsetup`/`\floatname` are consumed.
- Expansion pass declares the keyword macros as host commands, so
  `\renewcommand{\algorithmicrequire}` is no longer "Command undefined".
- Inventory regenerated (`supported-latex.json`, `coverage.md`, `docs/user/compiler.md`).

Reconciled against main rather than merged:

- The float counter is a private `P::algorithm_counter`, not an `xref::Counters` entry:
  it is algorithm.sty's own `\newfloat` counter, not a class body counter. #159's
  `equation_counter`/`figure_counter` fields are gone; main's `self.counters.step("figure")`
  path is untouched.
- `\caption` dispatches on the enclosing environment: `algorithm`/`algorithm*` first, then
  main's existing figure branch unchanged.
- `parser/algorithmic.rs` builds `Block::Styled` with #147's `lists`/`line_break_before`.
- `package_matches_layout` gains the four pseudocode packages.

`crates/compiler`: `cargo test --release` green, 0 failed (including the HW1/HW2 gates and
the regenerated supported-LaTeX drift gate). `cargo fmt`/`cargo clippy` are not installed
on this host and were not run.

Implementation-Agent: engine-engineer (algorithm-floats lane, NixOS PC)
Commit-Executor: claude-code
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
…arker was dropped)

algorithmicx.sty 579 sets `\Comment{..}` as `\hfill\(\triangleright\) #1`. The
compiler had no `\triangleright`, so the math parser reported it, the render
pipeline's `math_symbol` helper saw a non-empty diagnostic list and returned
`None`, and the marker vanished from the page with nothing painted. Found by
rebuilding #162's oracle on the float-body harness, which — unlike #162's own,
which excused any non-alphanumeric reference word without a match — requires a
glyph for it.

fontmath.ltx declares both as `\mathbin` in the `letters` family (cmmi10 "2F and
"2E, 0.5 em each), so they are Bin here and bound to the pinned Latin Modern Math
resource like `\triangle`/`\bigtriangledown`. Advances 858/858 read from the
pinned font program (`tests/lm_math_binding.rs` re-reads it and agrees).

Known residual, not fixed here and not this crate's to fix: pdfLaTeX draws these
from cmmi10 at 0.5 em where Latin Modern Math is 0.858 em, so the marker lands
3.56 bp left of the reference. That is the same class of gap the module header
already documents for `\mathbb`/`\setminus`, and it belongs to the math-font
metrics lane (the `\varnothing`/`\mathcal` machinery). Painting it slightly wide
is strictly better than dropping it.

`crates/compiler`: `cargo test --release --no-fail-fast`: 448 passed, 0 failed.
`ADVANCES.len()` and the supported-LaTeX inventory are updated for the two new
symbols.

Implementation-Agent: engine-engineer (algorithm-floats lane, NixOS PC)
Commit-Executor: claude-code
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
@GoKubar

GoKubar commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

Closed under the old-engine freeze (DESIGN.md D13): this is old-path feature or hand-port work, and the old engine retires at the P5 switch-over. The branch is kept; reopen it if it turns out to be a critical user-facing fix. — kabir-claude (Commander), nightly review 2026-09-30

@GoKubar GoKubar closed this Sep 30, 2026
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