Skip to content

engine: surface math the go-tex/math layer drops (Diagnostics.MathDropped) - #34

Merged
tannevaled merged 1 commit into
mainfrom
feat-math-dropped-diagnostics
Aug 18, 2026
Merged

engine: surface math the go-tex/math layer drops (Diagnostics.MathDropped)#34
tannevaled merged 1 commit into
mainfrom
feat-math-dropped-diagnostics

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Instrumentation #3 — surface MATH content the math layer drops

Feasibility finding

The go-tex/math parser does not silently swallow unknown control words: parse.go returns a hard error texmath: unknown command \X (and other structural errors like \left without \right). The engine already catches these in renderMathResolvingMacros/makeMath, and in lenient mode drops the whole equation and tallies the trigger via recordMathSkip. So go-tex/math already exposes unhandled tokens through its error return — bullet 1 of the task applies, and no change to the go-tex/math module is needed.

The one gap: that tally landed in the same skippedCS map as text-mode undefined commands, so a formula's silently-lost content was conflated with a missing text macro. In -report-skipped a math key (which carries its own \) was even printed with a doubled backslash.

(The only genuinely-silent degradations in go-tex/math are within array/column-spec parsing — an unknown column letter falls back to centred, stray punctuation is ignored. These are rendering approximations, not content drops, and are not worth a math-module change.)

Approach chosen

Separate math drops from text skips, without touching rendering or the existing skippedCS surface:

  • recordMathSkip now also tallies into a dedicated mathDropped map[string]int (same key).
  • Diagnostics() lifts those keys out of Skipped into a new MathDropped field (added at the end of the struct — trivial merge). Text-mode gaps stay in Skipped; math-layer drops go in MathDropped.
  • Raw skippedCS is unchanged, so SkippedCommands() and every existing caller/test keep identical behaviour.
  • Surfaced in the -report-skipped CLI report (its own "math equation group(s) dropped" section) and the wasm diagnostics object (mathDropped).

Tests (RED without / GREEN with)

mathdropped_test.go + a CLI TestRunReportMathDropped:

  • an unknown math command surfaces under MathDropped and not under Skipped (proving the separation), while SkippedCommands() still carries it;
  • a malformed equation (\left( unclosed) is counted under the $math$ sentinel;
  • valid math (\frac, \sum, \cdot, \alpha) drops nothing;
  • the snapshot is a copy.

Verified by temporarily disabling the tally: both new tests go RED (the report even reproduced the old doubled-backslash conflation), GREEN once restored.

Gates

  • GOWORK=off go test -race ./... green
  • gofmt -l clean, go vet ./... clean
  • GOWORK=off GOOS=js GOARCH=wasm go build ./... green
  • engine package coverage 92.5% (cmd/gotex 73.0%→73.6%, a pre-existing infra gap; new code paths covered)

🤖 Generated with Claude Code

…pped)

When go-tex/math meets a command it does not implement it returns
"unknown command \X", and the engine (in lenient mode) drops the WHOLE
equation and tallies the trigger. Until now that tally landed in the same
skippedCS map as text-mode undefined commands, so a formula's silently-lost
content was conflated with a missing text macro — and in -report-skipped it
even printed with a doubled backslash.

Separate the two. recordMathSkip now also tallies into a dedicated
mathDropped map (same key), and Diagnostics lifts those keys OUT of Skipped
into a new MathDropped field: text-mode gaps in Skipped, math-layer drops in
MathDropped. The raw skippedCS is untouched, so SkippedCommands and every
existing caller/test keep the same behaviour.

Surfaced in the -report-skipped CLI report (its own "math equation group(s)
dropped" section) and the wasm diagnostics object ("mathDropped"). A
regression test proves an unknown math command surfaces under MathDropped and
NOT under Skipped, that a malformed equation is counted under the "$math$"
sentinel, that valid math drops nothing, and that the snapshot is a copy.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit eff6a22 into main Aug 18, 2026
18 checks passed
@tannevaled
tannevaled deleted the feat-math-dropped-diagnostics branch August 18, 2026 10:19
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