MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / wrap

Method wrap

src/compute-engine/latex-syntax/serializer.ts:142–181  ·  view source on GitHub ↗

* Serialize the expression, and if the expression is an operator * of precedence less than or equal to prec, wrap it in some parens. * * Skip wrapping for matchfix operators (Abs, Floor, Ceil, Norm, etc.) * and Delimiter since they already have visible delimiters.

(expr: MathJsonExpression | null | undefined, prec?: number)

Source from the content-addressed store, hash-verified

140 * the same value, but not the same symbol — so it could not be flagged.
141 */
142const NUMBER_SPELLING_SYMBOLS = new Set([
143 'PositiveInfinity',
144 'NegativeInfinity',
145 'NaN',
146 'ImaginaryUnit',
147]);
148
149/**
150 * Is `name` a symbol whose spelling comes from the serializer's number
151 * options?
152 *
153 * The exemption is keyed on the symbol being serialized, not on the LaTeX the
154 * entry produces: an unrelated entry that happened to emit one of those
155 * spellings would not re-parse to its own name, so it must still fall back to
156 * `\mathrm{Name}`.
157 */
158function isNumberSpellingSymbol(name: string | null | undefined): boolean {
159 return (
160 name !== null && name !== undefined && NUMBER_SPELLING_SYMBOLS.has(name)
161 );
162}
163
164export class Serializer {
165 options: Readonly<Required<ResolvedSerializeLatexOptions>>;
166 readonly dictionary: IndexedLatexDictionary;
167 level = -1;
168 constructor(
169 dictionary: IndexedLatexDictionary,
170 options: SerializeLatexOptions
171 ) {
172 this.dictionary = dictionary;
173 // Ensure all optional properties are present with defaults
174 // (`dotNotation` is required on `options`, so no default is needed for it)
175 // The style options can be specified as a constant string: normalize them
176 // to their function form.
177 this.options = {
178 dmsFormat: false,
179 angleNormalization: 'none',
180 ...normalizeStyleOptions(options),
181 } as Required<ResolvedSerializeLatexOptions>;
182 }
183
184 /**

Callers 7

trySerializeDotNotationFunction · 0.45
serializeAddFunction · 0.45
serializeMultiplyFunction · 0.45
serializeFractionFunction · 0.45
makeSerializeHandlerFunction · 0.45

Calls 8

serializeMethod · 0.95
wrapStringMethod · 0.95
operatorFunction · 0.90
isNumberObjectFunction · 0.90
machineValueFunction · 0.90
groupStyleMethod · 0.80
applyFunctionStyleMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected