engine: a maths macro's optional argument - #166
Merged
Conversation
\newcommand{\cmd}[n][default] makes the FIRST of the n parameters optional: \cmd is
\@Protected@testopt, which supplies {default} when no [ follows (latex.ltx:1187-1199,
\@xargdef), and the remaining n-1 are grabbed as usual. The token path already does
this (engine.go's optArg/optDefault); the maths source path read all n as MANDATORY.
That is worse than not expanding at all. With the optional argument written out the
macro still "matched", by taking the brackets themselves as arguments:
\qbin [p]{N}{k} -> \genfrac []{0pt}{}{p}{]}_{[}{N}{k}
\qbin {N}{k}+1 -> \genfrac []{0pt}{}{k}{+}_{N}1
so the formula came out silently wrong, the + of an expression becoming an argument.
Without it, nothing matched and the formula was dropped — which is how a paper's own
\newcommand{\qbinom}[3][q]{\genfrac[]{0pt}{}{#2}{#3}_{#1}} lost 12 equations.
Measured over 200 arXiv papers and 200 beamer talks: 5 documents change for +1234
glyphs. One repaginates, 362 -> 363 against tectonic's 333 — a document already 29
pages long of it — and the page error against the 157 renders moves 669 -> 670.
beamer does not move by one glyph.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
\newcommand{\cmd}[n][default]makes the first of the n parameters optional:\cmdis\@protected@testopt, which supplies{default}when no[follows (latex.ltx:1187-1199,\@xargdef), and the remaining n−1 are grabbed as usual. The token path already does this (optArg/optDefaultin engine.go); the maths source path read all n as mandatory.That is worse than not expanding at all. With the optional argument written out the macro still "matched", by taking the brackets themselves as arguments:
— the formula came out silently wrong, the
+of an expression becoming an argument. Without the optional argument nothing matched and the formula was dropped instead, which is how a paper's ownlost 12 equations.
Measured — 200 arXiv papers, 200 beamer talks
5 documents change for +1234 glyphs. One repaginates, 362 → 363 against tectonic's 333 — a document already 29 pages clear of it — and the page error against the 157 renders moves 669 → 670. beamer does not move by one glyph.
Test
mathoptarg_test.goasserts the expansions themselves, since that is where the corruption is visible; all three fail onmainwith the stolen-bracket strings above. A second test takes it end to end: the formula must reach the page with the text around it.