@drghaliasri/butex 5.5.5 → 5.6.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.
@@ -65,7 +65,9 @@ function butexBasmalaDisplayTex() {
65
65
  }
66
66
  function butexBasmalaDisplayLatex() {
67
67
  return `\\[
68
- ${butexBasmalaDisplayTex()}
68
+ \\begin{gathered}
69
+ ${BASMALA_LINES.map((line) => butexMaghribiDisplayTex(line)).join(" \\\\\n")}
70
+ \\end{gathered}
69
71
  \\]`;
70
72
  }
71
73
  function butexInColumnMaketitleHook() {
@@ -2067,6 +2069,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2067
2069
  category: "operators1",
2068
2070
  Tex: "\\neq",
2069
2071
  mirror: true,
2072
+ compileMirror: true,
2070
2073
  Label: "\u2260",
2071
2074
  title: "\u0644\u0627 \u064A\u0633\u0627\u0648\u064A",
2072
2075
  svg_path: null
@@ -2106,6 +2109,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2106
2109
  Tex: "\\leq",
2107
2110
  mirror: true,
2108
2111
  displayMirror: false,
2112
+ compileMirror: true,
2109
2113
  Label: "\u2264",
2110
2114
  title: "\u0623\u0635\u063A\u0631 \u0645\u0646 \u0623\u0648 \u064A\u0633\u0627\u0648\u064A",
2111
2115
  svg_path: null
@@ -2116,6 +2120,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2116
2120
  Tex: "\\geq",
2117
2121
  mirror: true,
2118
2122
  displayMirror: false,
2123
+ compileMirror: true,
2119
2124
  Label: "\u2265",
2120
2125
  title: "\u0623\u0643\u0628\u0631 \u0645\u0646 \u0623\u0648 \u064A\u0633\u0627\u0648\u064A",
2121
2126
  svg_path: null
@@ -2126,6 +2131,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2126
2131
  Tex: "\\coloneqq",
2127
2132
  mirror: true,
2128
2133
  displayMirror: false,
2134
+ compileMirror: true,
2129
2135
  Label: "\u2254",
2130
2136
  title: "\u064A\u0639\u0631\u0641 \u0628\u0623\u0646\u0647 \u064A\u0633\u0627\u0648\u064A",
2131
2137
  svg_path: null
@@ -2136,6 +2142,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2136
2142
  Tex: "\\eqqcolon",
2137
2143
  mirror: true,
2138
2144
  displayMirror: false,
2145
+ compileMirror: true,
2139
2146
  Label: "\u2255",
2140
2147
  title: "\u064A\u0633\u0627\u0648\u064A \u0628\u0627\u0644\u062A\u0639\u0631\u064A\u0641",
2141
2148
  svg_path: null
@@ -2147,6 +2154,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2147
2154
  Tex: "\\propto",
2148
2155
  mirror: true,
2149
2156
  displayMirror: false,
2157
+ compileMirror: true,
2150
2158
  Label: "\u221D",
2151
2159
  title: "\u064A\u062A\u0646\u0627\u0633\u0628 \u0645\u0639",
2152
2160
  svg_path: null
@@ -2157,6 +2165,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2157
2165
  Tex: "\\in",
2158
2166
  mirror: true,
2159
2167
  displayMirror: false,
2168
+ compileMirror: true,
2160
2169
  Label: "\u2208",
2161
2170
  title: "\u064A\u0646\u062A\u0645\u064A \u0625\u0644\u0649",
2162
2171
  svg_path: null
@@ -2177,6 +2186,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2177
2186
  Tex: "\\subset",
2178
2187
  mirror: true,
2179
2188
  displayMirror: false,
2189
+ compileMirror: true,
2180
2190
  Label: "\u2282",
2181
2191
  title: "\u0645\u062C\u0645\u0648\u0639\u0629 \u062C\u0632\u0626\u064A\u0629 \u0645\u0646",
2182
2192
  svg_path: null
@@ -2187,6 +2197,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2187
2197
  Tex: "\\supset",
2188
2198
  mirror: true,
2189
2199
  displayMirror: false,
2200
+ compileMirror: true,
2190
2201
  Label: "\u2283",
2191
2202
  title: "\u0645\u062C\u0645\u0648\u0639\u0629 \u0634\u0627\u0645\u0644\u0629 \u0644\u0640",
2192
2203
  svg_path: null
@@ -2197,6 +2208,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2197
2208
  Tex: "\\subseteq",
2198
2209
  mirror: true,
2199
2210
  displayMirror: false,
2211
+ compileMirror: true,
2200
2212
  Label: "\u2286",
2201
2213
  title: "\u0645\u062C\u0645\u0648\u0639\u0629 \u062C\u0632\u0626\u064A\u0629 \u0623\u0648 \u062A\u0633\u0627\u0648\u064A",
2202
2214
  svg_path: null
@@ -2207,6 +2219,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2207
2219
  Tex: "\\supseteq",
2208
2220
  mirror: true,
2209
2221
  displayMirror: false,
2222
+ compileMirror: true,
2210
2223
  Label: "\u2287",
2211
2224
  title: "\u0645\u062C\u0645\u0648\u0639\u0629 \u0634\u0627\u0645\u0644\u0629 \u0623\u0648 \u062A\u0633\u0627\u0648\u064A",
2212
2225
  svg_path: null
@@ -2247,6 +2260,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2247
2260
  Tex: "\\nsubseteq",
2248
2261
  mirror: true,
2249
2262
  displayMirror: false,
2263
+ compileMirror: true,
2250
2264
  Label: "\u2288",
2251
2265
  title: "\u0644\u064A\u0633\u062A \u0645\u062C\u0645\u0648\u0639\u0629 \u062C\u0632\u0626\u064A\u0629 \u0623\u0648 \u062A\u0633\u0627\u0648\u064A",
2252
2266
  svg_path: null
@@ -2257,6 +2271,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2257
2271
  Tex: "\\nsupseteq",
2258
2272
  mirror: true,
2259
2273
  displayMirror: false,
2274
+ compileMirror: true,
2260
2275
  Label: "\u2289",
2261
2276
  title: "\u0644\u064A\u0633\u062A \u0645\u062C\u0645\u0648\u0639\u0629 \u0634\u0627\u0645\u0644\u0629 \u0623\u0648 \u062A\u0633\u0627\u0648\u064A",
2262
2277
  svg_path: null
@@ -2304,6 +2319,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2304
2319
  Tex: "\\ddots",
2305
2320
  mirror: true,
2306
2321
  displayMirror: false,
2322
+ compileMirror: true,
2307
2323
  Label: "\u22F1",
2308
2324
  title: "\u0646\u0642\u0627\u0637 \u0642\u0637\u0631\u064A\u0629",
2309
2325
  svg_path: null
@@ -2323,6 +2339,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2323
2339
  category: "operators3",
2324
2340
  Tex: "\\implies",
2325
2341
  mirror: true,
2342
+ compileMirror: true,
2326
2343
  Label: "\u21D2",
2327
2344
  title: "\u064A\u0633\u062A\u0644\u0632\u0645",
2328
2345
  svg_path: null
@@ -2332,6 +2349,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2332
2349
  category: "operators3",
2333
2350
  Tex: "\\impliedby",
2334
2351
  mirror: true,
2352
+ compileMirror: true,
2335
2353
  Label: "\u21D0",
2336
2354
  title: "\u0645\u0633\u062A\u0644\u0632\u0645 \u0645\u0646",
2337
2355
  svg_path: null
@@ -2350,6 +2368,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2350
2368
  category: "operators3",
2351
2369
  Tex: "\\Longrightarrow",
2352
2370
  mirror: true,
2371
+ compileMirror: true,
2353
2372
  Label: "\u27F9",
2354
2373
  title: "\u0633\u0647\u0645 \u0645\u0632\u062F\u0648\u062C \u0637\u0648\u064A\u0644 \u0625\u0644\u0649 \u0627\u0644\u064A\u0645\u064A\u0646",
2355
2374
  svg_path: null
@@ -2359,6 +2378,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2359
2378
  category: "operators3",
2360
2379
  Tex: "\\Longleftarrow",
2361
2380
  mirror: true,
2381
+ compileMirror: true,
2362
2382
  Label: "\u27F8",
2363
2383
  title: "\u0633\u0647\u0645 \u0645\u0632\u062F\u0648\u062C \u0637\u0648\u064A\u0644 \u0625\u0644\u0649 \u0627\u0644\u064A\u0633\u0627\u0631",
2364
2384
  svg_path: null
@@ -2368,6 +2388,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2368
2388
  category: "operators3",
2369
2389
  Tex: "\\to",
2370
2390
  mirror: true,
2391
+ compileMirror: true,
2371
2392
  Label: "\u2192",
2372
2393
  title: "\u064A\u0624\u0648\u0644 \u0625\u0644\u0649",
2373
2394
  svg_path: null
@@ -2377,6 +2398,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2377
2398
  category: "operators3",
2378
2399
  Tex: "\\rightleftharpoons",
2379
2400
  mirror: true,
2401
+ compileMirror: true,
2380
2402
  Label: "\u21CC",
2381
2403
  title: "\u0627\u062A\u0632\u0627\u0646",
2382
2404
  svg_path: null
@@ -2386,6 +2408,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2386
2408
  category: "operators3",
2387
2409
  Tex: "\\leftarrow",
2388
2410
  mirror: true,
2411
+ compileMirror: true,
2389
2412
  Label: "\u2190",
2390
2413
  title: "\u0633\u0647\u0645 \u0625\u0644\u0649 \u0627\u0644\u064A\u0633\u0627\u0631",
2391
2414
  svg_path: null
@@ -2395,6 +2418,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2395
2418
  category: "operators3",
2396
2419
  Tex: "\\rightarrow",
2397
2420
  mirror: true,
2421
+ compileMirror: true,
2398
2422
  Label: "\u2192",
2399
2423
  title: "\u0633\u0647\u0645 \u0625\u0644\u0649 \u0627\u0644\u064A\u0645\u064A\u0646",
2400
2424
  svg_path: null
@@ -2404,6 +2428,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2404
2428
  category: "operators3",
2405
2429
  Tex: "\\Leftarrow",
2406
2430
  mirror: true,
2431
+ compileMirror: true,
2407
2432
  Label: "\u21D0",
2408
2433
  title: "\u0633\u0647\u0645 \u0645\u0632\u062F\u0648\u062C \u0625\u0644\u0649 \u0627\u0644\u064A\u0633\u0627\u0631",
2409
2434
  svg_path: null
@@ -2413,6 +2438,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2413
2438
  category: "operators3",
2414
2439
  Tex: "\\Rightarrow",
2415
2440
  mirror: true,
2441
+ compileMirror: true,
2416
2442
  Label: "\u21D2",
2417
2443
  title: "\u0633\u0647\u0645 \u0645\u0632\u062F\u0648\u062C \u0625\u0644\u0649 \u0627\u0644\u064A\u0645\u064A\u0646",
2418
2444
  svg_path: null
@@ -2422,6 +2448,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2422
2448
  category: "operators3",
2423
2449
  Tex: "\\leftharpoonup",
2424
2450
  mirror: true,
2451
+ compileMirror: true,
2425
2452
  Label: "\u21BC",
2426
2453
  title: "\u0633\u0647\u0645 \u062E\u0637\u0627\u0641\u064A \u0639\u0644\u0648\u064A \u0625\u0644\u0649 \u0627\u0644\u064A\u0633\u0627\u0631",
2427
2454
  svg_path: null
@@ -2431,6 +2458,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2431
2458
  category: "operators3",
2432
2459
  Tex: "\\rightharpoonup",
2433
2460
  mirror: true,
2461
+ compileMirror: true,
2434
2462
  Label: "\u21C0",
2435
2463
  title: "\u0633\u0647\u0645 \u062E\u0637\u0627\u0641\u064A \u0639\u0644\u0648\u064A \u0625\u0644\u0649 \u0627\u0644\u064A\u0645\u064A\u0646",
2436
2464
  svg_path: null
@@ -2440,6 +2468,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2440
2468
  category: "operators3",
2441
2469
  Tex: "\\leftharpoondown",
2442
2470
  mirror: true,
2471
+ compileMirror: true,
2443
2472
  Label: "\u21BD",
2444
2473
  title: "\u0633\u0647\u0645 \u062E\u0637\u0627\u0641\u064A \u0633\u0641\u0644\u064A \u0625\u0644\u0649 \u0627\u0644\u064A\u0633\u0627\u0631",
2445
2474
  svg_path: null
@@ -2449,6 +2478,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2449
2478
  category: "operators3",
2450
2479
  Tex: "\\rightharpoondown",
2451
2480
  mirror: true,
2481
+ compileMirror: true,
2452
2482
  Label: "\u21C1",
2453
2483
  title: "\u0633\u0647\u0645 \u062E\u0637\u0627\u0641\u064A \u0633\u0641\u0644\u064A \u0625\u0644\u0649 \u0627\u0644\u064A\u0645\u064A\u0646",
2454
2484
  svg_path: null
@@ -2459,6 +2489,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2459
2489
  category: "integrals",
2460
2490
  Tex: "\\int",
2461
2491
  mirror: true,
2492
+ compileMirror: true,
2462
2493
  Label: "\u222B",
2463
2494
  title: "\u062A\u0643\u0627\u0645\u0644",
2464
2495
  svg_path: null
@@ -2469,6 +2500,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2469
2500
  Tex: "\\iint",
2470
2501
  mirror: true,
2471
2502
  displayMirror: false,
2503
+ compileMirror: true,
2472
2504
  Label: "\u222C",
2473
2505
  title: "\u062A\u0643\u0627\u0645\u0644 \u0645\u0632\u062F\u0648\u062C",
2474
2506
  svg_path: null
@@ -2479,6 +2511,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2479
2511
  Tex: "\\iiint",
2480
2512
  mirror: true,
2481
2513
  displayMirror: false,
2514
+ compileMirror: true,
2482
2515
  Label: "\u222D",
2483
2516
  title: "\u062A\u0643\u0627\u0645\u0644 \u062B\u0644\u0627\u062B\u064A",
2484
2517
  svg_path: null
@@ -2489,6 +2522,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2489
2522
  Tex: "\\iiiint",
2490
2523
  mirror: true,
2491
2524
  displayMirror: false,
2525
+ compileMirror: true,
2492
2526
  Label: "\u2A0C",
2493
2527
  title: "\u062A\u0643\u0627\u0645\u0644 \u0631\u0628\u0627\u0639\u064A",
2494
2528
  svg_path: null
@@ -2499,6 +2533,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2499
2533
  Tex: "\\oint",
2500
2534
  mirror: true,
2501
2535
  displayMirror: false,
2536
+ compileMirror: true,
2502
2537
  Label: "\u222E",
2503
2538
  title: "\u062A\u0643\u0627\u0645\u0644 \u0645\u063A\u0644\u0642",
2504
2539
  svg_path: null
@@ -2509,6 +2544,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2509
2544
  Tex: "\\oiint",
2510
2545
  mirror: true,
2511
2546
  displayMirror: false,
2547
+ compileMirror: true,
2512
2548
  Label: "\u222F",
2513
2549
  title: "\u062A\u0643\u0627\u0645\u0644 \u0633\u0637\u062D\u064A \u0645\u063A\u0644\u0642",
2514
2550
  svg_path: null
@@ -2519,6 +2555,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2519
2555
  Tex: "\\oiiint",
2520
2556
  mirror: true,
2521
2557
  displayMirror: false,
2558
+ compileMirror: true,
2522
2559
  Label: "\u2230",
2523
2560
  title: "\u062A\u0643\u0627\u0645\u0644 \u062D\u062C\u0645\u064A \u0645\u063A\u0644\u0642",
2524
2561
  svg_path: null
@@ -2528,8 +2565,9 @@ function shouldMirrorOperatorDisplay(command) {
2528
2565
  return command?.displayMirror ?? command?.mirror ?? false;
2529
2566
  }
2530
2567
  var MIRRORED_OPERATOR_TEX = Object.values(ATOMIC_OPERATOR_COMMANDS).filter((command) => command.mirror).map((command) => command.Tex).sort((a, b) => b.length - a.length);
2531
- function matchingMirroredOperator(tex, index) {
2532
- for (const operatorTex of MIRRORED_OPERATOR_TEX) {
2568
+ var COMPILE_MIRRORED_OPERATOR_TEX = Object.values(ATOMIC_OPERATOR_COMMANDS).filter((command) => "compileMirror" in command && command.compileMirror).map((command) => command.Tex).sort((a, b) => b.length - a.length);
2569
+ function matchingMirroredOperatorFrom(tex, index, operatorTexList) {
2570
+ for (const operatorTex of operatorTexList) {
2533
2571
  if (!tex.startsWith(operatorTex, index)) {
2534
2572
  continue;
2535
2573
  }
@@ -2560,19 +2598,26 @@ function findMatchingBrace(tex, openIndex) {
2560
2598
  }
2561
2599
  return -1;
2562
2600
  }
2563
- function mirrorBuTeXOperatorsInTex(tex) {
2601
+ function mirrorBuTeXOperatorsInTex(tex, options = {}) {
2602
+ const mirroredOperatorTex = options.target === "compile" ? COMPILE_MIRRORED_OPERATOR_TEX : MIRRORED_OPERATOR_TEX;
2564
2603
  let result = "";
2565
2604
  let index = 0;
2566
2605
  while (index < tex.length) {
2567
2606
  if (tex.startsWith("\\butexmirror{", index)) {
2568
2607
  const end = findMatchingBrace(tex, index + "\\butexmirror".length);
2569
2608
  if (end !== -1) {
2570
- result += tex.slice(index, end + 1);
2609
+ const bodyStart = index + "\\butexmirror{".length;
2610
+ const body = tex.slice(bodyStart, end);
2611
+ if (options.target === "compile" && MIRRORED_OPERATOR_TEX.includes(body) && !mirroredOperatorTex.includes(body)) {
2612
+ result += body;
2613
+ } else {
2614
+ result += tex.slice(index, end + 1);
2615
+ }
2571
2616
  index = end + 1;
2572
2617
  continue;
2573
2618
  }
2574
2619
  }
2575
- const operatorTex = matchingMirroredOperator(tex, index);
2620
+ const operatorTex = matchingMirroredOperatorFrom(tex, index, mirroredOperatorTex);
2576
2621
  if (operatorTex) {
2577
2622
  result += `\\butexmirror{${operatorTex}}`;
2578
2623
  index += operatorTex.length;
@@ -8234,18 +8279,19 @@ function mathNodeFromSession(session, opening = "$", closing = "$") {
8234
8279
  }
8235
8280
  return { nodeType: "MathObject", mathMode: opening, lines: [], closing };
8236
8281
  }
8237
- function mathTokenSourceForSide(token, side) {
8282
+ function mathTokenSourceForSide(token, side, digitForm) {
8238
8283
  if (!token.math || token.sourceOwner === "raw") {
8239
8284
  return token.source;
8240
8285
  }
8241
- if (token.sourceSide === side) {
8286
+ if (token.sourceSide === side && digitForm === void 0) {
8242
8287
  return token.source;
8243
8288
  }
8244
8289
  const result = mathTokenToEditorSession(token.math, side);
8245
8290
  if (!result.editable) {
8246
8291
  return token.source;
8247
8292
  }
8248
- return mathSourceFromSession(result.session, side, token.opening, token.closing);
8293
+ const session = digitForm === void 0 ? result.session : setCurrentDigitForm(result.session, digitForm);
8294
+ return mathSourceFromSession(session, side, token.opening, token.closing);
8249
8295
  }
8250
8296
 
8251
8297
  // src/document2/commands.ts
@@ -8979,6 +9025,19 @@ function document2KeyError(key, namespace = {}) {
8979
9025
  }
8980
9026
 
8981
9027
  // src/document2/arabicPreamble.ts
9028
+ function fontOptions(digitsMapping, includeScript = true) {
9029
+ const parts = [];
9030
+ if (includeScript) {
9031
+ parts.push("Script=Arabic");
9032
+ }
9033
+ if (digitsMapping !== "digits") {
9034
+ parts.push(`Mapping=${digitsMapping}`);
9035
+ }
9036
+ if (parts.length === 0) {
9037
+ return "";
9038
+ }
9039
+ return `[${parts.join(",")}]`;
9040
+ }
8982
9041
  function arabicXeLatexPreamblePkg(twocolumn = false) {
8983
9042
  const classOptions = twocolumn ? "12pt,a4paper,notitlepage,twocolumn" : "12pt,a4paper,notitlepage";
8984
9043
  return `
@@ -9007,25 +9066,27 @@ function arabicXeLatexPreamblePkg(twocolumn = false) {
9007
9066
  % save back tick for use - copy paste -> ` + "`";
9008
9067
  }
9009
9068
  function arabicXeLatexPreambleFont(digitsMapping = "arabicdigits") {
9010
- const customFonts = NON_DEFAULT_CHARACTER_FONT_SPECS.filter((font) => font.latexFontCommand && font.latexFontFamily).map((font) => `\\newfontfamily${font.latexFontCommand}[Script=Arabic,Mapping=${digitsMapping}]{${font.latexFontFamily}}`).join("\n");
9069
+ const customFonts = NON_DEFAULT_CHARACTER_FONT_SPECS.filter((font) => font.latexFontCommand && font.latexFontFamily).map((font) => `\\newfontfamily${font.latexFontCommand}${fontOptions(digitsMapping)}{${font.latexFontFamily}}`).join("\n");
9070
+ const mathFontOptions = fontOptions(digitsMapping, false);
9011
9071
  return `
9012
9072
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9013
9073
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9014
- % Toggle between eastern and western digits by changing the Mapping in the below fonts (inside math font as well) between "arabicdigits" and "digits"
9074
+ % Persian digits: Mapping=farsidigits
9075
+ % Arabic-Indic digits: Mapping=arabicdigits
9076
+ % Western digits: omit Mapping entirely
9015
9077
  \\setdefaultlanguage[calendar=gregorian]{arabic} % from polyglossia
9016
- \\setmainfont[Script=Arabic , Mapping=${digitsMapping}]{Amiri}
9078
+ \\setmainfont${fontOptions(digitsMapping)}{Amiri}
9017
9079
  ${customFonts}
9018
- \\newfontfamily\\boldarabic[Script=Arabic,Mapping=${digitsMapping}]{Amiri Bold}
9019
- \\newfontfamily\\italicarabic[Script=Arabic,Mapping=${digitsMapping}]{Amiri Italic}
9080
+ \\newfontfamily\\boldarabic${fontOptions(digitsMapping)}{Amiri Bold}
9081
+ \\newfontfamily\\italicarabic${fontOptions(digitsMapping)}{Amiri Italic}
9020
9082
 
9021
9083
  % for polyglossia url I dont know, sugggested by cursor
9022
- \\newfontfamily\\arabicfonttt[Script=Arabic,Mapping=${digitsMapping}]{Amiri}
9023
- \\newfontfamily\\arabicfontsf[Script=Arabic,Mapping=${digitsMapping}]{Amiri}
9084
+ \\newfontfamily\\arabicfonttt${fontOptions(digitsMapping)}{Amiri}
9085
+ \\newfontfamily\\arabicfontsf${fontOptions(digitsMapping)}{Amiri}
9024
9086
 
9025
9087
 
9026
9088
  % Explicitly set math font to XITS Math
9027
- % Remove "Script=Arabic" to cancel reflected symbols and other RTL symbols
9028
- \\setmathfont[Script=Arabic , Mapping=${digitsMapping}]{XITS Math} % Ensure XITS Math is correctly installed and available
9089
+ \\setmathfont${mathFontOptions}{XITS Math} % Ensure XITS Math is correctly installed and available
9029
9090
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9030
9091
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9031
9092
  `;
@@ -9187,8 +9248,20 @@ function getArabicXeLatexPreamble(digitsMappingOrOptions = "arabicdigits") {
9187
9248
  }
9188
9249
 
9189
9250
  // src/document2/exportLatex.ts
9251
+ function digitsMappingFromDigitForm(digitForm) {
9252
+ if (digitForm === "western") {
9253
+ return "digits";
9254
+ }
9255
+ if (digitForm === "persianIndic") {
9256
+ return "farsidigits";
9257
+ }
9258
+ return "arabicdigits";
9259
+ }
9190
9260
  function mathBodyLatex(token) {
9191
- if (!token.math || token.sourceOwner === "raw" || token.sourceOwner === "editor") {
9261
+ if (token.sourceOwner === "editor") {
9262
+ return stripDisplayMathDelimiters(mirrorBuTeXOperatorsInTex(token.source, { target: "compile" }));
9263
+ }
9264
+ if (!token.math || token.sourceOwner === "raw") {
9192
9265
  return stripDisplayMathDelimiters(token.source);
9193
9266
  }
9194
9267
  const rendered = renderMathNodeLatex(token.math);
@@ -9224,7 +9297,10 @@ ${body}
9224
9297
  \\label{${token.label.trim()}}
9225
9298
  \\end{equation}`;
9226
9299
  }
9227
- if (!token.math || token.sourceOwner === "raw" || token.sourceOwner === "editor") {
9300
+ if (token.sourceOwner === "editor") {
9301
+ return mirrorBuTeXOperatorsInTex(token.source, { target: "compile" });
9302
+ }
9303
+ if (!token.math || token.sourceOwner === "raw") {
9228
9304
  return token.source;
9229
9305
  }
9230
9306
  return renderMathNodeLatex(token.math);
@@ -9342,7 +9418,7 @@ function articleMaketitlePreamble(meta, twocolumn = false) {
9342
9418
  if (meta.authors.trim().length > 0) {
9343
9419
  parts.push(`\\author{${authorLatex(meta.authors)}}`);
9344
9420
  }
9345
- parts.push(`\\date{${formatHijriDate(meta.date, { locale: "ar", digitForm: "arabicIndic" })}}`);
9421
+ parts.push(`\\date{${formatHijriDate(meta.date, { locale: "ar", digitForm: "western" })}}`);
9346
9422
  return parts.join("\n");
9347
9423
  }
9348
9424
  function articleFrontMatterLatex(meta) {
@@ -9374,7 +9450,7 @@ function document2Latex(document2, options = {}) {
9374
9450
  ${body}` : body;
9375
9451
  }
9376
9452
  const preamble = getArabicXeLatexPreamble({
9377
- digitsMapping: options.digitsMapping ?? "arabicdigits",
9453
+ digitsMapping: options.digitsMapping ?? digitsMappingFromDigitForm(options.digitForm),
9378
9454
  twocolumn
9379
9455
  }) + "\n" + articleMaketitlePreamble(meta, twocolumn);
9380
9456
  return `${preamble}
@@ -9630,8 +9706,8 @@ function remapSelectionAfterRangeMove(selection, direction) {
9630
9706
  }
9631
9707
 
9632
9708
  // src/document2/previewModel.ts
9633
- function mathTex(token, equationSide) {
9634
- return mathTokenSourceForSide(token, equationSide);
9709
+ function mathTex(token, equationSide, digitForm) {
9710
+ return mathTokenSourceForSide(token, equationSide, digitForm);
9635
9711
  }
9636
9712
  function previewInlines(field, islands, output, equationSide, document2, previewOptions) {
9637
9713
  return field.tokens.map((token) => {
@@ -9663,7 +9739,7 @@ function previewInlines(field, islands, output, equationSide, document2, preview
9663
9739
  }
9664
9740
  const island = {
9665
9741
  id: token.id,
9666
- tex: mathTex(token, equationSide),
9742
+ tex: mathTex(token, equationSide, previewOptions.digitForm),
9667
9743
  display: token.display,
9668
9744
  output,
9669
9745
  editable: token.editable
@@ -10306,6 +10382,32 @@ function focusArticleMetaPanel(panel) {
10306
10382
  // src/react-document2/ButexDocumentEditor2.tsx
10307
10383
  import { useCallback as useCallback2, useEffect as useEffect9, useMemo as useMemo2, useRef as useRef8, useState as useState12 } from "react";
10308
10384
 
10385
+ // src/debugJson.ts
10386
+ function lineColumnForPosition(text, position) {
10387
+ const before = text.slice(0, Math.max(0, position));
10388
+ const lines = before.split("\n");
10389
+ return {
10390
+ line: lines.length,
10391
+ column: (lines[lines.length - 1]?.length ?? 0) + 1
10392
+ };
10393
+ }
10394
+ function parseJsonDebugInput(text) {
10395
+ try {
10396
+ return { ok: true, value: JSON.parse(text) };
10397
+ } catch (error) {
10398
+ const message = error instanceof Error ? error.message : String(error);
10399
+ const positionMatch = message.match(/position\s+(\d+)/i);
10400
+ if (positionMatch) {
10401
+ const position = Number(positionMatch[1]);
10402
+ if (Number.isFinite(position)) {
10403
+ const location = lineColumnForPosition(text, position);
10404
+ return { ok: false, error: `Invalid JSON at line ${String(location.line)}, column ${String(location.column)}: ${message}` };
10405
+ }
10406
+ }
10407
+ return { ok: false, error: `Invalid JSON: ${message}` };
10408
+ }
10409
+ }
10410
+
10309
10411
  // src/react-document2/BlockEditor.tsx
10310
10412
  import { useState as useState3 } from "react";
10311
10413
 
@@ -10845,6 +10947,7 @@ function MathChip({
10845
10947
  token,
10846
10948
  output = "svg",
10847
10949
  documentDirection = "rtl",
10950
+ digitForm,
10848
10951
  equationSide = "arabic",
10849
10952
  editable = true,
10850
10953
  uiLocale = "ar",
@@ -10856,7 +10959,7 @@ function MathChip({
10856
10959
  onTextInputFromFocus
10857
10960
  }) {
10858
10961
  const messages = document2Messages(uiLocale);
10859
- const tex = mathTokenSourceForSide(token, equationSide);
10962
+ const tex = mathTokenSourceForSide(token, equationSide, digitForm);
10860
10963
  const forwardArrowKey = documentDirection === "rtl" ? "ArrowLeft" : "ArrowRight";
10861
10964
  const backwardArrowKey = documentDirection === "rtl" ? "ArrowRight" : "ArrowLeft";
10862
10965
  const island = /* @__PURE__ */ jsx4(MathIsland, { id: token.id, tex, display: token.display, output });
@@ -11266,6 +11369,7 @@ function InlineField({
11266
11369
  token,
11267
11370
  output: mathOutput,
11268
11371
  equationSide,
11372
+ digitForm,
11269
11373
  editable: editableEquations,
11270
11374
  uiLocale,
11271
11375
  buttonRef: (element) => {
@@ -12817,6 +12921,11 @@ var WIDGET_CHROME_CSS = `
12817
12921
  font-family: ${BUTEX_DIWANI_OUTLINE_FONT_STACK};
12818
12922
  }
12819
12923
 
12924
+ .butex-widget .font-mode-btn--maghribi,
12925
+ .butex-widget .character-font-option--maghribi {
12926
+ font-family: ${BUTEX_MAGHRIBI_FONT_STACK};
12927
+ }
12928
+
12820
12929
  .butex-widget .character-font-options {
12821
12930
  position: absolute;
12822
12931
  z-index: 10;
@@ -13351,6 +13460,36 @@ var WIDGET_CHROME_CSS = `
13351
13460
  background: var(--butex-dev-inset-bg);
13352
13461
  color: var(--butex-dev-inset-fg);
13353
13462
  }
13463
+
13464
+ .butex-widget .debug-json-import {
13465
+ display: grid;
13466
+ gap: 8px;
13467
+ margin-bottom: 10px;
13468
+ }
13469
+
13470
+ .butex-widget .debug-json-import textarea {
13471
+ min-height: 150px;
13472
+ resize: vertical;
13473
+ border: 1px solid var(--butex-dev-inset-border);
13474
+ border-radius: 8px;
13475
+ padding: 8px 10px;
13476
+ direction: ltr;
13477
+ text-align: left;
13478
+ font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
13479
+ font-size: 11px;
13480
+ background: var(--butex-dev-inset-bg);
13481
+ color: var(--butex-dev-inset-fg);
13482
+ }
13483
+
13484
+ .butex-widget .debug-json-error {
13485
+ margin: 0;
13486
+ border: 1px solid rgba(220, 38, 38, 0.45);
13487
+ background: rgba(254, 226, 226, 0.9);
13488
+ color: #991b1b;
13489
+ border-radius: 8px;
13490
+ padding: 8px 10px;
13491
+ white-space: pre-wrap;
13492
+ }
13354
13493
  `.trim();
13355
13494
  var CHROME_STYLE_ID = "butex-widget-chrome-css";
13356
13495
  function injectWidgetChromeCss(doc) {
@@ -13479,6 +13618,7 @@ ${latex || messages.empty}`;
13479
13618
  var ButexEditor = forwardRef(
13480
13619
  function ButexEditor2({ className, debug = false, defaultSide, uiLocale = "ar", initialSession, onSessionChange }, ref) {
13481
13620
  const messages = equationEditorMessages(uiLocale);
13621
+ const debugEnabled = debug || typeof window !== "undefined" && new URLSearchParams(window.location.search).get("debug") === "1";
13482
13622
  const wrapperRef = useRef6(null);
13483
13623
  const surfaceRef = useRef6(null);
13484
13624
  const inputRef = useRef6(null);
@@ -13496,7 +13636,7 @@ var ButexEditor = forwardRef(
13496
13636
  const digitFormBtnRef = useRef6(null);
13497
13637
  const runtimeRef = useRef6(null);
13498
13638
  const debugRef = useRef6(debug);
13499
- debugRef.current = debug;
13639
+ debugRef.current = debugEnabled;
13500
13640
  const uiLocaleRef = useRef6(uiLocale);
13501
13641
  uiLocaleRef.current = uiLocale;
13502
13642
  const onSessionChangeRef = useRef6(onSessionChange);
@@ -13504,6 +13644,9 @@ var ButexEditor = forwardRef(
13504
13644
  const debugBodyHiddenRef = useRef6(false);
13505
13645
  const [debugBodyHidden, setDebugBodyHidden] = useState7(false);
13506
13646
  debugBodyHiddenRef.current = debugBodyHidden;
13647
+ const [debugImportOpen, setDebugImportOpen] = useState7(false);
13648
+ const [debugImportText, setDebugImportText] = useState7("");
13649
+ const [debugImportError, setDebugImportError] = useState7("");
13507
13650
  const [digitMenuOpen, setDigitMenuOpen] = useState7(false);
13508
13651
  const [characterFontMenuOpen, setCharacterFontMenuOpen] = useState7(false);
13509
13652
  const [delimiterMenuOpen, setDelimiterMenuOpen] = useState7(false);
@@ -13584,6 +13727,54 @@ ${arabic || currentMessages.empty}`;
13584
13727
  }, []);
13585
13728
  const updatePreviewRef = useRef6(updatePreview);
13586
13729
  updatePreviewRef.current = updatePreview;
13730
+ async function copyDebugText(text) {
13731
+ try {
13732
+ await navigator.clipboard.writeText(text);
13733
+ } catch {
13734
+ }
13735
+ }
13736
+ function currentMathObjectJsonText() {
13737
+ const session = runtimeRef.current?.getSession();
13738
+ if (!session) {
13739
+ return "";
13740
+ }
13741
+ const math = mathNodeFromEditorSession(session);
13742
+ if (!math.ok) {
13743
+ return "";
13744
+ }
13745
+ return JSON.stringify(toMathObjectJson(math.math), null, 2);
13746
+ }
13747
+ function openDebugMathObjectImport() {
13748
+ setDebugImportText(currentMathObjectJsonText());
13749
+ setDebugImportError("");
13750
+ setDebugImportOpen(true);
13751
+ }
13752
+ function applyDebugMathObjectImport() {
13753
+ const parsed = parseJsonDebugInput(debugImportText);
13754
+ if (!parsed.ok) {
13755
+ setDebugImportError(parsed.error);
13756
+ return;
13757
+ }
13758
+ try {
13759
+ const math = fromMathObjectJson(parsed.value, activeEditorSide);
13760
+ const result = mathObjectToEditorSession(math);
13761
+ if (!result.editable) {
13762
+ setDebugImportError(result.reason);
13763
+ return;
13764
+ }
13765
+ const next = { ...result.session, activeSide: activeEditorSide };
13766
+ runtimeRef.current?.setSession(next);
13767
+ setSelectedDigitForm(next.currentDigitForm ?? "western");
13768
+ setSelectedCharacterFont(next.currentCharacterFont ?? "default");
13769
+ setActiveEditorSide(next.activeSide);
13770
+ onSessionChangeRef.current?.(next);
13771
+ setDebugImportError("");
13772
+ setDebugImportOpen(false);
13773
+ void updatePreviewRef.current(next);
13774
+ } catch (importError) {
13775
+ setDebugImportError(importError instanceof Error ? importError.message : String(importError));
13776
+ }
13777
+ }
13587
13778
  useEffect6(() => {
13588
13779
  injectWidgetChromeCss();
13589
13780
  injectBuTeXEditorStyles(typeof document !== "undefined" ? document : void 0);
@@ -14744,7 +14935,7 @@ ${arabic || currentMessages.empty}`;
14744
14935
  /* @__PURE__ */ jsx12("div", { ref: renderErrorRef, className: "error", hidden: true })
14745
14936
  ] }),
14746
14937
  /* @__PURE__ */ jsx12("section", { className: "panel panel-preview", "aria-label": messages.renderPreview, children: /* @__PURE__ */ jsx12("div", { ref: mathOutputRef, className: "preview-box" }) }),
14747
- debug ? /* @__PURE__ */ jsxs10("section", { className: "panel", children: [
14938
+ debugEnabled ? /* @__PURE__ */ jsxs10("section", { className: "panel", children: [
14748
14939
  /* @__PURE__ */ jsxs10("div", { className: "dev-strip", children: [
14749
14940
  /* @__PURE__ */ jsx12("span", { className: "dev-badge", children: messages.development }),
14750
14941
  /* @__PURE__ */ jsx12("div", { ref: latexLinesRef, className: "ascii" }),
@@ -14752,6 +14943,8 @@ ${arabic || currentMessages.empty}`;
14752
14943
  ] }),
14753
14944
  /* @__PURE__ */ jsxs10("div", { style: { marginTop: 12 }, children: [
14754
14945
  /* @__PURE__ */ jsxs10("div", { className: "debug-head", children: [
14946
+ /* @__PURE__ */ jsx12("button", { type: "button", onClick: () => void copyDebugText(currentMathObjectJsonText()), children: "Copy MathObject JSON" }),
14947
+ /* @__PURE__ */ jsx12("button", { type: "button", "aria-expanded": debugImportOpen, onClick: openDebugMathObjectImport, children: "Import MathObject JSON" }),
14755
14948
  /* @__PURE__ */ jsx12(
14756
14949
  "button",
14757
14950
  {
@@ -14787,6 +14980,35 @@ ${arabic || currentMessages.empty}`;
14787
14980
  }
14788
14981
  )
14789
14982
  ] }),
14983
+ debugImportOpen ? /* @__PURE__ */ jsxs10("div", { className: "debug-json-import", children: [
14984
+ /* @__PURE__ */ jsx12(
14985
+ "textarea",
14986
+ {
14987
+ value: debugImportText,
14988
+ "aria-label": "Import MathObject JSON",
14989
+ spellCheck: false,
14990
+ onChange: (event) => {
14991
+ setDebugImportText(event.currentTarget.value);
14992
+ setDebugImportError("");
14993
+ }
14994
+ }
14995
+ ),
14996
+ /* @__PURE__ */ jsxs10("div", { className: "debug-head", children: [
14997
+ /* @__PURE__ */ jsx12("button", { type: "button", onClick: applyDebugMathObjectImport, children: "Apply" }),
14998
+ /* @__PURE__ */ jsx12(
14999
+ "button",
15000
+ {
15001
+ type: "button",
15002
+ onClick: () => {
15003
+ setDebugImportOpen(false);
15004
+ setDebugImportError("");
15005
+ },
15006
+ children: "Cancel"
15007
+ }
15008
+ )
15009
+ ] }),
15010
+ debugImportError ? /* @__PURE__ */ jsx12("p", { className: "debug-json-error", children: debugImportError }) : null
15011
+ ] }) : null,
14790
15012
  /* @__PURE__ */ jsx12("div", { ref: debugLogRef, className: "debug-log" })
14791
15013
  ] })
14792
15014
  ] }) : null
@@ -14812,6 +15034,7 @@ function keyErrorMessage2(error, messages) {
14812
15034
  return null;
14813
15035
  }
14814
15036
  function EquationDrawer({
15037
+ debug = false,
14815
15038
  session,
14816
15039
  reason,
14817
15040
  mathMode,
@@ -14929,7 +15152,7 @@ function EquationDrawer({
14929
15152
  /* @__PURE__ */ jsx13(
14930
15153
  ButexEditor,
14931
15154
  {
14932
- debug: false,
15155
+ debug,
14933
15156
  defaultSide: equationSide,
14934
15157
  uiLocale,
14935
15158
  initialSession: session,
@@ -16511,6 +16734,42 @@ var DOCUMENT2_WIDGET_CSS = `
16511
16734
  white-space: pre-wrap;
16512
16735
  }
16513
16736
 
16737
+ .butex-document2-widget__dev-actions {
16738
+ display: flex;
16739
+ flex-wrap: wrap;
16740
+ gap: 8px;
16741
+ margin: 0 0 10px;
16742
+ }
16743
+
16744
+ .butex-document2-widget__dev-import {
16745
+ display: grid;
16746
+ gap: 8px;
16747
+ margin-bottom: 12px;
16748
+ }
16749
+
16750
+ .butex-document2-widget__dev-import textarea {
16751
+ background: var(--butex-document2-dev-code-bg);
16752
+ border: 1px solid var(--butex-document2-dev-border);
16753
+ border-radius: 8px;
16754
+ color: var(--butex-document2-dev-code-fg);
16755
+ direction: ltr;
16756
+ font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
16757
+ min-height: 180px;
16758
+ padding: 10px;
16759
+ resize: vertical;
16760
+ text-align: left;
16761
+ }
16762
+
16763
+ .butex-document2-widget__dev-error {
16764
+ background: rgba(254, 226, 226, 0.9);
16765
+ border: 1px solid rgba(220, 38, 38, 0.45);
16766
+ border-radius: 8px;
16767
+ color: #991b1b;
16768
+ margin: 0;
16769
+ padding: 8px 10px;
16770
+ white-space: pre-wrap;
16771
+ }
16772
+
16514
16773
  .butex-document2-widget__dev-diagnostic {
16515
16774
  background: rgba(251, 191, 36, 0.18);
16516
16775
  border: 1px solid rgba(217, 119, 6, 0.4);
@@ -17374,11 +17633,17 @@ function ButexDocumentEditor2({
17374
17633
  const [labelsOpen, setLabelsOpen] = useState12(false);
17375
17634
  const [refPicker, setRefPicker] = useState12(null);
17376
17635
  const [digitFormState, setDigitFormState] = useState12(null);
17636
+ const [debugImportOpen, setDebugImportOpen] = useState12(false);
17637
+ const [debugImportText, setDebugImportText] = useState12("");
17638
+ const [debugImportError, setDebugImportError] = useState12("");
17377
17639
  const [editorFocus, setEditorFocus] = useState12(createEmptyDocument2EditorFocus());
17378
17640
  const [collapsedBlockIds, setCollapsedBlockIds] = useState12(() => /* @__PURE__ */ new Set());
17379
17641
  const [blockSelectionState, setBlockSelectionState] = useState12(emptyBlockSelection);
17380
17642
  const [historyTick, setHistoryTick] = useState12(0);
17381
17643
  const digitForm = digitFormProp ?? digitFormState ?? (documentDirection === "rtl" ? "arabicIndic" : "western");
17644
+ function equationSessionWithDocumentDigits(session) {
17645
+ return setCurrentDigitForm(session, digitForm);
17646
+ }
17382
17647
  const historyRef = useRef8(createDocument2History());
17383
17648
  const documentRef = useRef8(documentNode);
17384
17649
  const textSnapshotArmedRef = useRef8(false);
@@ -17387,7 +17652,7 @@ function ButexDocumentEditor2({
17387
17652
  const articleMetaPanelRef = useRef8(null);
17388
17653
  const pendingFocusRef = useRef8(null);
17389
17654
  documentRef.current = documentNode;
17390
- const latex = document2Latex(documentNode);
17655
+ const latex = document2Latex(documentNode, { digitForm });
17391
17656
  const documentJson = useMemo2(() => toDocumentJson2(documentNode), [documentNode]);
17392
17657
  const documentLabels = useMemo2(() => collectDocument2Labels(documentNode), [documentNode]);
17393
17658
  const preview = useMemo2(
@@ -17595,6 +17860,46 @@ function ButexDocumentEditor2({
17595
17860
  function openAllBlocks() {
17596
17861
  setCollapsedBlockIds(/* @__PURE__ */ new Set());
17597
17862
  }
17863
+ async function copyDebugText(text) {
17864
+ try {
17865
+ await navigator.clipboard.writeText(text);
17866
+ } catch {
17867
+ }
17868
+ }
17869
+ function openDebugJsonImport() {
17870
+ setDebugImportText(JSON.stringify(documentJson, null, 2));
17871
+ setDebugImportError("");
17872
+ setDebugImportOpen(true);
17873
+ }
17874
+ function applyDebugJsonImport() {
17875
+ const parsed = parseJsonDebugInput(debugImportText);
17876
+ if (!parsed.ok) {
17877
+ setDebugImportError(parsed.error);
17878
+ return;
17879
+ }
17880
+ try {
17881
+ const imported = fromDocumentJson2(parsed.value);
17882
+ textSnapshotArmedRef.current = false;
17883
+ if (textDebounceRef.current !== null) {
17884
+ window.clearTimeout(textDebounceRef.current);
17885
+ textDebounceRef.current = null;
17886
+ }
17887
+ setDocumentNode(imported);
17888
+ setError(null);
17889
+ setSelectedMath(null);
17890
+ setCitePicker(null);
17891
+ setRefPicker(null);
17892
+ clearBlockSelection();
17893
+ setCollapsedBlockIds(/* @__PURE__ */ new Set());
17894
+ setEditorFocus(createEmptyDocument2EditorFocus());
17895
+ historyRef.current = createDocument2History();
17896
+ bumpHistoryUi();
17897
+ setDebugImportError("");
17898
+ setDebugImportOpen(false);
17899
+ } catch (importError) {
17900
+ setDebugImportError(importError instanceof Error ? importError.message : String(importError));
17901
+ }
17902
+ }
17598
17903
  useEffect9(() => {
17599
17904
  const root = widgetRef.current;
17600
17905
  if (!root) {
@@ -17650,7 +17955,7 @@ function ButexDocumentEditor2({
17650
17955
  textTokenId: target?.textTokenId ?? null,
17651
17956
  insertAt: target?.caretOffset ?? 0,
17652
17957
  mathMode: mode,
17653
- session: createEmptyEquationSession(equationSide),
17958
+ session: equationSessionWithDocumentDigits(createEmptyEquationSession(equationSide)),
17654
17959
  reason: null,
17655
17960
  labelEnabled: false,
17656
17961
  label: ""
@@ -17670,7 +17975,7 @@ function ButexDocumentEditor2({
17670
17975
  insertAt: 0,
17671
17976
  textTokenId: null,
17672
17977
  mathMode: mode,
17673
- session: createEmptyEquationSession(equationSide),
17978
+ session: equationSessionWithDocumentDigits(createEmptyEquationSession(equationSide)),
17674
17979
  reason: result.reason,
17675
17980
  labelEnabled: Boolean(token.labelEnabled),
17676
17981
  label: token.label ?? ""
@@ -17683,7 +17988,7 @@ function ButexDocumentEditor2({
17683
17988
  insertAt: 0,
17684
17989
  textTokenId: null,
17685
17990
  mathMode: mode,
17686
- session: result.session,
17991
+ session: equationSessionWithDocumentDigits(result.session),
17687
17992
  reason: null,
17688
17993
  labelEnabled: Boolean(token.labelEnabled),
17689
17994
  label: token.label ?? ""
@@ -18108,14 +18413,51 @@ function ButexDocumentEditor2({
18108
18413
  /* @__PURE__ */ jsx17("strong", { children: messages.importWarnings }),
18109
18414
  documentNode.diagnostics.map((diagnostic) => /* @__PURE__ */ jsx17("p", { className: "butex-document2-widget__dev-diagnostic", children: formatDocument2Diagnostic(diagnostic, messages) }, `${diagnostic.path}-${diagnostic.message}`))
18110
18415
  ] }) : null,
18416
+ /* @__PURE__ */ jsxs15("div", { className: "butex-document2-widget__dev-actions", children: [
18417
+ /* @__PURE__ */ jsx17("button", { type: "button", onClick: () => void copyDebugText(JSON.stringify(documentJson, null, 2)), children: "Copy JSON" }),
18418
+ /* @__PURE__ */ jsx17("button", { type: "button", onClick: () => void copyDebugText(latex), children: "Copy TeX" }),
18419
+ /* @__PURE__ */ jsx17("button", { type: "button", "aria-expanded": debugImportOpen, onClick: openDebugJsonImport, children: "Import JSON" })
18420
+ ] }),
18421
+ debugImportOpen ? /* @__PURE__ */ jsxs15("div", { className: "butex-document2-widget__dev-import", children: [
18422
+ /* @__PURE__ */ jsx17(
18423
+ "textarea",
18424
+ {
18425
+ value: debugImportText,
18426
+ "aria-label": "Import Document2 JSON",
18427
+ spellCheck: false,
18428
+ onChange: (event) => {
18429
+ setDebugImportText(event.currentTarget.value);
18430
+ setDebugImportError("");
18431
+ }
18432
+ }
18433
+ ),
18434
+ /* @__PURE__ */ jsxs15("div", { className: "butex-document2-widget__dev-actions", children: [
18435
+ /* @__PURE__ */ jsx17("button", { type: "button", onClick: applyDebugJsonImport, children: "Apply" }),
18436
+ /* @__PURE__ */ jsx17(
18437
+ "button",
18438
+ {
18439
+ type: "button",
18440
+ onClick: () => {
18441
+ setDebugImportOpen(false);
18442
+ setDebugImportError("");
18443
+ },
18444
+ children: "Cancel"
18445
+ }
18446
+ )
18447
+ ] }),
18448
+ debugImportError ? /* @__PURE__ */ jsx17("p", { className: "butex-document2-widget__dev-error", children: debugImportError }) : null
18449
+ ] }) : null,
18111
18450
  /* @__PURE__ */ jsx17("strong", { children: "LaTeX" }),
18112
18451
  /* @__PURE__ */ jsx17("pre", { children: latex }),
18452
+ /* @__PURE__ */ jsx17("strong", { children: "JSON" }),
18453
+ /* @__PURE__ */ jsx17("pre", { children: JSON.stringify(documentJson, null, 2) }),
18113
18454
  /* @__PURE__ */ jsx17("strong", { children: "AST" }),
18114
18455
  /* @__PURE__ */ jsx17("pre", { children: JSON.stringify(documentNode, null, 2) })
18115
18456
  ] }) : null,
18116
18457
  !previewOnly && selectedMath ? /* @__PURE__ */ jsx17(
18117
18458
  EquationDrawer,
18118
18459
  {
18460
+ debug: debugEnabled,
18119
18461
  session: selectedMath.session,
18120
18462
  reason: selectedMath.reason,
18121
18463
  mathMode: selectedMath.mathMode,