(context, args)
| 9550 | |
| 9551 | |
| 9552 | const alignedHandler = function alignedHandler(context, args) { |
| 9553 | const cols = []; |
| 9554 | const res = parseArray(context.parser, { |
| 9555 | cols, |
| 9556 | addJot: true |
| 9557 | }, "display"); // Determining number of columns. |
| 9558 | // 1. If the first argument is given, we use it as a number of columns, |
| 9559 | // and makes sure that each row doesn't exceed that number. |
| 9560 | // 2. Otherwise, just count number of columns = maximum number |
| 9561 | // of cells in each row ("aligned" mode -- isAligned will be true). |
| 9562 | // |
| 9563 | // At the same time, prepend empty group {} at beginning of every second |
| 9564 | // cell in each row (starting with second cell) so that operators become |
| 9565 | // binary. This behavior is implemented in amsmath's \start@aligned. |
| 9566 | |
| 9567 | let numMaths; |
| 9568 | let numCols = 0; |
| 9569 | const emptyGroup = { |
| 9570 | type: "ordgroup", |
| 9571 | mode: context.mode, |
| 9572 | body: [] |
| 9573 | }; |
| 9574 | const ordgroup = checkNodeType(args[0], "ordgroup"); |
| 9575 | |
| 9576 | if (ordgroup) { |
| 9577 | let arg0 = ""; |
| 9578 | |
| 9579 | for (let i = 0; i < ordgroup.body.length; i++) { |
| 9580 | const textord = assertNodeType(ordgroup.body[i], "textord"); |
| 9581 | arg0 += textord.text; |
| 9582 | } |
| 9583 | |
| 9584 | numMaths = Number(arg0); |
| 9585 | numCols = numMaths * 2; |
| 9586 | } |
| 9587 | |
| 9588 | const isAligned = !numCols; |
| 9589 | res.body.forEach(function (row) { |
| 9590 | for (let i = 1; i < row.length; i += 2) { |
| 9591 | // Modify ordgroup node within styling node |
| 9592 | const styling = assertNodeType(row[i], "styling"); |
| 9593 | const ordgroup = assertNodeType(styling.body[0], "ordgroup"); |
| 9594 | ordgroup.body.unshift(emptyGroup); |
| 9595 | } |
| 9596 | |
| 9597 | if (!isAligned) { |
| 9598 | // Case 1 |
| 9599 | const curMaths = row.length / 2; |
| 9600 | |
| 9601 | if (numMaths < curMaths) { |
| 9602 | throw new ParseError("Too many math in a row: " + `expected ${numMaths}, but got ${curMaths}`, row[0]); |
| 9603 | } |
| 9604 | } else if (numCols < row.length) { |
| 9605 | // Case 2 |
| 9606 | numCols = row.length; |
| 9607 | } |
| 9608 | }); // Adjusting alignment. |
| 9609 | // In aligned mode, we add one \qquad between columns; |
nothing calls this directly
no test coverage detected