Skip to content

Commit

Permalink
feat: optional vertical alignment [t|b|c] for array environments
Browse files Browse the repository at this point in the history
Fixes #2172
Fixes #2760
  • Loading branch information
edemaine committed Aug 26, 2021
1 parent 4b62f19 commit 00d3d6d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/environments/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,21 @@ function parseArray(
const rowGaps = [];
const hLinesBeforeRow = [];

// Check for optional [t|b|c] vertical alignment argument
let verticalAlign = 'c';
const optArg = parser.parseGroupOfType(
"array vertical alignment", "raw", true);
const rawArg = optArg && assertNodeType(optArg, "raw");
if (rawArg) {
for (let i = 0; i < rawArg.string.length; ++i) {
const letter = rawArg.string[i];
if (letter === "t" || letter === "b" || letter === "c") {
verticalAlign = letter;
break;
}
}
}

// Test for \hline at the top of the array.
hLinesBeforeRow.push(getHLines(parser));

Expand Down Expand Up @@ -201,6 +216,7 @@ function parseArray(
mode: parser.mode,
addJot,
arraystretch,
verticalAlign,
body,
cols,
rowGaps,
Expand Down Expand Up @@ -333,7 +349,11 @@ const htmlBuilder: HtmlBuilder<"array"> = function(group, options) {
setHLinePos(hLinesBeforeRow[r + 1]);
}

const offset = totalHeight / 2 + options.fontMetrics().axisHeight;
const verticalAlign = group.verticalAlign;
const offset = options.fontMetrics().axisHeight +
(verticalAlign === 't' ? totalHeight :
verticalAlign === 'b' ? 0 :
/*verticalAlign == 'c'*/ totalHeight / 2);
const colDescriptions = group.cols || [];
const cols = [];
let colSep;
Expand Down
1 change: 1 addition & 0 deletions src/environments/cd.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export function parseCD(parser: Parser): ParseNode<"array"> {
mode: "math",
body,
arraystretch: 1,
verticalAlign: "c",
addJot: true,
rowGaps: [null],
cols,
Expand Down
1 change: 1 addition & 0 deletions src/parseNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type ParseNodeTypes = {
addJot?: boolean,
cols?: AlignSpec[],
arraystretch: number,
verticalAlign: "t" | "b" | "c",
body: AnyParseNode[][], // List of rows in the (2D) array.
rowGaps: (?Measurement)[],
hLinesBeforeRow: Array<boolean[]>,
Expand Down

0 comments on commit 00d3d6d

Please sign in to comment.