Properly handle comments in arguments and other places, and spaces in macro templates. (mathjax/MathJax#3577) - #1539
Open
dpvc wants to merge 1 commit into
Open
Properly handle comments in arguments and other places, and spaces in macro templates. (mathjax/MathJax#3577)#1539dpvc wants to merge 1 commit into
dpvc wants to merge 1 commit into
Conversation
…aces properly in macro templates. (mathjax/MathJax#3577)
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1539 +/- ##
==========================================
Coverage 86.93% 86.93%
==========================================
Files 388 388
Lines 87571 87663 +92
Branches 3290 4984 +1694
==========================================
+ Hits 76129 76210 +81
+ Misses 11442 11432 -10
- Partials 0 21 +21 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
This PR brings MathJax's handing of percent-sign comments for macros more in line with actual LaTeX, both in terms of calling a macro and defining one. In the past, percent signs could be part of a template macro's delimiter strings, and multiple spaces counted as significant in the template, but in actual LaTeX, percent signs act as comments within the template (the content is not part of the template) and multiple spaces are collapsed. Also, when calling a macro, percent signs were not properly acting as comments within the arguments.
These issues are resolved here, but since this could be a breaking change to existing content, two new options are added,
legacyCommentsandlegacyTemplateMacrosto control whether the new processing or the legacy processing is to be performed.Resolves issue mathjax/MathJax#3577.
Details
A number of tests needed to be added to cover the new functionality, and some old tests were updated that operate differently under the new comment processing. In
ConfigMacros.test.tstherunMacroTests()method doesn't need to run two tests, since the results are compared to snapshots rather than to each other, as they were in the past. That means the control test doesn't actually have to be performed, so it (and its parameter) is removed.The new options are added in the
input/tex.tsfile.In
input/tex/NodeUtil.ts,setAttribute()andsetProperty()now use the more-appropriatePropertytype rather thanArgs, since that's what the node's property object uses, and becauseArgsneeds to be more general in order to handle the new approach to template macros.Much of the work for percent signs is done in
input/tex/TexParser.ts. TheGetNext()macro now handles removing comments, so that everything that usesGetNext()will properly handle comments. (We then adjust other functions that used to walk the TeX string by hand to now useGetNext().) A newclipComment()function is used to remove a comment from the input string. A newunescapePercents()is defined for use in handling arguments that are not further processed as TeX, like the contents of\mmlTokencommands, so you can do\mmlToken{mo}{\%}to get<mo>%</mo>, or\mmlToken{text}{\\\%}to get<mtext>\%</mtext>.The
GetNext(),GetArgument(), andGetBrackets()functions take a new boolean argument that determines if the new percent-processing rules are to be used. (This allows thelegacyCommentsoption to get the old behavior.)The extra
returnvalues are to avoid a warning that the function doesn't always have a return value. I don't like it, but I don't think it hurts.In
input/tex/Types.ts, theArgstype is extended to allowstring[]values. These are needed for template macros, which now use an array of tokens to look for rather than a fixed string. That allows multiple spaces to be collapsed, and comments to be removed from both the template itself, and the usage within a macro call.In
input/tex/base/BaseItems.ts, thegetEntry()macro, which scans ahead for the end of the entry, now skips comments properly. (This isn't currently controlled bylegacyComments, but I suppose it should be.)In
input/tex/base/BaseMethods.ts, the\mmlTokenargument handles escaped percents. The loop in theEntry()method is modified to useGetNext()in order to handle comments. That means that we have to switch the roles ofiandparser.i, sinceGetNext()usesparser.i.The
input/tex/bbox/BBoxConfiguration.tsfile handles escaped percents in its argument (because it allows CSS specifier that might need to be percentages).The loop in
input/tex/cases/CasesConfiguration.tsis modified to useGetNext()as above, again requiring thatiandparser.ibe swapped.In
input/tex/configmacros/ConfigMacrosConfiguration.ts, if a macro is a templated one (def[2] is an array), we tokenize the elements in the array, since that is how the macro templates are now stored.In
input/tex/html/HtmlMethods.ts, the arguments are now processed for escaped percents, other than the CSS id, which is take verbatim. (I'm not sure why I did that, but it probably should be unescaped as well. Perhaps I just missed it when I added the service routine.)In
input/tex/newcommand/NewcommandMethods.ts, I replace ax ? y() : z()construct with an if-then. The other change is to use template token arrays rather than template strings. This uses the updatesgetParameter()call rather than the (removed)MatchParam()method (seeNewcommandUtil.tsbelow).The main changes are in
input/tex/newcommand/NewcommandMethods.ts. Here we add methods for tokenizing a string that acts as one of the template separators. The tokens newlines converted to space, multiple spaces collapsed to one, and only a single (actual) space at the end.Uses of
thiswere changes toNewcommandUtilfor consistency.The
GetTemplate()method is modified to return the parameter separators as token arrays instead of a single string. The loop is reorganized a bit to accommodate that.The
GetParameter()method is likewise modified in order to accept arrays of tokens instead of strings, and to look through the input string by tokens rather than looking for the exact string. That lets it handle comments and multiple spaces.The
SetOptionsmethod ininput/tex/setoptions/SetOptionsConfiguration.tshandles escaped percent signs, since the option may need a percentage (e.g., for multline widths).Finally, the loop in
input/tex/verb/VerbConfiguration.tsis modified to useGetNext(false). This allows you to do\verb|%|to get a monospaced percent sign, but note that you can't do this inside a macro definition, or within an argument that is passed to a macro, as the percent would eb traded as a comment in those cases. This is consistent with actual LaTeX.