Skip to content
1 min read · 172 words

Variable: evaluateKatexTool

ts
const evaluateKatexTool: Tool<SpooledArtifact>;

Defined in: src/batteries/tools/math/index.ts:598

Translates a LaTeX/KaTeX expression using evaluatex and returns the numeric result.

Remarks

Uses the evaluatex library to parse and evaluate LaTeX expressions. Handles common constructs (\frac{a}{b}, \sqrt{...}, \cdot, \times, Greek macros like \pi, inverse trig, \left/\right delimiters, \text{...}, subscripts, etc.) with a proper parser rather than brittle regex.

Also evaluates three calculus constructs numerically (mathjs has no symbolic integration, and its symbolic derivative is blocklisted here for safety):

  • Definite integrals — \int_{a}^{b} f \,dx via composite Simpson quadrature.
  • Derivatives at a point — \frac{d}{dx} f \big|_{x=a} via central finite difference.
  • Limits — \lim_{x \to a} f (including a = \pm\infty) via a two-sided numeric approach.

Numeric results are rounded with math.format(..., { precision: 12 }) and labelled Result (numeric): to flag that they are approximations. Constructs that cannot be evaluated numerically (indefinite integrals, derivatives without a point, infinite integration bounds, singular integrands, divergent limits) return a specific, guiding error string.

Parse and evaluation errors are returned as error strings rather than thrown.