\hspace*, \@ifstar, \@ifnextchar, \@firstoftwo (#975)

* \hspace*, \@ifstar, \@ifnextchar, \@firstoftwo

* Support both \hspace and \hspace* (still aliasing to \kern)
  using new \@ifstar
* \@ifstar is a macro using new \@ifnextchar and \@firstoftwo
  (same definition as LaTeX)
* \@firstoftwo and \@ifnextchar use available MacroParser features
  to act as they do in LaTeX.
* Also new method pushTokens (which I almost used but didn't end up),
  and moved pushToken next to it and popToken.

* Fix flow errors; generalize MacroDefinition

* Add tests for macros
This commit is contained in:
Erik Demaine
2017-11-24 14:48:04 -05:00
committed by Kevin Barabash
parent c8249c389f
commit e93668c666
3 changed files with 115 additions and 44 deletions

View File

@@ -2639,6 +2639,33 @@ describe("A macro expander", function() {
"": "'",
});
});
it("\\@firstoftwo should consume both, and avoid errors", function() {
expect("\\@firstoftwo{yes}{no}").toParseLike("yes");
expect("\\@firstoftwo{yes}{1'_2^3}").toParseLike("yes");
});
it("\\@ifstar should consume star but nothing else", function() {
expect("\\@ifstar{yes}{no}*!").toParseLike("yes!");
expect("\\@ifstar{yes}{no}?!").toParseLike("no?!");
});
it("\\@ifnextchar should not consume anything", function() {
expect("\\@ifnextchar!{yes}{no}!!").toParseLike("yes!!");
expect("\\@ifnextchar!{yes}{no}?!").toParseLike("no?!");
});
it("\\@firstoftwwo should consume star but nothing else", function() {
expect("\\@ifstar{yes}{no}*!").toParseLike("yes!");
expect("\\@ifstar{yes}{no}?!").toParseLike("no?!");
});
// This may change in the future, if we support the extra features of
// \hspace.
it("should treat \\hspace, \\hspace*, \\hskip like \\kern", function() {
expect("\\hspace{1em}").toParseLike("\\kern1em");
expect("\\hspace*{1em}").toParseLike("\\kern1em");
});
});
describe("A parser taking String objects", function() {