Skip to content

Fix DVI operand lengths for y1–y4 and xxx1–xxx4, and the fnt1–fnt4 range - #398

Merged
tdewolff merged 1 commit into
tdewolff:masterfrom
scttfrdmn:fix-dvi-opcode-lengths
Nov 18, 2026
Merged

tdewolff merged 1 commit into
tdewolff:masterfrom
scttfrdmn:fix-dvi-opcode-lengths

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Three opcode bugs in DVI2Path (latex_dvi.go), checked against the DVI format (Knuth, TeX: The Program §585):

Opcodes Before Should be
y1–y4 (162–165) reads cmd-152 = 10–13 operand bytes cmd-161 = 1–4
fnt1–fnt4 branch covers 235–242 235–238
xxx1–xxx4 (239–242) unreachable (swallowed by the fnt branch), and its length was cmd-242 cmd-238

The y bug desynchronises the byte stream, so any formula whose DVI uses y1 fails. For example, ParseLaTeX(\matrix{a & b \cr c & d}) returns bad command: stack is empty at position 172, and so does \pmatrix.

Test: a new latex_test.go (build tag !latex, the default pure-Go path) with TestLaTeXMatrix. It fails on master with the error above and passes with the fix. go test . passes.

Found while adding Markdown math to inkcap, following up on #397.

- y1..y4 (162-165) read cmd-152 (10-13) operand bytes instead of
  cmd-161 (1-4), desynchronising the stream. Any formula whose DVI uses
  y1, e.g. \matrix and \pmatrix, failed with 'stack is empty'.
- fnt1..fnt4 are 235-238, but the branch covered 235-242 and swallowed
  the xxx1..xxx4 specials (239-242), whose operand length was also off
  (cmd-242 instead of cmd-238).
@tdewolff
tdewolff merged commit c4d65ae into tdewolff:master Nov 18, 2026
1 check failed
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