Registry / serialization / mathex2java-translator

mathex2java-translator

JSON →
library1.1.6jsnpmunverified

MaTheX2Java is a transpiler that converts amsmath LaTeX mathematical expressions into well-structured, executable Java code. The current stable version (1.1.6) supports the amsmath package v2.1 and provides an annotation feature for customizing code generation. It is built with ANTLR4 and ships TypeScript types. Unlike general LaTeX-to-code tools, MaTheX2Java focuses specifically on Java, producing production-ready code without requiring Java knowledge. Release cadence is irregular but active; the GitHub repository shows recent maintenance. It is for mathematicians, students, and developers who want to run LaTeX formulas as Java programs.

npm install mathex2java-translator
INSTALL
IMPORT
SIG · MATHEX2JAVA-TRANSL
M
mathex2java-translator
serializationjavascriptv1.1.6
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

translate
✓ import { translate } from 'mathex2java-translator'
✗ const translate = require('mathex2java-translator')
Package is ESM-only. CommonJS require will fail.
AnnotatedTranslation
✓ import { AnnotatedTranslation } from 'mathex2java-translator'
TypeScript type for annotation objects; exported as named type.
default
✓ import maTheX2Java from 'mathex2java-translator'
✗ import { default } from 'mathex2java-translator'
Default export is the main translator class. Use default import syntax.

Translates a LaTeX integral expression into a Java method using numerical integration.

import { translate } from 'mathex2java-translator'; const latex = '\\[ \\int_{a}^{b} x^2 \\, dx \\]'; const javaCode = translate(latex, { annotations: [] }); console.log(javaCode); // Output: public static double integrate(double a, double b) { double result = 0; for (double x = a; x <= b; x += 0.001) { result += x * x * 0.001; } return result; }
mathex2java --version
Debug
Known issues
breakingOnly amsmath v2.1 LaTeX is supported; newer LaTeX constructs may fail or produce incorrect code.
fix
Use only amsmath v2.1 compatible LaTeX. Avoid LaTeX3 or non-amsmath packages.
affects: >=1.0.0
gotchaThe package is ESM-only (no CommonJS support). Direct require() will throw 'ERR_REQUIRE_ESM'.
fix
Use import syntax or dynamic import(). If using CommonJS, upgrade to ESM or use a wrapper.
affects: >=1.0.0
gotchaNumeric integration defaults to step size 0.001, which may be too coarse for precision-sensitive applications.
fix
Override step size via annotations or post-process the generated code.
affects: >=1.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/mathex2java-translator/index.mjs from /path/to/project/index.js not supported.
The package is ESM-only and cannot be used with CommonJS require().
fix
Convert your project to ESM (set type: module in package.json) or use dynamic import: const { translate } = await import('mathex2java-translator');
SyntaxError: Unexpected token 'export'
The source code contains ES module syntax but the runtime is Node.js without ESM support.
fix
Ensure Node.js version >= 12 and set type: module in package.json, or transpile with Babel/TypeScript.
TypeError: translate is not a function
Wrong import style: using default import when translate is a named export.
fix
Use import { translate } from 'mathex2java-translator' instead of import maTheX2Java from 'mathex2java-translator'.
Upgrade
Version history
1.1.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
mathex2java-translator — npm install mathex2java-translator · libregistry