diff --git a/src/environments.js b/src/environments.js index 0c183f259..3fb0de6a6 100644 --- 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 index 30cf29798..d01b6724f 100644 --- 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 new file mode 100644 index 000000000..89e5899b3 Binary files /dev/null and b/test/screenshotter/images/Aligned-chrome.png differ diff --git a/test/screenshotter/images/Aligned-firefox.png b/test/screenshotter/images/Aligned-firefox.png new file mode 100644 index 000000000..a98cb816c Binary files /dev/null and b/test/screenshotter/images/Aligned-firefox.png differ diff --git a/test/screenshotter/ss_data.yaml b/test/screenshotter/ss_data.yaml index 2e45694a1..d5e8736fa 100644 --- 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\\