mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-05 11:18:39 +00:00
feat: support {align}, {align*}, {alignat}, and {alignat*} (#2341)
* Support {align}, {align*}, {alignat}, and {alignat*} * Specify display mode for screenshots * Add bogus screenshots * Some screenshotter progress * Update screenshots
This commit is contained in:
@@ -73,9 +73,11 @@ table td {
|
||||
|\alef|$\alef$||
|
||||
|\alefsym|$\alefsym$||
|
||||
|\aleph|$\aleph$||
|
||||
|{align}|<span style="color:firebrick;">Not supported</span>|see `{aligned}`|
|
||||
|{align}|$$\begin{align}a&=b+c\\d+e&=f\end{align}$$|`\begin{align}`<br> `a&=b+c \\`<br> `d+e&=f`<br>`\end{align}`|
|
||||
|{align\*}|$$\begin{align*}a&=b+c\\d+e&=f\end{align*}$$|`\begin{align*}`<br> `a&=b+c \\`<br> `d+e&=f`<br>`\end{align*}`|
|
||||
|{aligned}|$\begin{aligned}a&=b+c\\d+e&=f\end{aligned}$|`\begin{aligned}`<br> `a&=b+c \\`<br> `d+e&=f`<br>`\end{aligned}`|
|
||||
|{alignat}|<span style="color:firebrick;">Not supported</span>|see `{alignedat}`|
|
||||
|{alignat}|$$\begin{alignat}{2}10&x+&3&y=2\\3&x+&13&y=4\end{alignat}$$|`\begin{alignat}{2}`<br> `10&x+ &3&y = 2 \\`<br> ` 3&x+&13&y = 4`<br>`\end{alignat}`|
|
||||
|{alignat\*}|$$\begin{alignat*}{2}10&x+&3&y=2\\3&x+&13&y=4\end{alignat*}$$|`\begin{alignat*}{2}`<br> `10&x+ &3&y = 2 \\`<br> ` 3&x+&13&y = 4`<br>`\end{alignat*}`|
|
||||
|{alignedat}|$\begin{alignedat}{2}10&x+&3&y=2\\3&x+&13&y=4\end{alignedat}$|`\begin{alignedat}{2}`<br> `10&x+ &3&y = 2 \\`<br> ` 3&x+&13&y = 4`<br>`\end{alignedat}`|
|
||||
|\allowbreak|||
|
||||
|\Alpha|$\Alpha$||
|
||||
|
@@ -83,7 +83,9 @@ $( \big( \Big( \bigg( \Bigg($ `( \big( \Big( \bigg( \Bigg(`
|
||||
|$\begin{pmatrix} a & b \\ c & d \end{pmatrix}$ |`\begin{pmatrix}`<br> `a & b \\`<br> `c & d`<br>`\end{pmatrix}` |$\begin{bmatrix} a & b \\ c & d \end{bmatrix}$ | `\begin{bmatrix}`<br> `a & b \\`<br> `c & d`<br>`\end{bmatrix}`
|
||||
|$\begin{vmatrix} a & b \\ c & d \end{vmatrix}$ |`\begin{vmatrix}`<br> `a & b \\`<br> `c & d`<br>`\end{vmatrix}` |$\begin{Vmatrix} a & b \\ c & d \end{Vmatrix}$ |`\begin{Vmatrix}`<br> `a & b \\`<br> `c & d`<br>`\end{Vmatrix}`
|
||||
|$\begin{Bmatrix} a & b \\ c & d \end{Bmatrix}$ |`\begin{Bmatrix}`<br> `a & b \\`<br> `c & d`<br>`\end{Bmatrix}`|$\def\arraystretch{1.5}\begin{array}{c:c:c} a & b & c \\ \hline d & e & f \\ \hdashline g & h & i \end{array}$|`\def\arraystretch{1.5}`<br> `\begin{array}{c:c:c}`<br> `a & b & c \\ \hline`<br> `d & e & f \\`<br> `\hdashline`<br> `g & h & i`<br>`\end{array}`
|
||||
|$\begin{aligned} a&=b+c \\ d+e&=f \end{aligned}$ |`\begin{aligned}`<br> `a&=b+c \\`<br> `d+e&=f`<br>`\end{aligned}`|$\begin{alignedat}{2}10&x+&3&y=2\\3&x+&13&y=4\end{alignedat}$ |`\begin{alignedat}{2}`<br> `10&x+ &3&y = 2 \\`<br> ` 3&x+&13&y = 4`<br>`\end{alignedat}`
|
||||
|$$\begin{align} a&=b+c \\ d+e&=f \end{align}$$ |`\begin{align}`<br> `a&=b+c \\`<br> `d+e&=f`<br>`\end{align}`|$$\begin{alignat}{2}10&x+&3&y=2\\3&x+&13&y=4\end{alignat}$$ |
|
||||
|$$\begin{align*} a&=b+c \\ d+e&=f \end{align*}$$ |`\begin{align*}`<br> `a&=b+c \\`<br> `d+e&=f`<br>`\end{align*}`|$\begin{aligned} a&=b+c \\ d+e&=f \end{aligned}$ |`\begin{aligned}`<br> `a&=b+c \\`<br> `d+e&=f`<br>`\end{aligned}`|
|
||||
`\begin{alignedat}{2}`<br> `10&x+ &3&y = 2 \\`<br> ` 3&x+&13&y = 4`<br>`\end{alignedat}`|$\begin{alignedat}{2}10&x+&3&y=2\\3&x+&13&y=4\end{alignedat}$ |`\begin{alignedat}{2}`<br> `10&x+ &3&y = 2 \\`<br> ` 3&x+&13&y = 4`<br>`\end{alignedat}`
|
||||
|$$\begin{gather} a=b \\ e=b+c \end{gather}$$ |`\begin{gather}`<br> `a=b \\ `<br> `e=b+c`<br>`\end{gather}`|$\begin{gathered} a=b \\ e=b+c \end{gathered}$ |`\begin{gathered}`<br> `a=b \\ `<br> `e=b+c`<br>`\end{gathered}`|
|
||||
|$x = \begin{cases} a &\text{if } b \\ c &\text{if } d \end{cases}$ |`x = \begin{cases}`<br> `a &\text{if } b \\`<br> `c &\text{if } d`<br>`\end{cases}`|$\begin{rcases} a &\text{if } b \\ c &\text{if } d \end{rcases}⇒…$ |`\begin{rcases}`<br> `a &\text{if } b \\`<br> `c &\text{if } d`<br>`\end{rcases}⇒…`|
|
||||
|$\begin{smallmatrix} a & b \\ c & d \end{smallmatrix}$ | `\begin{smallmatrix}`<br> `a & b \\`<br> `c & d`<br>`\end{smallmatrix}` |||
|
||||
|
@@ -577,10 +577,30 @@ const mathmlBuilder: MathMLBuilder<"array"> = function(group, options) {
|
||||
return table;
|
||||
};
|
||||
|
||||
// Convenience function for aligned and alignedat environments.
|
||||
// Convenience function for align, align*, aligned, alignat, alignat*, alignedat.
|
||||
const alignedHandler = function(context, args) {
|
||||
if (context.envName.indexOf("ed") === -1) {
|
||||
// Check if this environment call is allowed.
|
||||
const settings = context.parser.settings;
|
||||
if (!settings.displayMode) {
|
||||
throw new ParseError(`{${context.envName}} cannot be used inline.`);
|
||||
} else if (settings.strict && !settings.topEnv) {
|
||||
settings.reportNonstrict("textEnv",
|
||||
`{${context.envName}} called from math mode.`);
|
||||
}
|
||||
}
|
||||
const cols = [];
|
||||
const res = parseArray(context.parser, {cols, addJot: true}, "display");
|
||||
const separationType = context.envName.indexOf("at") > -1 ? "alignat" : "align";
|
||||
const res = parseArray(context.parser,
|
||||
{
|
||||
cols,
|
||||
addJot: true,
|
||||
addEqnNum: context.envName === "align" || context.envName === "alignat",
|
||||
colSeparationType: separationType,
|
||||
leqno: context.parser.settings.leqno,
|
||||
},
|
||||
"display"
|
||||
);
|
||||
|
||||
// Determining number of columns.
|
||||
// 1. If the first argument is given, we use it as a number of columns,
|
||||
@@ -848,13 +868,15 @@ defineEnvironment({
|
||||
mathmlBuilder,
|
||||
});
|
||||
|
||||
// An aligned environment is like the align* environment
|
||||
// except it operates within math mode.
|
||||
// In the align environment, one uses ampersands, &, to specify number of
|
||||
// columns in each row, and to locate spacing between each column.
|
||||
// align gets automatic numbering. align* and aligned do not.
|
||||
// The alignedat environment can be used in math mode.
|
||||
// Note that we assume \nomallineskiplimit to be zero,
|
||||
// so that \strut@ is the same as \strut.
|
||||
defineEnvironment({
|
||||
type: "array",
|
||||
names: ["aligned"],
|
||||
names: ["align", "align*", "aligned"],
|
||||
props: {
|
||||
numArgs: 0,
|
||||
},
|
||||
@@ -903,10 +925,7 @@ defineEnvironment({
|
||||
// each columns.
|
||||
defineEnvironment({
|
||||
type: "array",
|
||||
names: ["alignedat"],
|
||||
// One for numbered and for unnumbered;
|
||||
// but, KaTeX doesn't supports math numbering yet,
|
||||
// they make no difference for now.
|
||||
names: ["alignat", "alignat*", "alignedat"],
|
||||
props: {
|
||||
numArgs: 1,
|
||||
},
|
||||
|
@@ -2726,25 +2726,26 @@ describe("An aligned environment", function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("A gather environment", function() {
|
||||
describe("AMS environments", function() {
|
||||
const nonStrictDisplay = new Settings({displayMode: true, strict: false});
|
||||
|
||||
it("should fail outside display mode", () => {
|
||||
expect`\begin{gather}a+b\\c+d\end{gather}`.not.toParse(nonstrictSettings);
|
||||
});
|
||||
|
||||
it("should fail outside display mode", () => {
|
||||
expect`\begin{gather*}a+b\\c+d\end{gather*}`.not.toParse(nonstrictSettings);
|
||||
expect`\begin{align}a&=b+c\\d+e&=f\end{align}`.not.toParse(nonstrictSettings);
|
||||
expect`\begin{align*}a&=b+c\\d+e&=f\end{align*}`.not.toParse(nonstrictSettings);
|
||||
expect`\begin{alignat}{2}10&x+ &3&y = 2\\3&x+&13&y = 4\end{alignat}`.not.toParse(nonstrictSettings);
|
||||
expect`\begin{alignat*}{2}10&x+ &3&y = 2\\3&x+&13&y = 4\end{alignat*}`.not.toParse(nonstrictSettings);
|
||||
});
|
||||
|
||||
it("should build if in display mode", () => {
|
||||
it("should build if in non-strict display mode", () => {
|
||||
expect`\begin{gather}a+b\\c+d\end{gather}`.toBuild(nonStrictDisplay);
|
||||
});
|
||||
|
||||
it("should build if in display mode", () => {
|
||||
expect`\begin{gather*}a+b\\c+d\end{gather*}`.toBuild(nonStrictDisplay);
|
||||
expect`\begin{align}a&=b+c\\d+e&=f\end{align}`.toBuild(nonStrictDisplay);
|
||||
expect`\begin{align*}a&=b+c\\d+e&=f\end{align*}`.toBuild(nonStrictDisplay);
|
||||
expect`\begin{alignat}{2}10&x+ &3&y = 2\\3&x+&13&y = 4\end{alignat}`.toBuild(nonStrictDisplay);
|
||||
expect`\begin{alignat*}{2}10&x+ &3&y = 2\\3&x+&13&y = 4\end{alignat*}`.toBuild(nonStrictDisplay);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("operatorname support", function() {
|
||||
|
BIN
test/screenshotter/images/Align-chrome.png
Normal file
BIN
test/screenshotter/images/Align-chrome.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
BIN
test/screenshotter/images/Align-firefox.png
Normal file
BIN
test/screenshotter/images/Align-firefox.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
@@ -22,6 +22,9 @@ AccentsText: |
|
||||
\text{\'A} & \text{\.A} & \text{\`A} & \text{\"A} & \text{\H{A}} & \text{\r{A}} \\
|
||||
\text{\.I İ} & \text{\H e e̋} & \text{\i ı}
|
||||
\end{array}
|
||||
Align:
|
||||
tex: \begin{align}a &= 1 & b &= 2 \\ 3a &= 3 & 17b &= 34\end{align}
|
||||
display: 1
|
||||
Aligned: |
|
||||
\begin{aligned}
|
||||
a &= 1 & b &= 2 \\
|
||||
|
Reference in New Issue
Block a user