Advanced macro support and magic \dots (#794)

* Advanced macro support and magic \dots

* Fix \relax behavior

* Use \DOTSB in \iff, \implies, \impliedby

* Add multiple expansion test

* Implement some of @kevinbarash's comments

* More @kevinbarabash comments

* Token moved from merge

* Add type to defineMacro

* @flow
This commit is contained in:
Erik Demaine
2017-09-05 09:27:04 +09:00
committed by Kevin Barabash
parent 0c2dd845f3
commit 6857689946
8 changed files with 406 additions and 97 deletions

View File

@@ -783,6 +783,11 @@ describe("A text parser", function() {
it("should parse math within text group", function() {
expect(textWithEmbeddedMath).toParse();
});
it("should omit spaces after commands", function() {
expect("\\text{\\textellipsis !}")
.toParseLike("\\text{\\textellipsis!}");
});
});
describe("A color parser", function() {
@@ -2314,6 +2319,27 @@ describe("A macro expander", function() {
compareParseTree("e^\\foo", "e^1 23", {"\\foo": "123"});
});
it("should preserve leading spaces inside macro definition", function() {
compareParseTree("\\text{\\foo}", "\\text{ x}", {"\\foo": " x"});
});
it("should preserve leading spaces inside macro argument", function() {
compareParseTree("\\text{\\foo{ x}}", "\\text{ x}", {"\\foo": "#1"});
});
it("should ignore expanded spaces in math mode", function() {
compareParseTree("\\foo", "x", {"\\foo": " x"});
});
it("should consume spaces after macro", function() {
compareParseTree("\\text{\\foo }", "\\text{x}", {"\\foo": "x"});
});
it("should consume spaces between arguments", function() {
compareParseTree("\\text{\\foo 1 2}", "\\text{12end}", {"\\foo": "#1#2end"});
compareParseTree("\\text{\\foo {1} {2}}", "\\text{12end}", {"\\foo": "#1#2end"});
});
it("should allow for multiple expansion", function() {
compareParseTree("1\\foo2", "1aa2", {
"\\foo": "\\bar\\bar",
@@ -2321,6 +2347,41 @@ describe("A macro expander", function() {
});
});
it("should allow for multiple expansion with argument", function() {
compareParseTree("1\\foo2", "12222", {
"\\foo": "\\bar{#1}\\bar{#1}",
"\\bar": "#1#1",
});
});
it("should allow for macro argument", function() {
compareParseTree("\\foo\\bar", "(x)", {
"\\foo": "(#1)",
"\\bar": "x",
});
});
it("should allow for space macro argument (text version)", function() {
compareParseTree("\\text{\\foo\\bar}", "\\text{( )}", {
"\\foo": "(#1)",
"\\bar": " ",
});
});
it("should allow for space macro argument (math version)", function() {
compareParseTree("\\foo\\bar", "()", {
"\\foo": "(#1)",
"\\bar": " ",
});
});
it("should allow for empty macro argument", function() {
compareParseTree("\\foo\\bar", "()", {
"\\foo": "(#1)",
"\\bar": "",
});
});
it("should expand the \\overset macro as expected", function() {
expect("\\overset?=").toParseLike("\\mathop{=}\\limits^{?}");
expect("\\overset{x=y}{\sqrt{ab}}")

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

@@ -77,6 +77,11 @@ DisplayMode:
DisplayStyle: |
{\displaystyle\sqrt{x}}{\sqrt{x}}
{\displaystyle \frac12}{\frac12}{\displaystyle x^1_2}{x^1_2}
Dots: |
\begin{array}{l}
\cdots;\dots+\dots\int\dots,\dots \\
\cdots{};\ldots+\ldots\int\ldots,\ldots
\end{array}
Exponents: a^{a^a_a}_{a^a_a}
ExtensibleArrows: |
\begin{array}{l}