BuTeX
BuTeX (@drghaliasri/butex) provides Arabic mathematical typography and structured equation/document editing on MathJax 4. It ships an AST-first equation editor, canonical Document model, React editors/previews and a stateless Node document worker.
MathJax is an external peer dependency, not bundled as a vendored upstream source tree. See MathJax's upstream source for the reference implementation; package.json specifies the runtime peer dependency.
Install
npm install @drghaliasri/butex mathjax
# Add these if using the React editors:
npm install react react-dom
Node.js 20+ is required for tooling/worker usage. MathJax ^4.1.0 is a peer dependency; React and ReactDOM 18/19 are optional peers. package.json defines current versions, supported imports and CLI names.
Public entrypoints
| Import / executable | Implemented purpose |
|---|---|
@drghaliasri/butex | Core Arabic MathJax macros, parseBuTeX, registration, math-island rendering |
@drghaliasri/butex/react | Standalone ButexEditor equation editor |
@drghaliasri/butex/document | DocumentJson, commands, import/export, outline, validation, diff |
@drghaliasri/butex/react-document | ButexDocumentEditor editor |
@drghaliasri/butex/react-document-preview | Lightweight read-only ButexDocumentPreview |
butex-document | Stateless stdin / authenticated HTTP worker |
The completed Document2 → Document migration retired the first-generation editor and promoted the maintained model, worker and React editor to the unversioned names above. These are the current 8.0.3 package interfaces, not pending migration-branch APIs. See the post-fix verification for evidence and release qualifications.
MathJax setup
Use MathJax 4 tex-chtml.js or tex-svg.js, matching the chtml / svg output mode. Configure the butex-arabic-math TeX package and call registerBuTeX before MathJax startup completes. Use registerBuTeXSvgTextWrapper after startup initialization for SVG-specific Arabic text behavior.
import { registerBuTeX, injectBuTeXStyles } from '@drghaliasri/butex';
// Inside your host's MathJax startup.ready integration:
registerBuTeX(MathJax);
injectBuTeXStyles();
// Then complete the chosen MathJax component's startup.
See math/rendering architecture for initialization and semantic/visual RTL rules. parseBuTeX is a small Arabic-friendly surface preprocessor, not a general LaTeX-to-structured-AST parser.
Document model basics
import {
createEmptyDocument,
fromDocumentJson,
toDocumentJson,
validateDocument,
} from '@drghaliasri/butex/document';
const document = createEmptyDocument();
const validation = validateDocument(document);
const saved = toDocumentJson(document);
const restored = fromDocumentJson(saved);
Use ButexDocumentEditor from @drghaliasri/butex/react-document for the interactive editor; use ButexDocumentPreview from @drghaliasri/butex/react-document-preview to show read-only snapshots.
Renaming an enabled figure/table label with update_float_meta also updates matching \ref/\eqref tokens throughout the document in the same edit; disabling or clearing a label leaves references unchanged.
Host responsibility: authentication, article permissions, immutable revisions, image uploads/storage, compilation and publishing. BuTeX supplies pure Document transformations and editing UI, never an article database or MCP authorization bypass. See Document, React integration, and the worker.
Development and demos
npm ci
npm run build
npm run typecheck
npm run lint
npm test
The equation-editor demo is demo/editor-app/; the modern document editor is demo/document-editor-app/; the first-generation demo was replaced by the promoted modern demo at the canonical path. Read local development and verification.
Book authoring — proposed only
The BuTeX book design and Al-Bayan integration plan describe future multi-chapter editing, scoped references and whole-book export. Book/editor/worker APIs in those plans do not ship today.
Documentation
- Architecture — implemented package and host contracts
- Development — building, browser testing and releases
- Proposals — book authoring and completed Document migration evidence
- Archive — historical design records
The npm tarball includes dist/ and this README; docs/ live in the GitLab repository.
License
See the license field in package.json.