Converter
Formats Nerdamer values as TeX or normalized text and imports supported TeX input.
A converter retains its output mode between calls. The default mode is
`"TeX"`; construct a separate
`"text"`converter when both representations are needed. Formatting a string parses it with the process-wide parser, so registered functions, constants, settings, and known values can affect the result. Converter.fromTeX recognizes the TeX forms emitted by this converter and a practical subset of common mathematical notation. It is not a general TeX parser: unsupported macros, ambiguous implicit notation, or nesting outside the recognized forms can produce parser errors or a different symbolic interpretation.
Examples
import nerdamer from 'nerdamer';
const text = new nerdamer.classes.Converter('text');
const tex = new nerdamer.classes.Converter();
text.convert('x^2 + 2*x + 1'); // "1+2*x+x^2"
tex.convert('sqrt(x)'); // "\\sqrt{x}"Members
Converter(mode?: "text" | "TeX"): ConverterConstructorCreates a converter with persistent output mode.
Parameters
| Name | Type | Description |
|---|---|---|
mode | "text" | "TeX" | `"TeX"` (the default) or `"text"`. |
Returns
convert(input: string | number | ParserEntity, options?: OptionsObject): stringMethodFormats supported values while retaining ordinary Converter semantics by default. Source preservation is an internal compatibility option used by convertToLaTeX.
Parameters
| Name | Type | Description |
|---|---|---|
input | string | number | ParserEntity | — |
options | OptionsObject | — |
Returns
string
convertNtRoot(input: Expression, root: Expression): ExpressionMethodNo description is available yet.
Parameters
| Name | Type | Description |
|---|---|---|
input | Expression | — |
root | Expression | — |
Returns
convertSQRT(input: Expression): ExpressionMethodNo description is available yet.
Parameters
| Name | Type | Description |
|---|---|---|
input | Expression | — |
Returns
fromTeX(input: string): ParserEntityMethodParses a supported TeX subset into a Nerdamer parser entity.
Set notation is recognized before ordinary expression preprocessing and produces a value set or dictionary when appropriate. Other input is rewritten to Nerdamer parser syntax, tokenized in pure mode, and evaluated through the process-wide parser. Consequently, parser settings or registered functions can affect the result. The importer supports the converter's common function forms, roots, arbitrary-base logarithms, transforms, derivatives, integrals, limits, sums, products, floor and ceiling notation, equations, vectors, matrices, finite sets, and dictionaries. It does not promise round-tripping arbitrary third-party TeX.
Error When preprocessing leaves syntax that the parser cannot interpret.
Parameters
| Name | Type | Description |
|---|---|---|
input | string | TeX text in the supported conversion subset. |
Returns
ParserEntity — The parser entity represented by the supported TeX input.
Examples
import nerdamer from 'nerdamer';
const converter = new nerdamer.classes.Converter();
nerdamer.pretty(converter.fromTeX('\\log_{2}{256}'), 'text'); // "8"modes: { … }PropertyNo description is available yet.
setMode(mode: string): voidMethodSelects the output syntax used by subsequent conversions.
The mode is mutable converter state. Supported values are
`"TeX"`and
`"text"`; changing the mode does not alter parser settings or previously returned strings.
Error When
`mode`is not
`"TeX"`or
`"text"`.
Parameters
| Name | Type | Description |
|---|---|---|
mode | string | The output mode to activate. |
Returns
void
