* 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. If given an optional argument style * ("text", "display", etc.), then each cell is cast into that style.
(parser, _ref, style)
| 9352 | |
| 9353 | |
| 9354 | function parseArray(parser, _ref, style) { |
| 9355 | var hskipBeforeAndAfter = _ref.hskipBeforeAndAfter, |
| 9356 | addJot = _ref.addJot, |
| 9357 | cols = _ref.cols, |
| 9358 | arraystretch = _ref.arraystretch; |
| 9359 | // Parse body of array with \\ temporarily mapped to \cr |
| 9360 | parser.gullet.beginGroup(); |
| 9361 | parser.gullet.macros.set("\\\\", "\\cr"); // Get current arraystretch if it's not set by the environment |
| 9362 | |
| 9363 | if (!arraystretch) { |
| 9364 | var stretch = parser.gullet.expandMacroAsText("\\arraystretch"); |
| 9365 | |
| 9366 | if (stretch == null) { |
| 9367 | // Default \arraystretch from lttab.dtx |
| 9368 | arraystretch = 1; |
| 9369 | } else { |
| 9370 | arraystretch = parseFloat(stretch); |
| 9371 | |
| 9372 | if (!arraystretch || arraystretch < 0) { |
| 9373 | throw new src_ParseError("Invalid \\arraystretch: " + stretch); |
| 9374 | } |
| 9375 | } |
| 9376 | } |
| 9377 | |
| 9378 | var row = []; |
| 9379 | var body = [row]; |
| 9380 | var rowGaps = []; |
| 9381 | var hLinesBeforeRow = []; // Test for \hline at the top of the array. |
| 9382 | |
| 9383 | hLinesBeforeRow.push(getHLines(parser)); |
| 9384 | |
| 9385 | while (true) { |
| 9386 | // eslint-disable-line no-constant-condition |
| 9387 | var cell = parser.parseExpression(false, "\\cr"); |
| 9388 | cell = { |
| 9389 | type: "ordgroup", |
| 9390 | mode: parser.mode, |
| 9391 | body: cell |
| 9392 | }; |
| 9393 | |
| 9394 | if (style) { |
| 9395 | cell = { |
| 9396 | type: "styling", |
| 9397 | mode: parser.mode, |
| 9398 | style: style, |
| 9399 | body: [cell] |
| 9400 | }; |
| 9401 | } |
| 9402 | |
| 9403 | row.push(cell); |
| 9404 | var next = parser.nextToken.text; |
| 9405 | |
| 9406 | if (next === "&") { |
| 9407 | parser.consume(); |
| 9408 | } else if (next === "\\end") { |
| 9409 | // Arrays terminate newlines with `\crcr` which consumes a `\cr` if |
| 9410 | // the last line is empty. |
| 9411 | // NOTE: Currently, `cell` is the last item added into `row`. |
no test coverage detected