Skip to content

compiler + tex-expansion: scope user-defined environment bodies as real groups (#928) - #950

Merged
jay3332 merged 3 commits into
mainfrom
muse/newenvironment
Sep 19, 2026
Merged

jay3332 merged 3 commits into
mainfrom
muse/newenvironment

Conversation

@d-q222

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

Copy link
Copy Markdown
Contributor

Closes #928.

The issue's own title states the thesis: "Complexity needs user-defined environments, not more built-ins." This is the mechanism by which users extend LaTeX themselves — every custom homework class defines its own environments — and it matters more than any individual package we could add.

\newenvironment{name}{before}{after} now defines an environment whose \begin{name} / \end{name} expand their before/after code, so the body is processed normally instead of falling through.

Two halves:

  • tex-expansion emits balanced \begingroup/\endgroup around \begin/\end, so the environment's declarations scope the way LaTeX's do rather than leaking into the surrounding text.
  • compiler scopes environment bodies as parser groups, which is what makes the body a real nested context rather than a flat token run.

Oracle

Verified against TeX Live 2026 pdflatex with PyMuPDF span origins: a body \bfseries sets on its own baseline with the after-code \rmfamily text on a later one; a bigtext body sets at 14.4 pt with the after-code returning to 12.0 on the shared baseline y=86.40 — matching pdflatex's structure exactly. Absolute values differ (the repro is 12 pt Times against 10 pt Computer Modern), which is why the check is on structure and relative baselines, not absolute coordinates. Zero diagnostics on both documents.

Tests

Both profiles, both crates:

compiler       debug 94 suites ok / 0 failed    release 94 / 0     (full run: 1169 passed)
tex-expansion  debug  6 suites ok / 0 failed    release  6 / 0     (expand_tests 90, oracle 9)

No supported-latex regeneration was needed, so nothing to sync into apps/.

Reach

Like every crates/compiler / crates/tex-expansion change right now, this is inert for users of the shipped CLI until crates/render-pipeline/vendor/ is re-pinned — see #896 and the build evidence in #945. Merging this does not yet put it in anyone's hands.

Implementation-Agent: muse-spark-1.3-contributor
Commit-Executor: daniel-parent

🤖 Generated with Claude Code

d-q222 and others added 3 commits September 18, 2026 11:08
do_begin opened the environment group silently while do_end already
emitted \endgroup, so a \newenvironment whose begin/end code expands
inline left a lone closer and no scope behind: downstream declarations
leaked past \end. Emit the matching \begingroup (queued for output, not
re-executed), and give the pushed \endgroup the \end span.

Implementation-Agent: muse-spark-1.3-contributor
Commit-Executor: muse-spark-1.3-contributor
The expansion pass now delivers balanced group boundaries around every
\begin/\end; map \begingroup/\endgroup to parser groups so declarations
(\bfseries, \large, ...) stop at \end instead of leaking. The two
source-text range scanners (verbatim, comment) consume the reconstituted
\end tag structurally so the trailing close survives; runaway scans treat
the env LBrace as the boundary; the end-of-input brace sweep skips
\begin-spanned openers already covered by environment diagnostics.

Implementation-Agent: muse-spark-1.3-contributor
Commit-Executor: muse-spark-1.3-contributor
…ts and regenerate derived artefacts

Implementation-Agent: muse-spark-1.3-contributor
Commit-Executor: daniel-parent
Co-authored-by: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
@jay3332

jay3332 commented Sep 19, 2026

Copy link
Copy Markdown
Member

Not merged in the integration batch (main 6196051): its {/} emission for every \begin/\end collides with main's beamer \column{} command form — beamer_blocks fails twice with "argument to \frame is missing its closing brace". The CI red on the PR itself was a preview-controller stdio timeout, not this. Needs a rebase over main that scopes the group emission so the beamer command-form environments keep their argument parsing; happy to take it once rebased. (The other 17 of your green PRs are on main.)

@jay3332
jay3332 merged commit 951609f into main Sep 19, 2026
19 of 20 checks passed
jay3332 added a commit that referenced this pull request Sep 19, 2026
… heads

Two integration fixes for the merges just above, each pinned by a test.

#863 (factor-by-length dimensions) made `parse_dimen_pt_current` accept
`<factor>\baselineskip` as an unvalued `FACTOR_LENGTHS` reference, which
shadowed main's own `baselineskip_multiple` fallback for list lengths
(8a24707): `\setlength{\topsep}{0.6\baselineskip}` inside a list warned
"unsupported length expression" instead of resolving 7.2pt
(`list_topsep_accepts_a_baselineskip_factor`). The leading multiple is now
tried first, in `apply_length_value` and in `calc_chain_term_pt_current` —
the same reorder #863 itself applied to `\enlargethispage`.

#950 (environment bodies as real groups) emits the environment's
`\begingroup` brace directly ahead of every reconstituted `\begin{name}`,
so beamer's optional `{title}{subtitle}` scan after `\begin{frame}` read a
nested `\begin{itemize}`/`\begin{columns}` as a title group and reported
"argument to \frame is missing its closing brace" (5 failures in
`beamer_blocks`/`beamer_overlays`). `environment_group_open_at` tells that
brace apart (a literal `{` ahead of an environment is followed by the
environment's own brace, never by `\begin` itself), and the four
`\@ifnextchar\bgroup`-style scans — frame head, `\onslide`, `\note`, the
theme declarations — use `next_opens_literal_group`. Real `\column{...}`
/ `\frame{...}` argument parsing is untouched (their braces are literal).

Implementation-Agent: Claude Code (mac-claude-a / lane-integrate2)
Commit-Executor: git via Claude Code
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y1nAv4pEnmMYXgteBoadHn
jay3332 added a commit that referenced this pull request Sep 19, 2026
…he integration batch + package definitions

The pin reads main again after the second integration pass (#827 cherry-picks,
#863, #950, #737/#739/#758/#732/#740/#825, visual-oracle tooling) and the
`metadata.packages` work (`crate::package_definitions`, tex-expansion's
`package_defs.rs`). `git archive` of this tree's `crates/compiler` and
`crates/tex-expansion`, PINs at the merge commit, VENDORING.md rows updated,
`scripts/check-vendor-pins.sh` both "up to date". render-pipeline 819/0 in
both profiles against the new pins; compiler 1368/0, tex-expansion 150/0
release; Mac inventory sync current; swift build clean.

Implementation-Agent: Claude Code (mac-claude-a)
Commit-Executor: git via Claude Code
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y1nAv4pEnmMYXgteBoadHn
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.

Complexity needs user-defined environments, not more built-ins — \newenvironment bodies fall through to plain text

2 participants