mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-05 03:08:40 +00:00
Implement \TextOrMath, \@secondoftwo (#1024)
* Implement \TextOrMath, \@secondoftwo * Parser now tells MacroExpander about mode switching. (This seems preferable to a circular reference between Parser and MacroExpander.) * Implement \TextOrMath * Improve when we switch modes so that this actually works, in all cases except single-symbol arguments. * Add \@secondoftwo to match \@firstoftwo. * Add comments documenting all the conditional macros * Define type for switchMode * Fix mode detection for ligatures * Switch mode before the call to parseSymbol() in parseGroup This fixes the Colorbox screenshot test.
This commit is contained in:
committed by
Kevin Barabash
parent
2d439f076a
commit
c30edaaf5b
@@ -2672,11 +2672,61 @@ describe("A macro expander", function() {
|
||||
expect("\\@ifnextchar!{yes}{no}?!").toParseLike("no?!");
|
||||
});
|
||||
|
||||
it("\\@firstoftwwo should consume star but nothing else", function() {
|
||||
it("\\@ifstar should consume star but nothing else", function() {
|
||||
expect("\\@ifstar{yes}{no}*!").toParseLike("yes!");
|
||||
expect("\\@ifstar{yes}{no}?!").toParseLike("no?!");
|
||||
});
|
||||
|
||||
it("\\TextOrMath should work immediately", function() {
|
||||
expect("\\TextOrMath{text}{math}").toParseLike("math");
|
||||
});
|
||||
|
||||
it("\\TextOrMath should work after other math", function() {
|
||||
expect("x+\\TextOrMath{text}{math}").toParseLike("x+math");
|
||||
});
|
||||
|
||||
it("\\TextOrMath should work immediately after \\text", function() {
|
||||
expect("\\text{\\TextOrMath{text}{math}}").toParseLike("\\text{text}");
|
||||
});
|
||||
|
||||
it("\\TextOrMath should work later after \\text", function() {
|
||||
expect("\\text{hello \\TextOrMath{text}{math}}")
|
||||
.toParseLike("\\text{hello text}");
|
||||
});
|
||||
|
||||
it("\\TextOrMath should work immediately after \\text ends", function() {
|
||||
expect("\\text{\\TextOrMath{text}{math}}\\TextOrMath{text}{math}")
|
||||
.toParseLike("\\text{text}math");
|
||||
});
|
||||
|
||||
it("\\TextOrMath should work immediately after $", function() {
|
||||
expect("\\text{$\\TextOrMath{text}{math}$}")
|
||||
.toParseLike("\\text{$math$}");
|
||||
});
|
||||
|
||||
it("\\TextOrMath should work later after $", function() {
|
||||
expect("\\text{$x+\\TextOrMath{text}{math}$}")
|
||||
.toParseLike("\\text{$x+math$}");
|
||||
});
|
||||
|
||||
it("\\TextOrMath should work immediately after $ ends", function() {
|
||||
expect("\\text{$\\TextOrMath{text}{math}$\\TextOrMath{text}{math}}")
|
||||
.toParseLike("\\text{$math$text}");
|
||||
});
|
||||
|
||||
it("\\TextOrMath should work in a macro", function() {
|
||||
compareParseTree("\\mode\\text{\\mode$\\mode$\\mode}\\mode",
|
||||
"math\\text{text$math$text}math",
|
||||
{"\\mode": "\\TextOrMath{text}{math}"});
|
||||
});
|
||||
|
||||
// TODO(edemaine): This doesn't work yet. Parses like `\text math`,
|
||||
// which doesn't even treat all four letters as an argument.
|
||||
//it("\\TextOrMath should work in a macro passed to \\text", function() {
|
||||
// compareParseTree("\\text\\mode", "\\text{text}",
|
||||
// {"\\mode": "\\TextOrMath{text}{math}"});
|
||||
//});
|
||||
|
||||
// This may change in the future, if we support the extra features of
|
||||
// \hspace.
|
||||
it("should treat \\hspace, \\hspace*, \\hskip like \\kern", function() {
|
||||
|
Reference in New Issue
Block a user