commit 8201501d770a9dd5a58af2f6023a1f85027f7aff
parent b9c4237ac23039e36a8852617ccd755054f1cd4e
Author: Martin von Gagern <gagern@ma.tum.de>
Date: Mon, 23 Nov 2015 13:14:02 +0100
Introduce an aligned environment
This is almost like the align* environment, but it starts out in math mode,
so we don't have to worry about the fact that we have no real surrounding
text mode in KaTeX. This is the first step towards align* and align.
Diffstat:
5 files changed, 54 insertions(+), 0 deletions(-)
diff --git a/src/environments.js b/src/environments.js
@@ -176,3 +176,43 @@ defineEnvironment("cases", {
}, context.mode);
return res;
});
+
+// An aligned environment is like the align* environment
+// except it operates within math mode.
+// Note that we assume \nomallineskiplimit to be zero,
+// so that \strut@ is the same as \strut.
+defineEnvironment("aligned", {
+}, function(context) {
+ var res = {
+ type: "array",
+ cols: []
+ };
+ res = parseArray(context.parser, res);
+ var emptyGroup = new ParseNode("ordgroup", [], context.mode);
+ var numCols = 0;
+ res.value.body.forEach(function(row) {
+ var i;
+ for (i = 1; i < row.length; i += 2) {
+ row[i].value.unshift(emptyGroup);
+ }
+ if (numCols < row.length) {
+ numCols = row.length;
+ }
+ });
+ for (var i = 0; i < numCols; ++i) {
+ var align = "r";
+ var pregap = 0;
+ if (i % 2 === 1) {
+ align = "l";
+ } else if (i > 0) {
+ pregap = 2; // one \qquad between columns
+ }
+ res.value.cols[i] = {
+ type: "align",
+ align: align,
+ pregap: pregap,
+ postgap: 0
+ };
+ }
+ return res;
+});
diff --git a/test/katex-spec.js b/test/katex-spec.js
@@ -1672,6 +1672,15 @@ describe("A cases environment", function() {
});
+describe("An aligned environment", function() {
+
+ it("should parse its input", function() {
+ expect("\\begin{aligned}a&=b&c&=d\\\\e&=f\\end{aligned}")
+ .toParse();
+ });
+
+});
+
var getMathML = function(expr, settings) {
var usedSettings = settings ? settings : defaultSettings;
diff --git a/test/screenshotter/images/Aligned-chrome.png b/test/screenshotter/images/Aligned-chrome.png
Binary files differ.
diff --git a/test/screenshotter/images/Aligned-firefox.png b/test/screenshotter/images/Aligned-firefox.png
Binary files differ.
diff --git a/test/screenshotter/ss_data.yaml b/test/screenshotter/ss_data.yaml
@@ -12,6 +12,11 @@
# on the next line. See http://www.yaml.org/ for syntax details.
Accents: \vec{A}\vec{x}\vec x^2\vec{x}_2^2\vec{A}^2\vec{xA}^2
+Aligned: |
+ \begin{aligned}
+ a &= 1 & b &= 2 \\
+ 3a &= 3 & 17b &= 34
+ \end{aligned}
Arrays: |
\left(\begin{array}{|rl|c||}
1&2&3\\