{"id":25926,"library":"mathex2java-translator","title":"MaTheX2Java","description":"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.","status":"active","version":"1.1.6","language":"javascript","source_language":"en","source_url":"https://github.com/francismaria/MaTheX2Java","tags":["javascript","latex","mathex2java","java","transpiler","compiler","antlr4","languages","cfg","typescript"],"install":[{"cmd":"npm install mathex2java-translator","lang":"bash","label":"npm"},{"cmd":"yarn add mathex2java-translator","lang":"bash","label":"yarn"},{"cmd":"pnpm add mathex2java-translator","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package is ESM-only. CommonJS require will fail.","wrong":"const translate = require('mathex2java-translator')","symbol":"translate","correct":"import { translate } from 'mathex2java-translator'"},{"note":"TypeScript type for annotation objects; exported as named type.","wrong":"","symbol":"AnnotatedTranslation","correct":"import { AnnotatedTranslation } from 'mathex2java-translator'"},{"note":"Default export is the main translator class. Use default import syntax.","wrong":"import { default } from 'mathex2java-translator'","symbol":"default","correct":"import maTheX2Java from 'mathex2java-translator'"}],"quickstart":{"code":"import { translate } from 'mathex2java-translator';\n\nconst latex = '\\\\[ \\\\int_{a}^{b} x^2 \\\\, dx \\\\]';\nconst javaCode = translate(latex, { annotations: [] });\nconsole.log(javaCode);\n// 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; }","lang":"typescript","description":"Translates a LaTeX integral expression into a Java method using numerical integration."},"warnings":[{"fix":"Use only amsmath v2.1 compatible LaTeX. Avoid LaTeX3 or non-amsmath packages.","message":"Only amsmath v2.1 LaTeX is supported; newer LaTeX constructs may fail or produce incorrect code.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Use import syntax or dynamic import(). If using CommonJS, upgrade to ESM or use a wrapper.","message":"The package is ESM-only (no CommonJS support). Direct require() will throw 'ERR_REQUIRE_ESM'.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Override step size via annotations or post-process the generated code.","message":"Numeric integration defaults to step size 0.001, which may be too coarse for precision-sensitive applications.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Convert your project to ESM (set type: module in package.json) or use dynamic import: const { translate } = await import('mathex2java-translator');","cause":"The package is ESM-only and cannot be used with CommonJS require().","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/mathex2java-translator/index.mjs from /path/to/project/index.js not supported."},{"fix":"Ensure Node.js version >= 12 and set type: module in package.json, or transpile with Babel/TypeScript.","cause":"The source code contains ES module syntax but the runtime is Node.js without ESM support.","error":"SyntaxError: Unexpected token 'export'"},{"fix":"Use import { translate } from 'mathex2java-translator' instead of import maTheX2Java from 'mathex2java-translator'.","cause":"Wrong import style: using default import when translate is a named export.","error":"TypeError: translate is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}