(context, args)
| 9700 | |
| 9701 | |
| 9702 | var array_alignedHandler = function alignedHandler(context, args) { |
| 9703 | var cols = []; |
| 9704 | var res = parseArray(context.parser, { |
| 9705 | cols: cols, |
| 9706 | addJot: true |
| 9707 | }, "display"); // Determining number of columns. |
| 9708 | // 1. If the first argument is given, we use it as a number of columns, |
| 9709 | // and makes sure that each row doesn't exceed that number. |
| 9710 | // 2. Otherwise, just count number of columns = maximum number |
| 9711 | // of cells in each row ("aligned" mode -- isAligned will be true). |
| 9712 | // |
| 9713 | // At the same time, prepend empty group {} at beginning of every second |
| 9714 | // cell in each row (starting with second cell) so that operators become |
| 9715 | // binary. This behavior is implemented in amsmath's \start@aligned. |
| 9716 | |
| 9717 | var numMaths; |
| 9718 | var numCols = 0; |
| 9719 | var emptyGroup = { |
| 9720 | type: "ordgroup", |
| 9721 | mode: context.mode, |
| 9722 | body: [] |
| 9723 | }; |
| 9724 | var ordgroup = checkNodeType(args[0], "ordgroup"); |
| 9725 | |
| 9726 | if (ordgroup) { |
| 9727 | var arg0 = ""; |
| 9728 | |
| 9729 | for (var i = 0; i < ordgroup.body.length; i++) { |
| 9730 | var textord = assertNodeType(ordgroup.body[i], "textord"); |
| 9731 | arg0 += textord.text; |
| 9732 | } |
| 9733 | |
| 9734 | numMaths = Number(arg0); |
| 9735 | numCols = numMaths * 2; |
| 9736 | } |
| 9737 | |
| 9738 | var isAligned = !numCols; |
| 9739 | res.body.forEach(function (row) { |
| 9740 | for (var _i = 1; _i < row.length; _i += 2) { |
| 9741 | // Modify ordgroup node within styling node |
| 9742 | var styling = assertNodeType(row[_i], "styling"); |
| 9743 | |
| 9744 | var _ordgroup = assertNodeType(styling.body[0], "ordgroup"); |
| 9745 | |
| 9746 | _ordgroup.body.unshift(emptyGroup); |
| 9747 | } |
| 9748 | |
| 9749 | if (!isAligned) { |
| 9750 | // Case 1 |
| 9751 | var curMaths = row.length / 2; |
| 9752 | |
| 9753 | if (numMaths < curMaths) { |
| 9754 | throw new src_ParseError("Too many math in a row: " + ("expected " + numMaths + ", but got " + curMaths), row[0]); |
| 9755 | } |
| 9756 | } else if (numCols < row.length) { |
| 9757 | // Case 2 |
| 9758 | numCols = row.length; |
| 9759 | } |
nothing calls this directly
no test coverage detected