Support \arraystretch as a macro definition (#1381)

* Support \arraystretch as a macro definition

Also add `expandMacro` and `expandMacroAsText` helpers to `MacroExpander`.

* Remove excess defaulting

* Add test
This commit is contained in:
Erik Demaine
2018-06-03 18:19:23 -04:00
committed by Kevin Barabash
parent 563b0d5f8f
commit fcb32f058b
5 changed files with 212 additions and 6 deletions

View File

@@ -25,7 +25,7 @@ type AlignSpec = { type: "separator", separator: string } | {
export type ArrayEnvNodeData = {|
type: "array",
hskipBeforeAndAfter?: boolean,
arraystretch?: number,
arraystretch: number,
addJot?: boolean,
cols?: AlignSpec[],
body: ParseNode<*>[][], // List of rows in the (2D) array.
@@ -71,6 +71,20 @@ function parseArray(
parser.gullet.beginGroup();
parser.gullet.macros.set("\\\\", "\\cr");
// Get current arraystretch if it's not set by the environment
if (!result.arraystretch) {
const arraystretch = parser.gullet.expandMacroAsText("\\arraystretch");
if (arraystretch == null) {
// Default \arraystretch from lttab.dtx
result.arraystretch = 1;
} else {
result.arraystretch = parseFloat(arraystretch);
if (!result.arraystretch || result.arraystretch < 0) {
throw new ParseError(`Invalid \\arraystretch: ${arraystretch}`);
}
}
}
let row = [];
const body = [row];
const rowGaps = [];
@@ -166,10 +180,7 @@ const htmlBuilder = function(group, options) {
// 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(groupValue.arraystretch, 1);
const arrayskip = arraystretch * baselineskip;
const arrayskip = groupValue.arraystretch * baselineskip;
const arstrutHeight = 0.7 * arrayskip; // \strutbox in ltfsstrc.dtx and
const arstrutDepth = 0.3 * arrayskip; // \@arstrutbox in lttab.dtx
@@ -358,7 +369,7 @@ const mathmlBuilder = function(group, options) {
}));
};
// Convinient function for aligned and alignedat environments.
// Convenience function for aligned and alignedat environments.
const alignedHandler = function(context, args) {
const cols = [];
let res = {