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.
This commit is contained in:
Martin von Gagern
2015-11-23 13:14:02 +01:00
parent b9c4237ac2
commit 8201501d77
5 changed files with 54 additions and 0 deletions

View File

@@ -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;
});