* 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)
| 140 | * the same value, but not the same symbol — so it could not be flagged. |
| 141 | */ |
| 142 | const 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 | */ |
| 158 | function isNumberSpellingSymbol(name: string | null | undefined): boolean { |
| 159 | return ( |
| 160 | name !== null && name !== undefined && NUMBER_SPELLING_SYMBOLS.has(name) |
| 161 | ); |
| 162 | } |
| 163 | |
| 164 | export 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 | /** |
no test coverage detected