@drghaliasri/butex 4.1.0 → 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 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. 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`).
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,7 +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).
130
- - **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{…}}`. BuTeX’s own save path already stores plain glyphs; upstream converters may emit wrapped `expr` and do not need to change for document render.
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.
131
132
 
132
133
  Minimal browser example:
133
134
 
@@ -274,7 +275,7 @@ Open:
274
275
 
275
276
  - `http://localhost:4173/demo/` (MathJax + `\arabsqrt`)
276
277
  - `http://localhost:4173/demo/parser.html` (parser-only normalize preview)
277
- - **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.
278
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).
279
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.
280
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 = new CharNode(node.expr);
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") {