@enumeratio/formats
A Wolfram-style format registry — Import/Export over MathJSON, Wolfram Language, TeX, AsciiMath, MathML, code targets (Python/JS/GLSL/WGSL), and images. Reach for this when you have a boxed expression and need it as text in some notation, or text in some notation and need it back as an expression.
Entry points
.— the registry (registerFileFormat,getFormat,exportTo,importFrom,fileFormat,sniffFormat,mimeTypeToFormatList) and the built-in formats, registered as a side effect of import../node— adds the PNG codec (needs the native rasterizer,raster) and file I/O (writeFormat/readFormat); also registers the browser-safe formats, so a Node consumer imports just this../expression—parseExpression/serializeExpression: Epsil in and out, the syntax everynotatio-*attribute and editable cell is written in. No statements or effects (assignment, declarations, pragmas) —parseExpressionreports those rather than evaluating them../inputform—toInputForm: an expression printed as Epsil you could retype, with a normalization pass over compute-engine's raw and canonical serializations (written inengine, re-exported here)../fullform—toFullForm: the expression's tree as Epsil, every head an explicit call (Take(List(a, b, c), 2)), no operators or sugar;parseEpsilreads it back as the same uncanonical MathJSON. Wolfram's FullForm is theWLformat../tex—portableTeX: compute-engine's LaTeX rewritten for a document (amsmath/amssymb macros in place of MathLive-only commands like\imaginaryI)../mathml,./asciimath— MathMLForm and AsciiMath, built onboxes's presentation tree.
Usage
import { exportTo, fileFormat, getFormat, importFrom } from "@enumeratio/formats";
exportTo(box(["Binomial", 10, 3]), "WL"); // "Binomial[10, 3]"
exportTo(box(["Add", ["Power", "x", 2], 1]), "JavaScript"); // contains "x"
importFrom("Binomial[10, 3]", "WL"); // ["Binomial", 10, 3]
getFormat("numpy")?.name; // "Python"
fileFormat("out/plot.png")?.name; // "PNG"A format name resolves case-insensitively and by alias (numpy → Python, WolframLanguage → WL). Text formats consume a boxed compute-engine expression; image formats consume an SVG string — the registry stays value-agnostic about which.
Graphics as values
Image and Rasterize (declareGraphics) let an expression hold a picture rather than a bespoke element special-casing it: Image carries a URI, so it serializes and behaves the same in Node and a browser. setRasterizer installs the pixel-producing backend; raster supplies Node's.
Where to go next
/reference/formats/— every form and syntax, with worked examples (InputForm, LaTeX, MathJSON, AsciiMath).boxes— the presentation tree these serializers and MathML/AsciiMath parsers are built on.- Boxes — the design behind boxes and the formats built on them.