@drghaliasri/butex 4.0.1 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/dist/document.js +37 -1
- package/dist/document.js.map +1 -1
- package/dist/document.mjs +37 -1
- package/dist/document.mjs.map +1 -1
- package/dist/document2.js +160 -2
- package/dist/document2.js.map +1 -1
- package/dist/document2.mjs +160 -2
- package/dist/document2.mjs.map +1 -1
- package/dist/index.d.mts +20 -2
- package/dist/index.d.ts +20 -2
- package/dist/index.global.js +223 -4
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +223 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +223 -4
- package/dist/index.mjs.map +1 -1
- package/dist/react-document.js +437 -6
- package/dist/react-document.js.map +1 -1
- package/dist/react-document.mjs +437 -6
- package/dist/react-document.mjs.map +1 -1
- package/dist/react-document2.js +437 -6
- package/dist/react-document2.js.map +1 -1
- package/dist/react-document2.mjs +437 -6
- package/dist/react-document2.mjs.map +1 -1
- package/dist/react.d.mts +11 -0
- package/dist/react.d.ts +11 -0
- package/dist/react.js +303 -4
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +303 -4
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -61,7 +61,8 @@ Peer dependency: `mathjax` ^4.x (aligned with MathJax 4 components). If you use
|
|
|
61
61
|
2. Load BuTeX’s IIFE bundle (`dist/index.global.js` exposes global `BuTeX`).
|
|
62
62
|
3. In `MathJax.startup.ready`, call `BuTeX.registerBuTeX(MathJax)` before `MathJax.startup.defaultReady()`.
|
|
63
63
|
4. Inject styles once: `BuTeX.injectBuTeXStyles()` (or embed `BuTeX.BUTEX_CHROME_CSS` yourself).
|
|
64
|
-
5.
|
|
64
|
+
5. When using **SVG** (`tex-svg.js`), call `BuTeX.registerBuTeXSvgTextWrapper(MathJax)` **after** `defaultReady()` so Takween/Diwani text, `\ad`, and Arabic atomic commands (`\arsin`, etc.) render in the preview with the correct fonts. CommonHTML (`tex-chtml.js`) uses the injected CSS classes instead.
|
|
65
|
+
6. Render math with `renderBuTeXMathIsland(tex, options?)` or mount into a host element via `mountBuTeXMathIsland(host, tex, options?)`. Pass `output: 'svg'` when the host loads `tex-svg.js`, or `output: 'chtml'` with `tex-chtml.js`. For raw Arabic TeX that did not come from the editor AST, pass `mirrorOperators: true` to wrap directional operators according to BuTeX's shared operator table. `ButexEditor` picks SVG vs CHTML automatically from the loaded MathJax bundle (`tex2svg` vs `tex2chtml`).
|
|
65
66
|
|
|
66
67
|
Ensure TeX `packages` includes `butex-arabic-math` (use `BUTEX_TEX_PACKAGE` in config when using `{ '[+]': [...] }`).
|
|
67
68
|
|
|
@@ -127,6 +128,7 @@ Use this when you want the same editor UX as the demo:
|
|
|
127
128
|
- Optionally pass `buttonElements` (undo/redo/copy/cut/split toggle) for auto button state refresh.
|
|
128
129
|
- Wire your toolbar/actions to runtime methods (`toggleSide`, `insertDelimiterByKind`, `addSup`, `addSub`, `removeSup`, `removeSub`, `deleteStructure`, `performUndo`, `performRedo`, `performCopy`, `performCut`, `performPaste`).
|
|
129
130
|
- Use `onSessionChange(session)` to render external previews (e.g., MathJax pane, status labels).
|
|
131
|
+
- **Imported `MathObject` / `CharObject` for the editor:** document LaTeX preview treats `CharObject.expr` as already-rendered Arabic TeX (e.g. `\text{م}`). When opening an imported equation in `<ButexEditor />` via `mathObjectToEditorSession`, BuTeX unwraps supported LaTeX text/font wrappers into plain glyph `expr` plus editor `characterFont`. Supported patterns: `\text{…}`, `\takween{…}`, `\diwani{…}`, `\butextakween{…}`, `\butexdiwani{…}`, `\butexdiwanioutline{…}`, and nested forms such as `\text{\takween{…}}`. On save, default-font chars stay plain `CharObject` nodes; non-default fonts are stored as font `CommandObject` wrappers so editor round-trip preserves `characterFont`. Upstream converters may still emit wrapped `expr` on import.
|
|
130
132
|
|
|
131
133
|
Minimal browser example:
|
|
132
134
|
|
|
@@ -273,7 +275,7 @@ Open:
|
|
|
273
275
|
|
|
274
276
|
- `http://localhost:4173/demo/` (MathJax + `\arabsqrt`)
|
|
275
277
|
- `http://localhost:4173/demo/parser.html` (parser-only normalize preview)
|
|
276
|
-
- **Equation editor (React):** run `cd demo/editor-app && npm install && npm run dev`, then open the URL Vite prints (see `demo/editor.html` for a short pointer).
|
|
278
|
+
- **Equation editor (React):** run `cd demo/editor-app && npm install && npm run dev`, then open the URL Vite prints (see `demo/editor.html` for a short pointer). The equation editor demo loads MathJax SVG from `public/vendor/`, matching document editor v2.
|
|
277
279
|
- **Document editor (React):** run `cd demo/document-editor-app && npm install && npm run dev`, then open the URL Vite prints (see `demo/document.html` for a short pointer).
|
|
278
280
|
- **Document editor v2 (React):** run `cd demo/document-editor-app2 && npm install && npm run dev`, then open the URL Vite prints. The v2 demo loads MathJax SVG and includes grouped insert controls (sections, lists, tables, figures, equations), per-block delete, list item controls, and editor/preview toggles. Optional bottom dev panels (LaTeX + AST) appear only if you append `?debug=1` to the URL or pass the `debug` prop from your host app.
|
|
279
281
|
|
package/dist/document.js
CHANGED
|
@@ -1020,6 +1020,16 @@ var ATOMIC_COMMANDS = {
|
|
|
1020
1020
|
arabicLabel: "\u0645\u062D\u062F\u062F",
|
|
1021
1021
|
title: "\u0645\u062D\u062F\u062F"
|
|
1022
1022
|
},
|
|
1023
|
+
////////////////////// Derivatives ////////////////////////////////
|
|
1024
|
+
ad: {
|
|
1025
|
+
id: "ad",
|
|
1026
|
+
category: "derivative",
|
|
1027
|
+
englishTex: "\\mathrm{d}",
|
|
1028
|
+
englishLabel: "d",
|
|
1029
|
+
arabicTex: "\\ad",
|
|
1030
|
+
arabicLabel: "\u0621",
|
|
1031
|
+
title: "\u0639\u0644\u0627\u0645\u0629 \u0627\u0644\u0627\u0634\u062A\u0642\u0627\u0642"
|
|
1032
|
+
},
|
|
1023
1033
|
////////////////////// Groups /////////////////////////////////
|
|
1024
1034
|
N: {
|
|
1025
1035
|
id: "N",
|
|
@@ -1611,6 +1621,16 @@ function atomicOperatorCommandSpec(id) {
|
|
|
1611
1621
|
return Object.prototype.hasOwnProperty.call(ATOMIC_OPERATOR_COMMANDS, id) ? ATOMIC_OPERATOR_COMMANDS[id] : null;
|
|
1612
1622
|
}
|
|
1613
1623
|
|
|
1624
|
+
// src/editor/divideOperator.ts
|
|
1625
|
+
var DIVIDE_OPERATOR_EN = "/";
|
|
1626
|
+
var DIVIDE_OPERATOR_AR = "\\";
|
|
1627
|
+
function isDivideOperatorExpr(expr) {
|
|
1628
|
+
return expr === DIVIDE_OPERATOR_EN || expr === DIVIDE_OPERATOR_AR;
|
|
1629
|
+
}
|
|
1630
|
+
function renderDivideOperatorLatex(side) {
|
|
1631
|
+
return side === "arabic" ? "\\backslash" : DIVIDE_OPERATOR_EN;
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1614
1634
|
// src/editor/digits.ts
|
|
1615
1635
|
var WESTERN = "0123456789";
|
|
1616
1636
|
var ARABIC_INDIC = "\u0660\u0661\u0662\u0663\u0664\u0665\u0666\u0667\u0668\u0669";
|
|
@@ -1733,6 +1753,9 @@ function renderNodeArabic(node, options) {
|
|
|
1733
1753
|
const content = renderCharContent(node, options);
|
|
1734
1754
|
return arabicScripts(node, (node.characterFont ?? "default") === "default" ? `\\text{${escapeText(expr)}}` : content, options);
|
|
1735
1755
|
}
|
|
1756
|
+
if (node.kind === "operator" && isDivideOperatorExpr(node.expr)) {
|
|
1757
|
+
return arabicScripts(node, renderDivideOperatorLatex("arabic"), options);
|
|
1758
|
+
}
|
|
1736
1759
|
return arabicScripts(node, formatDigits(node.expr, selectedDigitForm(options)), options);
|
|
1737
1760
|
}
|
|
1738
1761
|
function renderChainArabic(chain, options) {
|
|
@@ -2304,6 +2327,19 @@ ${ATOMIC_OPERATOR_COMMAND_CSS}
|
|
|
2304
2327
|
`.trim();
|
|
2305
2328
|
|
|
2306
2329
|
// src/document/mathEditorAdapter.ts
|
|
2330
|
+
var CHAR_FONT_EXPORT_TEX = {
|
|
2331
|
+
takween: "\\butextakween",
|
|
2332
|
+
diwani: "\\butexdiwani",
|
|
2333
|
+
diwaniOutline: "\\butexdiwanioutline"
|
|
2334
|
+
};
|
|
2335
|
+
function charEditorNodeToAstNode(node) {
|
|
2336
|
+
const font = node.characterFont ?? "default";
|
|
2337
|
+
const charNode = new CharNode(node.expr);
|
|
2338
|
+
if (font === "default") {
|
|
2339
|
+
return charNode;
|
|
2340
|
+
}
|
|
2341
|
+
return new CommandNode(CHAR_FONT_EXPORT_TEX[font], [], [new ChainNode([charNode])]);
|
|
2342
|
+
}
|
|
2307
2343
|
function attachAstScripts(editorNode, astNode) {
|
|
2308
2344
|
if (editorNode.superscript) {
|
|
2309
2345
|
const sup = editorChainToAstChain(editorNode.superscript);
|
|
@@ -2359,7 +2395,7 @@ function editorEnvToAstNode(node) {
|
|
|
2359
2395
|
function editorNodeToAstNode(node) {
|
|
2360
2396
|
let astNode;
|
|
2361
2397
|
if (node.kind === "char") {
|
|
2362
|
-
astNode =
|
|
2398
|
+
astNode = charEditorNodeToAstNode(node);
|
|
2363
2399
|
} else if (node.kind === "number") {
|
|
2364
2400
|
astNode = new NumberNode(node.expr);
|
|
2365
2401
|
} else if (node.kind === "operator") {
|