Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update newcommand to handle delimiters vs macros better, and add tests #1165

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

dpvc
Copy link
Member

@dpvc dpvc commented Nov 16, 2024

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() and addDelimiter() methods in NewcommandUtil 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 main delimiter 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 the applicable() method. These are the changes in the MapHandler.ts file.

The structure of the Let() method in NewcommandMethods.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 produce Wrong! 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 produce X 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.

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