MCPcopy Create free account
hub / github.com/KaTeX/KaTeX / parseArray

Function parseArray

src/environments/array.ts:94–278  ·  view source on GitHub ↗

* 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: Parser,
    {
        hskipBeforeAndAfter,
        addJot,
        cols,
        arraystretch,
        colSeparationType,
        autoTag,
        singleRow,
        emptySingleRow,
        maxNumCols,
        leqno,
    }: {
        hskipBeforeAndAfter?: boolean;
        addJot?: boolean;
        cols?: AlignSpec[];
        arraystretch?: number;
        colSeparationType?: ColSeparationType;
        autoTag?: boolean | null | undefined;
        singleRow?: boolean;
        emptySingleRow?: boolean;
        maxNumCols?: number;
        leqno?: boolean;
    },
    style: StyleStr,
)

Source from the content-addressed store, hash-verified

92 * ("text", "display", etc.), then each cell is cast into that style.
93 */
94function parseArray(
95 parser: Parser,
96 {
97 hskipBeforeAndAfter,
98 addJot,
99 cols,
100 arraystretch,
101 colSeparationType,
102 autoTag,
103 singleRow,
104 emptySingleRow,
105 maxNumCols,
106 leqno,
107 }: {
108 hskipBeforeAndAfter?: boolean;
109 addJot?: boolean;
110 cols?: AlignSpec[];
111 arraystretch?: number;
112 colSeparationType?: ColSeparationType;
113 autoTag?: boolean | null | undefined;
114 singleRow?: boolean;
115 emptySingleRow?: boolean;
116 maxNumCols?: number;
117 leqno?: boolean;
118 },
119 style: StyleStr,
120): ParseNode<"array"> {
121 parser.gullet.beginGroup();
122 if (!singleRow) {
123 // \cr is equivalent to \\ without the optional size argument (see below)
124 // TODO: provide helpful error when \cr is used outside array environment
125 parser.gullet.macros.set("\\cr", "\\\\\\relax");
126 }
127
128 // Get current arraystretch if it's not set by the environment
129 if (!arraystretch) {
130 const stretch = parser.gullet.expandMacroAsText("\\arraystretch");
131 if (stretch == null) {
132 // Default \arraystretch from lttab.dtx
133 arraystretch = 1;
134 } else {
135 arraystretch = parseFloat(stretch);
136 if (!arraystretch || arraystretch < 0) {
137 throw new ParseError(`Invalid \\arraystretch: ${stretch}`);
138 }
139 }
140 }
141
142 // Start group for first cell
143 parser.gullet.beginGroup();
144
145 let row: AnyParseNode[] = [];
146 const body: AnyParseNode[][] = [row];
147 const rowGaps = [];
148 const hLinesBeforeRow = [];
149 const tags: Array<AnyParseNode[] | boolean> | undefined =
150 (autoTag != null ? [] : undefined);
151

Callers 2

alignedHandlerFunction · 0.85
handlerFunction · 0.85

Calls 13

handleStrictFunction · 0.90
beginRowFunction · 0.85
getHLinesFunction · 0.85
endRowFunction · 0.85
setMethod · 0.80
parseExpressionMethod · 0.80
fetchMethod · 0.80
consumeMethod · 0.80
parseSizeGroupMethod · 0.80
expandMacroAsTextMethod · 0.65
futureMethod · 0.65
beginGroupMethod · 0.45

Tested by

no test coverage detected