\color affects following \right, put array cells in their own groups (#1845)

* \color affects following \right

Fix #1844 by giving `leftright` nodes a `rightColor` attribute for how
to color the right bracket.  Now `\color` sets the macro
`\current@color` in the current environment (in particular, resetting
after `\right`), just like `color.sty` does in LaTeX.  This is used to
specially pass the current color into any following `\right` and then
into the `leftright` parse node.

* Add test

* Put each array cell in its own group/namespace

* Improve cell group isolation, add test and TODO

* Improve comments
This commit is contained in:
Erik Demaine
2019-07-05 00:27:55 -04:00
committed by Kevin Barabash
parent 39da3f5119
commit 19d9d83ad3
8 changed files with 58 additions and 4 deletions

View File

@@ -145,10 +145,16 @@ defineFunction({
// \left case below triggers parsing of \right in
// `const right = parser.parseFunction();`
// uses this return value.
const color = context.parser.gullet.macros.get("\\current@color");
if (color && typeof color !== "string") {
throw new ParseError(
"\\current@color set to non-string in \\right");
}
return {
type: "leftright-right",
mode: context.parser.mode,
delim: checkDelimiter(args[0], context).text,
color, // undefined if not set via \color
};
},
});
@@ -178,6 +184,7 @@ defineFunction({
body,
left: delim.text,
right: right.delim,
rightColor: right.color,
};
},
htmlBuilder: (group, options) => {
@@ -241,12 +248,14 @@ defineFunction({
}
let rightDelim;
// Same for the right delimiter
// Same for the right delimiter, but using color specified by \color
if (group.right === ".") {
rightDelim = html.makeNullDelimiter(options, ["mclose"]);
} else {
const colorOptions = group.rightColor ?
options.withColor(group.rightColor) : options;
rightDelim = delimiter.leftRightDelim(
group.right, innerHeight, innerDepth, options,
group.right, innerHeight, innerDepth, colorOptions,
group.mode, ["mclose"]);
}
// Add it to the end of the expression.
@@ -273,6 +282,10 @@ defineFunction({
rightNode.setAttribute("fence", "true");
if (group.rightColor) {
rightNode.setAttribute("mathcolor", group.rightColor);
}
inner.push(rightNode);
}