katex-ui
v2.0.0
Published
Formula calculator engine that turns expressions and pragmatic LaTeX into serializable schemas.
Downloads
1,551
Maintainers
Readme
katex-ui
Framework-free formula engine and schema toolkit for dynamic calculators.
katex-ui owns the durable domain layer: expression validation, LaTeX conversion, variable extraction, serializable calculator config, schema normalization, batch calculation, reusable runners, and display-safe formatting.
It is not a TeX renderer like katex: use it when formulas need to become calculator schemas, live forms, and persisted business rules.
Install
pnpm add katex-uiRepository
github.com/LaoChen1994/katex-ui
Homepage
laochen1994.github.io/katex-ui/
Highlights
- Formula engine - calculate arithmetic expressions with variables and functions.
- LaTeX bridge - convert
\frac,\sqrt, powers, functions, and simple subscripts. - Schema generator - turn variables into stable
FormulaSchemafields. - Calculator config - serialize source, expression, fields, and result metadata.
- Batch formulas - derive ordered values such as subtotal, tax, and total.
- Renderer agnostic - no React, Vue, or form-renderer runtime dependency.
Quick Start
import { createLatexFormulaCalculator } from 'katex-ui/parser';
const calculator = createLatexFormulaCalculator({
source: '\\frac{price \\times count}{discount}',
fields: [
{ name: 'price', label: 'Price', defaultValue: 100 },
{ name: 'count', label: 'Count', defaultValue: 2 },
{ name: 'discount', label: 'Discount', defaultValue: 4 },
],
result: {
label: 'Total',
precision: 12,
},
});
calculator.config;
calculator.schema;
calculator.calculate({ price: 100, count: 2, discount: 4 });
// { value: 50, errors: [] }API Surface
katex-ui/core-calculateFormula,createFormulaRunner,calculateFormulaBatch,formatFormulaValue.katex-ui/parser-latexToExpression,parseLatexFormula,createLatexFormulaCalculator.katex-ui/schema-createFormulaSchema,createFormulaCalculatorConfig,mergeFormulaFields.
Quality
- Unit tests: 46 core/parser/schema tests.
- Coverage: 90.37% statements, 83.55% branches, 96% functions.
- Build:
tsupESM +.d.ts. - Runtime dependencies: none.
