Start here

Choosing how to use Nerdamer

The library exposes three user-facing interfaces. They share the same symbolic engine, but they are written and documented differently.

1. Nerdamer Notation

Use notation when you want to write mathematics as text. Functions inside the string are symbolic functions, not JavaScript calls.

import nerdamer from 'nerdamer';

const result = nerdamer('factor(x^2-1)');

Nerdamer Notation is especially useful when an application accepts mathematical input from users. A formula entered in a text field, loaded from stored data, or otherwise received as text can be passed to nerdamer('...') without first translating it into a sequence of JavaScript API calls. The library parses that text as mathematical notation; it does not evaluate the input as JavaScript.

This is usually the shortest route for symbolic work and the natural interface for dynamic mathematical input. Applications should still handle invalid syntax and set appropriate limits for workloads they accept from users. See Expression syntax and the function reference.

2. Nerdamer Scripting

Use scripting when the text passed to nerdamer(...) needs more than one expression: assignments, user-defined functions, conditions, loops, blocks, or local bindings.

const result = nerdamer(`
f(x):=x^2+1;
if(a>0, f(a), 0)
`);

These constructs are evaluated by the scripting layer, not by JavaScript. See Nerdamer Scripting. For function definitions specifically, see User-defined functions.

3. JavaScript / TypeScript API

Use the API when your application wants to call the library directly from JavaScript or TypeScript. There are two common forms.

The nerdamer API

The default import is a callable JavaScript value with additional public functions and properties attached to it.

import nerdamer from 'nerdamer';

const expression = nerdamer('x^2+1');
const tex = nerdamer.convertToTeX(expression);
const f = nerdamer('8*cos(x)').buildFunction(['x']);
nerdamer.setFunction('f', ['x'], 'x^2+1');
const factored = nerdamer.factor('x^2-1');

Use convertToTeX() when you need TeX math markup from the root API. Expressions also provide toTeX(). The older convertToLaTeX() name remains available as a deprecated compatibility alias.

buildFunction() is available directly on values returned by nerdamer(...) so scalar expressions can be compiled without a manual type cast or type guard. It only compiles an Expression. If the parsed result is an equation, vector, matrix, set, or another structured value, the method throws UnexpectedDataType rather than compiling the contained values independently.

Browse the generated nerdamer API to see the callable export and its attached members.

Direct imports

import { factor } from 'nerdamer/algebra';
import { Matrix } from 'nerdamer/structures';

const result = factor('x^2-1');
const M = new Matrix([1, 2], ['x', 'y']);

Direct imports are useful when you want a specific function, class, or TypeScript type. See the JavaScript / TypeScript API for public package paths.

The same operation in different forms

import nerdamer from 'nerdamer';
import { factor } from 'nerdamer/algebra';

nerdamer('factor(x^2-1)');  // Nerdamer Notation

nerdamer.factor('x^2-1');   // JavaScript / TypeScript API

factor('x^2-1');            // JavaScript / TypeScript API

The first line asks the parser to interpret factor(...). The other two call JavaScript functions directly.

What about nerdamer/parser?

nerdamer/parser is a JavaScript / TypeScript package entry point for programmatic parser access. It belongs to the API reference and is separate from the documentation for writing Nerdamer Notation.