www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit f1c02226ccada3da62fef0aa91f7bbb4ab10a7cb
parent 38ba9f91877cdbc3b687de16803c41d6fffafb74
Author: Erik Demaine <edemaine@mit.edu>
Date:   Sun, 15 Jan 2017 16:17:45 -0500

Change cell style to 'text' in {array}, {matrix}, {cases}. Add {darray} and {dcases}. (#606)

* Change cell style to 'text' in {array}, {matrix}, {cases}.
* Add {darray} and {dcases} which use display style for their cells.
* Add ArrayMode test with \frac's inside {array} in display mode.

Diffstat:
Msrc/environments.js | 43++++++++++++++++++++++++++++++++++---------
Atest/screenshotter/images/ArrayMode-chrome.png | 0
Atest/screenshotter/images/ArrayMode-firefox.png | 0
Mtest/screenshotter/ss_data.yaml | 11++++++++++-
4 files changed, 44 insertions(+), 10 deletions(-)

diff --git a/src/environments.js b/src/environments.js @@ -8,15 +8,23 @@ const ParseNode = parseData.ParseNode; /** * Parse the body of the environment, with rows delimited by \\ and * columns delimited by &, and create a nested list in row-major order - * with one group per cell. + * with one group per cell. If given an optional argument style + * ("text", "display", etc.), then each cell is cast into that style. */ -function parseArray(parser, result) { +function parseArray(parser, result, style) { let row = []; const body = [row]; const rowGaps = []; while (true) { - const cell = parser.parseExpression(false, null); - row.push(new ParseNode("ordgroup", cell, parser.mode)); + let cell = parser.parseExpression(false, null); + cell = new ParseNode("ordgroup", cell, parser.mode); + if (style) { + cell = new ParseNode("styling", { + style: style, + value: [cell], + }, parser.mode); + } + row.push(cell); const next = parser.nextToken.text; if (next === "&") { parser.consume(); @@ -82,9 +90,21 @@ function defineEnvironment(names, props, handler) { } } +// Decides on a style for cells in an array according to whether the given +// environment name starts with the letter 'd'. +function dCellStyle(envName) { + if (envName.substr(0, 1) === "d") { + return "display"; + } else { + return "text"; + } +} + // Arrays are part of LaTeX, defined in lttab.dtx so its documentation // is part of the source2e.pdf file of LaTeX2e source documentation. -defineEnvironment("array", { +// {darray} is an {array} environment where cells are set in \displaystyle, +// as defined in nccmath.sty. +defineEnvironment(["array", "darray"], { numArgs: 1, }, function(context, args) { let colalign = args[0]; @@ -111,7 +131,7 @@ defineEnvironment("array", { cols: cols, hskipBeforeAndAfter: true, // \@preamble in lttab.dtx }; - res = parseArray(context.parser, res); + res = parseArray(context.parser, res, dCellStyle(context.envName)); return res; }); @@ -138,7 +158,7 @@ defineEnvironment([ type: "array", hskipBeforeAndAfter: false, // \hskip -\arraycolsep in amsmath }; - res = parseArray(context.parser, res); + res = parseArray(context.parser, res, dCellStyle(context.envName)); if (delimiters) { res = new ParseNode("leftright", { body: [res], @@ -152,7 +172,12 @@ defineEnvironment([ // A cases environment (in amsmath.sty) is almost equivalent to // \def\arraystretch{1.2}% // \left\{\begin{array}{@{}l@{\quad}l@{}} … \end{array}\right. -defineEnvironment("cases", { +// {dcases} is a {cases} environment where cells are set in \displaystyle, +// as defined in mathtools.sty. +defineEnvironment([ + "cases", + "dcases", +], { }, function(context) { let res = { type: "array", @@ -173,7 +198,7 @@ defineEnvironment("cases", { postgap: 0, }], }; - res = parseArray(context.parser, res); + res = parseArray(context.parser, res, dCellStyle(context.envName)); res = new ParseNode("leftright", { body: [res], left: "\\{", diff --git a/test/screenshotter/images/ArrayMode-chrome.png b/test/screenshotter/images/ArrayMode-chrome.png Binary files differ. diff --git a/test/screenshotter/images/ArrayMode-firefox.png b/test/screenshotter/images/ArrayMode-firefox.png Binary files differ. diff --git a/test/screenshotter/ss_data.yaml b/test/screenshotter/ss_data.yaml @@ -23,11 +23,20 @@ Arrays: | 1+1&2+1&3+1\cr1\over2&\scriptstyle 1/2&\frac12\\[1ex] \begin{pmatrix}x\\y\end{pmatrix}&0&\begin{vmatrix}a&b\\c&d\end{vmatrix} \end{array}\right] +ArrayMode: + tex: | + \begin{matrix} + \frac{\partial^2 f}{\partial x_1^2} & \frac{\partial^2 f}{\partial x_1\,\partial x_2} & \cdots & \frac{\partial^2 f}{\partial x_1\,\partial x_n} \\ + \frac{\partial^2 f}{\partial x_2\,\partial x_1} & \frac{\partial^2 f}{\partial x_2^2} & \cdots & \frac{\partial^2 f}{\partial x_2\,\partial x_n} \\ + \vdots & \vdots & \ddots & \vdots \\ + \frac{\partial^2 f}{\partial x_n\,\partial x_1} & \frac{\partial^2 f}{\partial x_n\,\partial x_2} & \cdots & \frac{\partial^2 f}{\partial x_n^2} + \end{matrix} + display: 1 ArrayType: 1\begin{array}{c}2\\3\end{array}4 Baseline: a+b-c\cdot d/e BasicTest: a BinCancellation: | - \begin{array}{ccc} + \begin{array}{cccc} +1 & 1+ & 1+1 & (,) \\ 1++1 & 3\times) & 1+, & \left(,\right) \end{array}