@drghaliasri/butex 4.2.0 → 4.4.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
@@ -118,6 +118,30 @@ Use this when you only need to render LaTeX strings:
118
118
 
119
119
  This mode does not require the GUI editor runtime.
120
120
 
121
+ ### Host CSS resets (Tailwind Preflight and similar)
122
+
123
+ MathJax renders SVG equations as inline `<svg>` elements, and MathJax 4's inline
124
+ line-breaking can emit one equation as **several sibling `<svg>` chunks**. Global
125
+ CSS resets that declare `svg { display: block }` (e.g. **Tailwind Preflight**)
126
+ stack those chunks vertically, so equations render one term per line.
127
+
128
+ BuTeX's injected styles guard against this with:
129
+
130
+ ```css
131
+ mjx-container svg {
132
+ display: inline;
133
+ }
134
+ ```
135
+
136
+ The guard ships in both `injectBuTeXStyles()` (`BUTEX_CHROME_CSS`) and
137
+ `injectBuTeXDocument2Styles()` (`DOCUMENT2_WIDGET_CSS`), so make sure the host
138
+ calls at least one of them (or embeds the CSS constants). If your app injects
139
+ neither and you see stacked/wrapped equations under Tailwind, add the rule above
140
+ to your global stylesheet after the reset.
141
+
142
+ Also pin the MathJax version the host loads (e.g. `mathjax@4.1`) instead of a
143
+ floating major tag, so CDN updates cannot change rendering behavior silently.
144
+
121
145
  ### 2) GUI editor contract (shippable editor UX)
122
146
 
123
147
  Use this when you want the same editor UX as the demo:
@@ -231,6 +255,60 @@ const preview = document2Preview(documentNode, 'svg');
231
255
 
232
256
  V2 exports Arabic TeX by default for equations saved from the embedded editor. Imported raw-only math is preserved as raw source and marked non-editable until a structured equation object is attached.
233
257
 
258
+ ### Document JSON contract (`value` + `math_objects`)
259
+
260
+ Both document layers import the same shape. A text field holds `value` (the full string, **with math delimiters kept in place**) and an optional parallel `math_objects` array that supplies the structured equation AST for each math span found in that string.
261
+
262
+ Rules:
263
+
264
+ - **Detect, then align.** The importer scans `value` for delimiters (`$…$`, `\(…\)`, `\[…\]`, `$$…$$`, and math environments) and binds each detected span to `math_objects` **in reading order (left-to-right)**.
265
+ - **Count and order must match.** Extra or missing entries produce a diagnostic; the browser never silently remaps. `math_mode`/`closing` on each `MathObject` must match the delimiter in `value`.
266
+ - **Per field, not per document.** Each paragraph, heading, and list `item` carries its own `math_objects`.
267
+ - **Tables are the exception:** one flat `math_objects` array lives on the `\begin{tabular}` block and is consumed **row-major** across all cells (each cell takes as many entries as it has spans).
268
+ - **Missing `math_objects`** → the span renders as a non-editable raw math chip from its delimited source.
269
+ - The browser **does not** parse equation LaTeX bodies into `ChainClass`; structured chains come from `math_objects` (import) or the equation editor (GUI).
270
+
271
+ Paragraph with one inline span:
272
+
273
+ ```json
274
+ {
275
+ "command": "\\paragraph",
276
+ "value": "لدينا $x^2$ ثابت.",
277
+ "math_objects": [
278
+ { "node_type": "MathObject", "math_mode": "$",
279
+ "lines": [{ "node_type": "ChainClass", "chain": [] }], "closing": "$" }
280
+ ]
281
+ }
282
+ ```
283
+
284
+ List item with a display span (`math_mode`/`closing` match the delimiter in `value`):
285
+
286
+ ```json
287
+ {
288
+ "value": "الحل \\[a+b\\]",
289
+ "math_objects": [
290
+ { "node_type": "MathObject", "math_mode": "\\[",
291
+ "lines": [{ "node_type": "ChainClass", "chain": [] }], "closing": "\\]" }
292
+ ]
293
+ }
294
+ ```
295
+
296
+ Table: one flat array, consumed row-major (here `$x$`, then `$y$`):
297
+
298
+ ```json
299
+ {
300
+ "command": "\\begin{tabular}",
301
+ "columns": "cc",
302
+ "rows": [["الرمز $x$", "القيمة"], ["الرمز $y$", "القيمة"]],
303
+ "math_objects": [
304
+ { "node_type": "MathObject", "math_mode": "$",
305
+ "lines": [{ "node_type": "ChainClass", "chain": [] }], "closing": "$" },
306
+ { "node_type": "MathObject", "math_mode": "$",
307
+ "lines": [{ "node_type": "ChainClass", "chain": [] }], "closing": "$" }
308
+ ]
309
+ }
310
+ ```
311
+
234
312
  ### Document React widget v2 (`butex/react-document2`)
