mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-05 11:18:39 +00:00
Add \jot lineskip to aligned environment, switch contents to displaystyle, and add gathered (#725)
This commit is contained in:
committed by
Kevin Barabash
parent
95af9379da
commit
06d6c96894
@@ -592,6 +592,9 @@ groupTypes.array = function(group, options) {
|
||||
|
||||
// Vertical spacing
|
||||
const baselineskip = 12 * pt; // see size10.clo
|
||||
// Default \jot from ltmath.dtx
|
||||
// TODO(edemaine): allow overriding \jot via \setlength (#687)
|
||||
const jot = 3 * pt;
|
||||
// Default \arraystretch from lttab.dtx
|
||||
// TODO(gagern): may get redefined once we have user-defined macros
|
||||
const arraystretch = utils.deflt(group.value.arraystretch, 1);
|
||||
@@ -632,6 +635,12 @@ groupTypes.array = function(group, options) {
|
||||
gap = 0;
|
||||
}
|
||||
}
|
||||
// In AMS multiline environments such as aligned and gathered, rows
|
||||
// correspond to lines that have additional \jot added to the
|
||||
// \baselineskip via \openup.
|
||||
if (group.value.addJot) {
|
||||
depth += jot;
|
||||
}
|
||||
|
||||
outrow.height = height;
|
||||
outrow.depth = depth;
|
||||
|
@@ -216,13 +216,20 @@ defineEnvironment("aligned", {
|
||||
let res = {
|
||||
type: "array",
|
||||
cols: [],
|
||||
addJot: true,
|
||||
};
|
||||
res = parseArray(context.parser, res);
|
||||
res = parseArray(context.parser, res, "display");
|
||||
// Count number of columns = maximum number of cells in each row.
|
||||
// At the same time, prepend empty group {} at beginning of every second
|
||||
// cell in each row (starting with second cell) so that operators become
|
||||
// binary. This behavior is implemented in amsmath's \start@aligned.
|
||||
const emptyGroup = new ParseNode("ordgroup", [], context.mode);
|
||||
let numCols = 0;
|
||||
res.value.body.forEach(function(row) {
|
||||
for (let i = 1; i < row.length; i += 2) {
|
||||
row[i].value.unshift(emptyGroup);
|
||||
// Modify ordgroup node within styling node
|
||||
const ordgroup = row[i].value.value[0];
|
||||
ordgroup.value.unshift(emptyGroup);
|
||||
}
|
||||
if (numCols < row.length) {
|
||||
numCols = row.length;
|
||||
@@ -245,3 +252,20 @@ defineEnvironment("aligned", {
|
||||
}
|
||||
return res;
|
||||
});
|
||||
|
||||
// A gathered environment is like an array environment with one centered
|
||||
// column, but where rows are considered lines so get \jot line spacing
|
||||
// and contents are set in \displaystyle.
|
||||
defineEnvironment("gathered", {
|
||||
}, function(context) {
|
||||
let res = {
|
||||
type: "array",
|
||||
cols: [{
|
||||
type: "align",
|
||||
align: "c",
|
||||
}],
|
||||
addJot: true,
|
||||
};
|
||||
res = parseArray(context.parser, res, "display");
|
||||
return res;
|
||||
});
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 9.4 KiB After Width: | Height: | Size: 9.4 KiB |
Binary file not shown.
Before Width: | Height: | Size: 8.8 KiB After Width: | Height: | Size: 8.8 KiB |
BIN
test/screenshotter/images/Gathered-chrome.png
Normal file
BIN
test/screenshotter/images/Gathered-chrome.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
BIN
test/screenshotter/images/Gathered-firefox.png
Normal file
BIN
test/screenshotter/images/Gathered-firefox.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
@@ -73,6 +73,15 @@ DisplayStyle: |
|
||||
Exponents: a^{a^a_a}_{a^a_a}
|
||||
FractionTest: \dfrac{a}{b}\frac{a}{b}\tfrac{a}{b}\;-\dfrac12\;1\tfrac12\;{1 \atop 2}
|
||||
Functions: \sin\cos\tan\ln\log
|
||||
Gathered: |
|
||||
\begin{gathered}
|
||||
x = \frac{1}{2} \\
|
||||
y = \sum_{i=1}^n i
|
||||
\end{gathered} \approx
|
||||
\begin{array}{c}
|
||||
x = \frac{1}{2} \\
|
||||
y = \sum_{i=1}^n i
|
||||
\end{array}
|
||||
GreekLetters: \alpha\beta\gamma\omega
|
||||
GroupMacros:
|
||||
macros:
|
||||
|
Reference in New Issue
Block a user