Skip to content

Single-symbol macro arguments #1027

@edemaine

Description

@edemaine

PR #1024 added support for detecting text or math mode (e.g. via \TextOrMath) within a macro, not just in the parser. There is one edge case that doesn't work yet: in a function's argument that has a specified argument type (math or text) and when that argument is given by a single-symbol macro.

For example, test/katex-spec.js has a commented-out test that should work but doesn't:

    it("\\TextOrMath should work in a macro passed to \\text", function() {
        compareParseTree("\\text\\mode", "\\text{text}",
            {"\\mode": "\\TextOrMath{text}{math}"});
    });

This test has two issues. Because of #924, only the first letter of \mode gets passed to the \text function. Because of this issue, that letter is m instead of t, because the mode gets set right after \mode gets expanded by the MacroExpander. The offender is the else case of parseGroup (when it gets called by parseGroupOfType, but to fix this, we'll have to avoid having already read the symbol by the time parseGroup gets called.

I'm hoping that both issues will be fixed by one idea: when the MacroExpander encounters a function (like \text), it should grab the arguments at the same time (and in the right mode), and return everything to the parser, instead of just the function token. This is probably roughly what TeX does too, for built-in commands.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions