commit 3a15a8402fb6fd80aa94b20131dcba0c293b2828
parent b9c4237ac23039e36a8852617ccd755054f1cd4e
Author: Kevin Barabash <kevinb7@gmail.com>
Date: Sat, 28 Nov 2015 11:20:04 -0800
Merge pull request #398 from gagern/aligned
Introduce an aligned environment
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\\