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

Function parseArray

src/environments/array.ts:93–271  ·  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

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

Callers 2

alignedHandlerFunction · 0.85
handlerFunction · 0.85

Calls 13

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

Tested by

no test coverage detected