Formats Nerdamer values as TeX or normalized text and imports supported TeX input.

remarks

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"): ConverterConstructor

Creates a converter with persistent output mode.

Parameters

NameTypeDescription
mode"text" | "TeX"`"TeX"` (the default) or `"text"`.

Returns

Converter

convert(input: string | number | ParserEntity, options?: OptionsObject): stringMethod

Formats supported values while retaining ordinary Converter semantics by default. Source preservation is an internal compatibility option used by convertToLaTeX.

Parameters

NameTypeDescription
inputstring | number | ParserEntity
optionsOptionsObject

Returns

string

fromTeX(input: string): ParserEntityMethod

Parses a supported TeX subset into a Nerdamer parser entity.

remarks

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.

throws

Error When preprocessing leaves syntax that the parser cannot interpret.

Parameters

NameTypeDescription
inputstringTeX 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: { … }Property

No description is available yet.

setMode(mode: string): voidMethod

Selects the output syntax used by subsequent conversions.

remarks

The mode is mutable converter state. Supported values are

`"TeX"`

and

`"text"`

; changing the mode does not alter parser settings or previously returned strings.

throws

Error When

`mode`

is not

`"TeX"`

or

`"text"`

.

Parameters

NameTypeDescription
modestringThe output mode to activate.

Returns

void