Support \brace and \brack (#1453)

* Support \brace and \brack

* Update screenshots
This commit is contained in:
Ron Kok
2018-06-27 11:43:02 -07:00
committed by ylemkimon
parent 518379aed5
commit 8621f5b76a
5 changed files with 54 additions and 3 deletions

View File

@@ -15,6 +15,7 @@ defineFunction({
"\\cfrac", "\\dfrac", "\\frac", "\\tfrac",
"\\dbinom", "\\binom", "\\tbinom",
"\\\\atopfrac", // cant be entered directly
"\\\\bracefrac", "\\\\brackfrac", // ditto
],
props: {
numArgs: 2,
@@ -45,6 +46,16 @@ defineFunction({
leftDelim = "(";
rightDelim = ")";
break;
case "\\\\bracefrac":
hasBarLine = false;
leftDelim = "\\{";
rightDelim = "\\}";
break;
case "\\\\brackfrac":
hasBarLine = false;
leftDelim = "[";
rightDelim = "]";
break;
default:
throw new Error("Unrecognized genfrac command");
}
@@ -272,7 +283,7 @@ defineFunction({
// immediately by one of the variants above.
defineFunction({
type: "infix",
names: ["\\over", "\\choose", "\\atop"],
names: ["\\over", "\\choose", "\\atop", "\\brace", "\\brack"],
props: {
numArgs: 0,
infix: true,
@@ -289,6 +300,12 @@ defineFunction({
case "\\atop":
replaceWith = "\\\\atopfrac";
break;
case "\\brace":
replaceWith = "\\\\bracefrac";
break;
case "\\brack":
replaceWith = "\\\\brackfrac";
break;
default:
throw new Error("Unrecognized infix genfrac command");
}

View File

@@ -477,13 +477,17 @@ describe("A frac parser", function() {
});
});
describe("An over parser", function() {
describe("An over/brace/brack parser", function() {
const simpleOver = "1 \\over x";
const complexOver = "1+2i \\over 3+4i";
const braceFrac = "a+b \\brace c+d";
const brackFrac = "a+b \\brack c+d";
it("should not fail", function() {
expect(simpleOver).toParse();
expect(complexOver).toParse();
expect(braceFrac).toParse();
expect(brackFrac).toParse();
});
it("should produce a frac", function() {
@@ -500,6 +504,22 @@ describe("An over parser", function() {
expect(parse.type).toEqual("genfrac");
expect(parse.value.numer).toBeDefined();
expect(parse.value.denom).toBeDefined();
const parseBraceFrac = getParsed(braceFrac)[0];
expect(parseBraceFrac.type).toEqual("genfrac");
expect(parseBraceFrac.value.numer).toBeDefined();
expect(parseBraceFrac.value.denom).toBeDefined();
expect(parseBraceFrac.value.leftDelim).toBeDefined();
expect(parseBraceFrac.value.rightDelim).toBeDefined();
const parseBrackFrac = getParsed(brackFrac)[0];
expect(parseBrackFrac.type).toEqual("genfrac");
expect(parseBrackFrac.value.numer).toBeDefined();
expect(parseBrackFrac.value.denom).toBeDefined();
expect(parseBrackFrac.value.leftDelim).toBeDefined();
expect(parseBrackFrac.value.rightDelim).toBeDefined();
});
it("should create a numerator from the atoms before \\over", function() {
@@ -567,6 +587,16 @@ describe("An over parser", function() {
});
});
describe("A infix builder", function() {
it("should not fail", function() {
expect("a \\over b").toBuild();
expect("a \\atop b").toBuild();
expect("a \\choose b").toBuild();
expect("a \\brace b").toBuild();
expect("a \\brack b").toBuild();
});
});
describe("A sizing parser", function() {
const sizeExpression = "\\Huge{x}\\small{x}";

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.0 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -113,7 +113,11 @@ ExtensibleArrows: |
\xrightleftharpoons[ab]{ABC} + \xhookrightarrow[ab]{ABC} \\
\xtwoheadrightarrow{ABC} + \frac{\xrightarrow[ab]{ABC}}{\xrightarrow[ab]{ABC}} + \left\lvert\xrightarrow[ab]{ABC}\right\rvert
\end{array}
FractionTest: \dfrac{a}{b}\frac{a}{b}\tfrac{a}{b}\;-\dfrac12\;1\tfrac12\;{1 \atop 2}\; \cfrac{1}{1+\cfrac{1}{x}}
FractionTest: |
\begin{array}{l}
\dfrac{a}{b}\frac{a}{b}\tfrac{a}{b}\;-\dfrac12\;1\tfrac12\;{1 \atop 2}\; \cfrac{1}{1+\cfrac{1}{x}} \\[2.5em]
{a \brace b} \; {a \brack b}
\end{array}
Functions: \sin\cos\tan\ln\log
Gathered: |
\begin{gathered}