Update newcommand to handle delimiters vs macros better, and add tests #1165
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.
This PR fixes some problems with the
newcommand
package where definitions for macros and delimiters don't always stay synchronized (e.g.,\let\|=\sqrt \left\| X \right\|
should produce an error but doesn't currently).In order to manage this, the
addMacro()
andaddDelimiter()
methods inNewcommandUtil
are modified to keep the macro and delimiter mappings in sync. One approach would have been to delete a delimiter when a corresponding macro is defined, for instance; but we don't want to remove delimiters from the maindelimiter
mapping, as that is global, and might be in use by other TeX input jax. Had we done this, changes in one TeX input jax would affect all others. In particular, with the jest tests, where the TeX input has is re-instantiated for each test, would see previous tests affect later ones, for example.In order to avoid that problem, we the ability to have definitions that force the parsing of macros and delimiters to terminate and drop directly to the fallback method. For macros, if the parse function returns a new special symbol, that causes the parse loop to terminate early and go to the fallback method. For delimiters, if the character is
null
, that terminates the lookup in theapplicable()
method. These are the changes in theMapHandler.ts
file.The structure of the
Let()
method inNewcommandMethods.ts
is reorganized a bit to break out the various cases for the defining control sequence (macro vs. character vs. delimiter), and to include a new case where the macro becomes undefined (in the past,\def\test{\text{Wrong!}} \let\test=\undefined \test
would produceWrong!
rather than an undefined macro error, as it should).The case for a CharacterMap now excludes DelimiterMap, since something like
\let\test=<
would find the delimiter definition and use that to create\test
as a macro rather than a delimiter. For example,\def\test{X}\let\test=< \test
used to produceX
rather than⟨
.Finally, 17 new tests are added to check for the various interactions of macros and delimiters. With this PR, together with
fix/3300-tests
all the tests should now pass.