235
313
 
236
314
  Use this entry for the new document editor integration. It opens embedded `<ButexEditor />` sessions in Arabic/RTL mode by default and renders document preview math islands with MathJax **SVG** by default (`mathOutput` defaults to `'svg'`; pass `mathOutput="chtml"` only if the host loads `tex-chtml.js`).
@@ -254,7 +332,7 @@ export default function Page() {
254
332
  }
255
333
  ```
256
334
 
257
- Host apps still register BuTeX with MathJax before preview rendering. `uiLocale` selects Arabic (`"ar"`, the default) or English (`"en"`) document-editor chrome and is passed to the embedded equation editor. `documentDirection` independently controls prose inputs and preview flow without creating a second document tree. `equationSide` independently controls whether structured equations open, render, and save from the `"english"` or `"arabic"` side. Set `editableEquations={false}` to show math islands without equation insertion, deletion, or editor access. Raw-only equations keep their original source because the browser does not parse raw LaTeX into equation ASTs. Document editor v2 defaults to **`tex-svg.js`**; use `tex-chtml.js` only if you pass `mathOutput="chtml"`.
335
+ Host apps still register BuTeX with MathJax before preview rendering. `uiLocale` selects Arabic (`"ar"`, the default) or English (`"en"`) document-editor chrome and is passed to the embedded equation editor. `documentDirection` independently controls prose inputs and preview flow without creating a second document tree. `equationSide` independently controls whether structured equations open, render, and save from the `"english"` or `"arabic"` side. Set `editableEquations={false}` to show math islands without equation insertion, deletion, or editor access. Set `previewOnly={true}` to render only the read-only document preview with no toolbar, editor panel, or equation drawer. Raw-only equations keep their original source because the browser does not parse raw LaTeX into equation ASTs. Document editor v2 defaults to **`tex-svg.js`**; use `tex-chtml.js` only if you pass `mathOutput="chtml"`.
258
336
 
259
337
  ### Styling/theming contract
260
338
 
@@ -101,6 +101,14 @@ ${BUTEX_TAKWEEN_FONT_FACE_CSS}
101
101
  var BUTEX_CHROME_CSS = `
102
102
  ${BUTEX_FONT_FACE_CSS}
103
103
 
104
+ /* Guard against host CSS resets (e.g. Tailwind Preflight's \`svg { display: block }\`).
105
+ * MathJax relies on the browser default \`display: inline\` for its SVG output; with
106
+ * MathJax v4 inline line-breaking an equation can be emitted as several sibling
107
+ * <svg> chunks, and a block-level reset stacks them vertically. */
108
+ mjx-container svg {
109
+ display: inline;
110
+ }
111
+
104
112
  /* BuTeX: Arabic sqrt \u2014 outer mirror entire radical, inner unmirror index & radicand */
105
113
  mjx-container[jax="CHTML"] .mjx-rtl-mirror {
106
114
  transform: scaleX(-1);