@drghaliasri/butex 5.5.5 → 5.6.1

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.
@@ -678,7 +678,7 @@ declare function bibliographyEntryLatex(reference: Reference2): string;
678
678
  */
679
679
  declare function absoluteHttpHref(url: string): string;
680
680
 
681
- type ArabicDigitsMapping = 'arabicdigits' | 'digits';
681
+ type ArabicDigitsMapping = 'arabicdigits' | 'farsidigits' | 'digits';
682
682
  type ArabicXeLatexPreambleOptions = {
683
683
  digitsMapping?: ArabicDigitsMapping;
684
684
  /** When true, add the article class twocolumn option. Default false. */
@@ -698,6 +698,8 @@ type Document2LatexOptions = {
698
698
  wrapDocument?: boolean;
699
699
  /** Font digit Mapping when wrapping. Default 'arabicdigits'. */
700
700
  digitsMapping?: ArabicDigitsMapping;
701
+ /** Document-level digit form for XeLaTeX font Mapping. Ignored when digitsMapping is set. */
702
+ digitForm?: DigitFormId;
701
703
  /** When true, use article class option twocolumn. Default false. */
702
704
  twocolumn?: boolean;
703
705
  };
@@ -760,7 +762,7 @@ declare function mathSourceFromSession(session: EditorSession, side: EditorSide,
760
762
  declare function mathSourceFromArabicSession(session: EditorSession, opening?: string, closing?: string): string;
761
763
  declare function mathNodeFromSession(session: EditorSession, opening?: string, closing?: string): MathNode;
762
764
  declare function mathNodeFromArabicSession(session: EditorSession, opening?: string, closing?: string): MathNode;
763
- declare function mathTokenSourceForSide(token: MathToken2, side: EditorSide): string;
765
+ declare function mathTokenSourceForSide(token: MathToken2, side: EditorSide, digitForm?: DigitFormId): string;
764
766
 
765
767
  type Document2PreviewOptions = {
766
768
  documentDirection?: Document2Direction;
@@ -678,7 +678,7 @@ declare function bibliographyEntryLatex(reference: Reference2): string;
678
678
  */
679
679
  declare function absoluteHttpHref(url: string): string;
680
680
 
681
- type ArabicDigitsMapping = 'arabicdigits' | 'digits';
681
+ type ArabicDigitsMapping = 'arabicdigits' | 'farsidigits' | 'digits';
682
682
  type ArabicXeLatexPreambleOptions = {
683
683
  digitsMapping?: ArabicDigitsMapping;
684
684
  /** When true, add the article class twocolumn option. Default false. */
@@ -698,6 +698,8 @@ type Document2LatexOptions = {
698
698
  wrapDocument?: boolean;
699
699
  /** Font digit Mapping when wrapping. Default 'arabicdigits'. */
700
700
  digitsMapping?: ArabicDigitsMapping;
701
+ /** Document-level digit form for XeLaTeX font Mapping. Ignored when digitsMapping is set. */
702
+ digitForm?: DigitFormId;
701
703
  /** When true, use article class option twocolumn. Default false. */
702
704
  twocolumn?: boolean;
703
705
  };
@@ -760,7 +762,7 @@ declare function mathSourceFromSession(session: EditorSession, side: EditorSide,
760
762
  declare function mathSourceFromArabicSession(session: EditorSession, opening?: string, closing?: string): string;
761
763
  declare function mathNodeFromSession(session: EditorSession, opening?: string, closing?: string): MathNode;
762
764
  declare function mathNodeFromArabicSession(session: EditorSession, opening?: string, closing?: string): MathNode;
763
- declare function mathTokenSourceForSide(token: MathToken2, side: EditorSide): string;
765
+ declare function mathTokenSourceForSide(token: MathToken2, side: EditorSide, digitForm?: DigitFormId): string;
764
766
 
765
767
  type Document2PreviewOptions = {
766
768
  documentDirection?: Document2Direction;
package/dist/document2.js CHANGED
@@ -222,7 +222,9 @@ function butexBasmalaDisplayTex() {
222
222
  }
223
223
  function butexBasmalaDisplayLatex() {
224
224
  return `\\[
225
- ${butexBasmalaDisplayTex()}
225
+ \\begin{gathered}
226
+ ${BASMALA_LINES.map((line) => butexMaghribiDisplayTex(line)).join(" \\\\\n")}
227
+ \\end{gathered}
226
228
  \\]`;
227
229
  }
228
230
  function butexInColumnMaketitleHook() {
@@ -2218,6 +2220,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2218
2220
  category: "operators1",
2219
2221
  Tex: "\\neq",
2220
2222
  mirror: true,
2223
+ compileMirror: true,
2221
2224
  Label: "\u2260",
2222
2225
  title: "\u0644\u0627 \u064A\u0633\u0627\u0648\u064A",
2223
2226
  svg_path: null
@@ -2257,6 +2260,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2257
2260
  Tex: "\\leq",
2258
2261
  mirror: true,
2259
2262
  displayMirror: false,
2263
+ compileMirror: true,
2260
2264
  Label: "\u2264",
2261
2265
  title: "\u0623\u0635\u063A\u0631 \u0645\u0646 \u0623\u0648 \u064A\u0633\u0627\u0648\u064A",
2262
2266
  svg_path: null
@@ -2267,6 +2271,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2267
2271
  Tex: "\\geq",
2268
2272
  mirror: true,
2269
2273
  displayMirror: false,
2274
+ compileMirror: true,
2270
2275
  Label: "\u2265",
2271
2276
  title: "\u0623\u0643\u0628\u0631 \u0645\u0646 \u0623\u0648 \u064A\u0633\u0627\u0648\u064A",
2272
2277
  svg_path: null
@@ -2277,6 +2282,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2277
2282
  Tex: "\\coloneqq",
2278
2283
  mirror: true,
2279
2284
  displayMirror: false,
2285
+ compileMirror: true,
2280
2286
  Label: "\u2254",
2281
2287
  title: "\u064A\u0639\u0631\u0641 \u0628\u0623\u0646\u0647 \u064A\u0633\u0627\u0648\u064A",
2282
2288
  svg_path: null
@@ -2287,6 +2293,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2287
2293
  Tex: "\\eqqcolon",
2288
2294
  mirror: true,
2289
2295
  displayMirror: false,
2296
+ compileMirror: true,
2290
2297
  Label: "\u2255",
2291
2298
  title: "\u064A\u0633\u0627\u0648\u064A \u0628\u0627\u0644\u062A\u0639\u0631\u064A\u0641",
2292
2299
  svg_path: null
@@ -2298,6 +2305,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2298
2305
  Tex: "\\propto",
2299
2306
  mirror: true,
2300
2307
  displayMirror: false,
2308
+ compileMirror: true,
2301
2309
  Label: "\u221D",
2302
2310
  title: "\u064A\u062A\u0646\u0627\u0633\u0628 \u0645\u0639",
2303
2311
  svg_path: null
@@ -2308,6 +2316,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2308
2316
  Tex: "\\in",
2309
2317
  mirror: true,
2310
2318
  displayMirror: false,
2319
+ compileMirror: true,
2311
2320
  Label: "\u2208",
2312
2321
  title: "\u064A\u0646\u062A\u0645\u064A \u0625\u0644\u0649",
2313
2322
  svg_path: null
@@ -2328,6 +2337,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2328
2337
  Tex: "\\subset",
2329
2338
  mirror: true,
2330
2339
  displayMirror: false,
2340
+ compileMirror: true,
2331
2341
  Label: "\u2282",
2332
2342
  title: "\u0645\u062C\u0645\u0648\u0639\u0629 \u062C\u0632\u0626\u064A\u0629 \u0645\u0646",
2333
2343
  svg_path: null
@@ -2338,6 +2348,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2338
2348
  Tex: "\\supset",
2339
2349
  mirror: true,
2340
2350
  displayMirror: false,
2351
+ compileMirror: true,
2341
2352
  Label: "\u2283",
2342
2353
  title: "\u0645\u062C\u0645\u0648\u0639\u0629 \u0634\u0627\u0645\u0644\u0629 \u0644\u0640",
2343
2354
  svg_path: null
@@ -2348,6 +2359,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2348
2359
  Tex: "\\subseteq",
2349
2360
  mirror: true,
2350
2361
  displayMirror: false,
2362
+ compileMirror: true,
2351
2363
  Label: "\u2286",
2352
2364
  title: "\u0645\u062C\u0645\u0648\u0639\u0629 \u062C\u0632\u0626\u064A\u0629 \u0623\u0648 \u062A\u0633\u0627\u0648\u064A",
2353
2365
  svg_path: null
@@ -2358,6 +2370,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2358
2370
  Tex: "\\supseteq",
2359
2371
  mirror: true,
2360
2372
  displayMirror: false,
2373
+ compileMirror: true,
2361
2374
  Label: "\u2287",
2362
2375
  title: "\u0645\u062C\u0645\u0648\u0639\u0629 \u0634\u0627\u0645\u0644\u0629 \u0623\u0648 \u062A\u0633\u0627\u0648\u064A",
2363
2376
  svg_path: null
@@ -2398,6 +2411,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2398
2411
  Tex: "\\nsubseteq",
2399
2412
  mirror: true,
2400
2413
  displayMirror: false,
2414
+ compileMirror: true,
2401
2415
  Label: "\u2288",
2402
2416
  title: "\u0644\u064A\u0633\u062A \u0645\u062C\u0645\u0648\u0639\u0629 \u062C\u0632\u0626\u064A\u0629 \u0623\u0648 \u062A\u0633\u0627\u0648\u064A",
2403
2417
  svg_path: null
@@ -2408,6 +2422,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2408
2422
  Tex: "\\nsupseteq",
2409
2423
  mirror: true,
2410
2424
  displayMirror: false,
2425
+ compileMirror: true,
2411
2426
  Label: "\u2289",
2412
2427
  title: "\u0644\u064A\u0633\u062A \u0645\u062C\u0645\u0648\u0639\u0629 \u0634\u0627\u0645\u0644\u0629 \u0623\u0648 \u062A\u0633\u0627\u0648\u064A",
2413
2428
  svg_path: null
@@ -2455,6 +2470,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2455
2470
  Tex: "\\ddots",
2456
2471
  mirror: true,
2457
2472
  displayMirror: false,
2473
+ compileMirror: true,
2458
2474
  Label: "\u22F1",
2459
2475
  title: "\u0646\u0642\u0627\u0637 \u0642\u0637\u0631\u064A\u0629",
2460
2476
  svg_path: null
@@ -2474,6 +2490,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2474
2490
  category: "operators3",
2475
2491
  Tex: "\\implies",
2476
2492
  mirror: true,
2493
+ compileMirror: true,
2477
2494
  Label: "\u21D2",
2478
2495
  title: "\u064A\u0633\u062A\u0644\u0632\u0645",
2479
2496
  svg_path: null
@@ -2483,6 +2500,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2483
2500
  category: "operators3",
2484
2501
  Tex: "\\impliedby",
2485
2502
  mirror: true,
2503
+ compileMirror: true,
2486
2504
  Label: "\u21D0",
2487
2505
  title: "\u0645\u0633\u062A\u0644\u0632\u0645 \u0645\u0646",
2488
2506
  svg_path: null
@@ -2501,6 +2519,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2501
2519
  category: "operators3",
2502
2520
  Tex: "\\Longrightarrow",
2503
2521
  mirror: true,
2522
+ compileMirror: true,
2504
2523
  Label: "\u27F9",
2505
2524
  title: "\u0633\u0647\u0645 \u0645\u0632\u062F\u0648\u062C \u0637\u0648\u064A\u0644 \u0625\u0644\u0649 \u0627\u0644\u064A\u0645\u064A\u0646",
2506
2525
  svg_path: null
@@ -2510,6 +2529,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2510
2529
  category: "operators3",
2511
2530
  Tex: "\\Longleftarrow",
2512
2531
  mirror: true,
2532
+ compileMirror: true,
2513
2533
  Label: "\u27F8",
2514
2534
  title: "\u0633\u0647\u0645 \u0645\u0632\u062F\u0648\u062C \u0637\u0648\u064A\u0644 \u0625\u0644\u0649 \u0627\u0644\u064A\u0633\u0627\u0631",
2515
2535
  svg_path: null
@@ -2519,6 +2539,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2519
2539
  category: "operators3",
2520
2540
  Tex: "\\to",
2521
2541
  mirror: true,
2542
+ compileMirror: true,
2522
2543
  Label: "\u2192",
2523
2544
  title: "\u064A\u0624\u0648\u0644 \u0625\u0644\u0649",
2524
2545
  svg_path: null
@@ -2528,6 +2549,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2528
2549
  category: "operators3",
2529
2550
  Tex: "\\rightleftharpoons",
2530
2551
  mirror: true,
2552
+ compileMirror: true,
2531
2553
  Label: "\u21CC",
2532
2554
  title: "\u0627\u062A\u0632\u0627\u0646",
2533
2555
  svg_path: null
@@ -2537,6 +2559,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2537
2559
  category: "operators3",
2538
2560
  Tex: "\\leftarrow",
2539
2561
  mirror: true,
2562
+ compileMirror: true,
2540
2563
  Label: "\u2190",
2541
2564
  title: "\u0633\u0647\u0645 \u0625\u0644\u0649 \u0627\u0644\u064A\u0633\u0627\u0631",
2542
2565
  svg_path: null
@@ -2546,6 +2569,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2546
2569
  category: "operators3",
2547
2570
  Tex: "\\rightarrow",
2548
2571
  mirror: true,
2572
+ compileMirror: true,
2549
2573
  Label: "\u2192",
2550
2574
  title: "\u0633\u0647\u0645 \u0625\u0644\u0649 \u0627\u0644\u064A\u0645\u064A\u0646",
2551
2575
  svg_path: null
@@ -2555,6 +2579,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2555
2579
  category: "operators3",
2556
2580
  Tex: "\\Leftarrow",
2557
2581
  mirror: true,
2582
+ compileMirror: true,
2558
2583
  Label: "\u21D0",
2559
2584
  title: "\u0633\u0647\u0645 \u0645\u0632\u062F\u0648\u062C \u0625\u0644\u0649 \u0627\u0644\u064A\u0633\u0627\u0631",
2560
2585
  svg_path: null
@@ -2564,6 +2589,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2564
2589
  category: "operators3",
2565
2590
  Tex: "\\Rightarrow",
2566
2591
  mirror: true,
2592
+ compileMirror: true,
2567
2593
  Label: "\u21D2",
2568
2594
  title: "\u0633\u0647\u0645 \u0645\u0632\u062F\u0648\u062C \u0625\u0644\u0649 \u0627\u0644\u064A\u0645\u064A\u0646",
2569
2595
  svg_path: null
@@ -2573,6 +2599,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2573
2599
  category: "operators3",
2574
2600
  Tex: "\\leftharpoonup",
2575
2601
  mirror: true,
2602
+ compileMirror: true,
2576
2603
  Label: "\u21BC",
2577
2604
  title: "\u0633\u0647\u0645 \u062E\u0637\u0627\u0641\u064A \u0639\u0644\u0648\u064A \u0625\u0644\u0649 \u0627\u0644\u064A\u0633\u0627\u0631",
2578
2605
  svg_path: null
@@ -2582,6 +2609,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2582
2609
  category: "operators3",
2583
2610
  Tex: "\\rightharpoonup",
2584
2611
  mirror: true,
2612
+ compileMirror: true,
2585
2613
  Label: "\u21C0",
2586
2614
  title: "\u0633\u0647\u0645 \u062E\u0637\u0627\u0641\u064A \u0639\u0644\u0648\u064A \u0625\u0644\u0649 \u0627\u0644\u064A\u0645\u064A\u0646",
2587
2615
  svg_path: null
@@ -2591,6 +2619,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2591
2619
  category: "operators3",
2592
2620
  Tex: "\\leftharpoondown",
2593
2621
  mirror: true,
2622
+ compileMirror: true,
2594
2623
  Label: "\u21BD",
2595
2624
  title: "\u0633\u0647\u0645 \u062E\u0637\u0627\u0641\u064A \u0633\u0641\u0644\u064A \u0625\u0644\u0649 \u0627\u0644\u064A\u0633\u0627\u0631",
2596
2625
  svg_path: null
@@ -2600,6 +2629,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2600
2629
  category: "operators3",
2601
2630
  Tex: "\\rightharpoondown",
2602
2631
  mirror: true,
2632
+ compileMirror: true,
2603
2633
  Label: "\u21C1",
2604
2634
  title: "\u0633\u0647\u0645 \u062E\u0637\u0627\u0641\u064A \u0633\u0641\u0644\u064A \u0625\u0644\u0649 \u0627\u0644\u064A\u0645\u064A\u0646",
2605
2635
  svg_path: null
@@ -2610,6 +2640,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2610
2640
  category: "integrals",
2611
2641
  Tex: "\\int",
2612
2642
  mirror: true,
2643
+ compileMirror: true,
2613
2644
  Label: "\u222B",
2614
2645
  title: "\u062A\u0643\u0627\u0645\u0644",
2615
2646
  svg_path: null
@@ -2620,6 +2651,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2620
2651
  Tex: "\\iint",
2621
2652
  mirror: true,
2622
2653
  displayMirror: false,
2654
+ compileMirror: true,
2623
2655
  Label: "\u222C",
2624
2656
  title: "\u062A\u0643\u0627\u0645\u0644 \u0645\u0632\u062F\u0648\u062C",
2625
2657
  svg_path: null
@@ -2630,6 +2662,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2630
2662
  Tex: "\\iiint",
2631
2663
  mirror: true,
2632
2664
  displayMirror: false,
2665
+ compileMirror: true,
2633
2666
  Label: "\u222D",
2634
2667
  title: "\u062A\u0643\u0627\u0645\u0644 \u062B\u0644\u0627\u062B\u064A",
2635
2668
  svg_path: null
@@ -2640,6 +2673,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2640
2673
  Tex: "\\iiiint",
2641
2674
  mirror: true,
2642
2675
  displayMirror: false,
2676
+ compileMirror: true,
2643
2677
  Label: "\u2A0C",
2644
2678
  title: "\u062A\u0643\u0627\u0645\u0644 \u0631\u0628\u0627\u0639\u064A",
2645
2679
  svg_path: null
@@ -2650,6 +2684,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2650
2684
  Tex: "\\oint",
2651
2685
  mirror: true,
2652
2686
  displayMirror: false,
2687
+ compileMirror: true,
2653
2688
  Label: "\u222E",
2654
2689
  title: "\u062A\u0643\u0627\u0645\u0644 \u0645\u063A\u0644\u0642",
2655
2690
  svg_path: null
@@ -2660,6 +2695,7 @@ var ATOMIC_OPERATOR_COMMANDS = {
2660
2695
  Tex: "\\oiint",
2661
2696
  mirror: true,
2662
2697
  displayMirror: false,
2698
+ compileMirror: true,
2663
2699
  Label: "\u222F",
2664
2700
  title: "\u062A\u0643\u0627\u0645\u0644 \u0633\u0637\u062D\u064A \u0645\u063A\u0644\u0642",
2665
2701
  svg_path: null
@@ -2670,12 +2706,76 @@ var ATOMIC_OPERATOR_COMMANDS = {
2670
2706
  Tex: "\\oiiint",
2671
2707
  mirror: true,
2672
2708
  displayMirror: false,
2709
+ compileMirror: true,
2673
2710
  Label: "\u2230",
2674
2711
  title: "\u062A\u0643\u0627\u0645\u0644 \u062D\u062C\u0645\u064A \u0645\u063A\u0644\u0642",
2675
2712
  svg_path: null
2676
2713
  }
2677
2714
  };
2678
2715
  var MIRRORED_OPERATOR_TEX = Object.values(ATOMIC_OPERATOR_COMMANDS).filter((command) => command.mirror).map((command) => command.Tex).sort((a, b) => b.length - a.length);
2716
+ 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);
2717
+ function matchingMirroredOperatorFrom(tex, index, operatorTexList) {
2718
+ for (const operatorTex of operatorTexList) {
2719
+ if (!tex.startsWith(operatorTex, index)) {
2720
+ continue;
2721
+ }
2722
+ const next = tex[index + operatorTex.length];
2723
+ if (next != null && /[A-Za-z]/.test(next)) {
2724
+ continue;
2725
+ }
2726
+ return operatorTex;
2727
+ }
2728
+ return null;
2729
+ }
2730
+ function findMatchingBrace(tex, openIndex) {
2731
+ let depth = 0;
2732
+ for (let index = openIndex; index < tex.length; index += 1) {
2733
+ const char = tex[index];
2734
+ if (char === "\\") {
2735
+ index += 1;
2736
+ continue;
2737
+ }
2738
+ if (char === "{") {
2739
+ depth += 1;
2740
+ } else if (char === "}") {
2741
+ depth -= 1;
2742
+ if (depth === 0) {
2743
+ return index;
2744
+ }
2745
+ }
2746
+ }
2747
+ return -1;
2748
+ }
2749
+ function mirrorBuTeXOperatorsInTex(tex, options = {}) {
2750
+ const mirroredOperatorTex = options.target === "compile" ? COMPILE_MIRRORED_OPERATOR_TEX : MIRRORED_OPERATOR_TEX;
2751
+ let result = "";
2752
+ let index = 0;
2753
+ while (index < tex.length) {
2754
+ if (tex.startsWith("\\butexmirror{", index)) {
2755
+ const end = findMatchingBrace(tex, index + "\\butexmirror".length);
2756
+ if (end !== -1) {
2757
+ const bodyStart = index + "\\butexmirror{".length;
2758
+ const body = tex.slice(bodyStart, end);
2759
+ if (options.target === "compile" && MIRRORED_OPERATOR_TEX.includes(body) && !mirroredOperatorTex.includes(body)) {
2760
+ result += body;
2761
+ } else {
2762
+ result += tex.slice(index, end + 1);
2763
+ }
2764
+ index = end + 1;
2765
+ continue;
2766
+ }
2767
+ }
2768
+ const operatorTex = matchingMirroredOperatorFrom(tex, index, mirroredOperatorTex);
2769
+ if (operatorTex) {
2770
+ result += `\\butexmirror{${operatorTex}}`;
2771
+ index += operatorTex.length;
2772
+ continue;
2773
+ }
2774
+ result += tex[index];
2775
+ index += 1;
2776
+ }
2777
+ return result;
2778
+ }
2679
2779
  function atomicOperatorCommandSpec(id) {
2680
2780
  return Object.prototype.hasOwnProperty.call(ATOMIC_OPERATOR_COMMANDS, id) ? ATOMIC_OPERATOR_COMMANDS[id] : null;
2681
2781
  }
@@ -3158,6 +3258,28 @@ function renderArabicLatexFromSession(session) {
3158
3258
  return renderChainArabic(session.arabicTree, { digitForm: session.currentDigitForm ?? "western" });
3159
3259
  }
3160
3260
 
3261
+ // src/editor/state.ts
3262
+ function appendDebug(session, command, note) {
3263
+ const entry = {
3264
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
3265
+ command,
3266
+ activeSide: session.activeSide,
3267
+ englishLatex: renderEnglishLatexFromSession(session),
3268
+ arabicLatex: renderArabicLatexFromSession(session),
3269
+ renderOk: true,
3270
+ renderError: null,
3271
+ note
3272
+ };
3273
+ const nextLog = session.debugLog.concat(entry);
3274
+ session.debugLog = nextLog.slice(-120);
3275
+ }
3276
+ function setCurrentDigitForm(session, digitForm) {
3277
+ const next = cloneEditorSession(session);
3278
+ next.currentDigitForm = digitForm;
3279
+ appendDebug(next, "setCurrentDigitForm", digitForm);
3280
+ return next;
3281
+ }
3282
+
3161
3283
  // src/editor/display/delimiter.ts
3162
3284
  var DELIMITER_CSS = `
3163
3285
  .delim-pair {
@@ -4477,18 +4599,19 @@ function mathNodeFromSession(session, opening = "$", closing = "$") {
4477
4599
  function mathNodeFromArabicSession(session, opening = "$", closing = "$") {
4478
4600
  return mathNodeFromSession(session, opening, closing);
4479
4601
  }
4480
- function mathTokenSourceForSide(token, side) {
4602
+ function mathTokenSourceForSide(token, side, digitForm) {
4481
4603
  if (!token.math || token.sourceOwner === "raw") {
4482
4604
  return token.source;
4483
4605
  }
4484
- if (token.sourceSide === side) {
4606
+ if (token.sourceSide === side && digitForm === void 0) {
4485
4607
  return token.source;
4486
4608
  }
4487
4609
  const result = mathTokenToEditorSession(token.math, side);
4488
4610
  if (!result.editable) {
4489
4611
  return token.source;
4490
4612
  }
4491
- return mathSourceFromSession(result.session, side, token.opening, token.closing);
4613
+ const session = digitForm === void 0 ? result.session : setCurrentDigitForm(result.session, digitForm);
4614
+ return mathSourceFromSession(session, side, token.opening, token.closing);
4492
4615
  }
4493
4616
 
4494
4617
  // src/document2/commands.ts
@@ -5288,6 +5411,19 @@ function document2KeyError(key, namespace = {}) {
5288
5411
  }
5289
5412
 
5290
5413
  // src/document2/arabicPreamble.ts
5414
+ function fontOptions(digitsMapping, includeScript = true) {
5415
+ const parts = [];
5416
+ if (includeScript) {
5417
+ parts.push("Script=Arabic");
5418
+ }
5419
+ if (digitsMapping !== "digits") {
5420
+ parts.push(`Mapping=${digitsMapping}`);
5421
+ }
5422
+ if (parts.length === 0) {
5423
+ return "";
5424
+ }
5425
+ return `[${parts.join(",")}]`;
5426
+ }
5291
5427
  function arabicXeLatexPreamblePkg(twocolumn = false) {
5292
5428
  const classOptions = twocolumn ? "12pt,a4paper,notitlepage,twocolumn" : "12pt,a4paper,notitlepage";
5293
5429
  return `
@@ -5316,25 +5452,27 @@ function arabicXeLatexPreamblePkg(twocolumn = false) {
5316
5452
  % save back tick for use - copy paste -> ` + "`";
5317
5453
  }
5318
5454
  function arabicXeLatexPreambleFont(digitsMapping = "arabicdigits") {
5319
- 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");
5455
+ const customFonts = NON_DEFAULT_CHARACTER_FONT_SPECS.filter((font) => font.latexFontCommand && font.latexFontFamily).map((font) => `\\newfontfamily${font.latexFontCommand}${fontOptions(digitsMapping)}{${font.latexFontFamily}}`).join("\n");
5456
+ const mathFontOptions = fontOptions(digitsMapping, false);
5320
5457
  return `
5321
5458
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5322
5459
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5323
- % Toggle between eastern and western digits by changing the Mapping in the below fonts (inside math font as well) between "arabicdigits" and "digits"
5460
+ % Persian digits: Mapping=farsidigits
5461
+ % Arabic-Indic digits: Mapping=arabicdigits
5462
+ % Western digits: omit Mapping entirely
5324
5463
  \\setdefaultlanguage[calendar=gregorian]{arabic} % from polyglossia
5325
- \\setmainfont[Script=Arabic , Mapping=${digitsMapping}]{Amiri}
5464
+ \\setmainfont${fontOptions(digitsMapping)}{Amiri}
5326
5465
  ${customFonts}
5327
- \\newfontfamily\\boldarabic[Script=Arabic,Mapping=${digitsMapping}]{Amiri Bold}
5328
- \\newfontfamily\\italicarabic[Script=Arabic,Mapping=${digitsMapping}]{Amiri Italic}
5466
+ \\newfontfamily\\boldarabic${fontOptions(digitsMapping)}{Amiri Bold}
5467
+ \\newfontfamily\\italicarabic${fontOptions(digitsMapping)}{Amiri Italic}
5329
5468
 
5330
5469
  % for polyglossia url I dont know, sugggested by cursor
5331
- \\newfontfamily\\arabicfonttt[Script=Arabic,Mapping=${digitsMapping}]{Amiri}
5332
- \\newfontfamily\\arabicfontsf[Script=Arabic,Mapping=${digitsMapping}]{Amiri}
5470
+ \\newfontfamily\\arabicfonttt${fontOptions(digitsMapping)}{Amiri}
5471
+ \\newfontfamily\\arabicfontsf${fontOptions(digitsMapping)}{Amiri}
5333
5472
 
5334
5473
 
5335
5474
  % Explicitly set math font to XITS Math
5336
- % Remove "Script=Arabic" to cancel reflected symbols and other RTL symbols
5337
- \\setmathfont[Script=Arabic , Mapping=${digitsMapping}]{XITS Math} % Ensure XITS Math is correctly installed and available
5475
+ \\setmathfont${mathFontOptions}{XITS Math} % Ensure XITS Math is correctly installed and available
5338
5476
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5339
5477
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5340
5478
  `;
@@ -5496,8 +5634,20 @@ function getArabicXeLatexPreamble(digitsMappingOrOptions = "arabicdigits") {
5496
5634
  }
5497
5635
 
5498
5636
  // src/document2/exportLatex.ts
5637
+ function digitsMappingFromDigitForm(digitForm) {
5638
+ if (digitForm === "western") {
5639
+ return "digits";
5640
+ }
5641
+ if (digitForm === "persianIndic") {
5642
+ return "farsidigits";
5643
+ }
5644
+ return "arabicdigits";
5645
+ }
5499
5646
  function mathBodyLatex(token) {
5500
- if (!token.math || token.sourceOwner === "raw" || token.sourceOwner === "editor") {
5647
+ if (token.sourceOwner === "editor") {
5648
+ return stripDisplayMathDelimiters(mirrorBuTeXOperatorsInTex(token.source, { target: "compile" }));
5649
+ }
5650
+ if (!token.math || token.sourceOwner === "raw") {
5501
5651
  return stripDisplayMathDelimiters(token.source);
5502
5652
  }
5503
5653
  const rendered = renderMathNodeLatex(token.math);
@@ -5533,7 +5683,10 @@ ${body}
5533
5683
  \\label{${token.label.trim()}}
5534
5684
  \\end{equation}`;
5535
5685
  }
5536
- if (!token.math || token.sourceOwner === "raw" || token.sourceOwner === "editor") {
5686
+ if (token.sourceOwner === "editor") {
5687
+ return mirrorBuTeXOperatorsInTex(token.source, { target: "compile" });
5688
+ }
5689
+ if (!token.math || token.sourceOwner === "raw") {
5537
5690
  return token.source;
5538
5691
  }
5539
5692
  return renderMathNodeLatex(token.math);
@@ -5651,7 +5804,7 @@ function articleMaketitlePreamble(meta, twocolumn = false) {
5651
5804
  if (meta.authors.trim().length > 0) {
5652
5805
  parts.push(`\\author{${authorLatex(meta.authors)}}`);
5653
5806
  }
5654
- parts.push(`\\date{${formatHijriDate(meta.date, { locale: "ar", digitForm: "arabicIndic" })}}`);
5807
+ parts.push(`\\date{${formatHijriDate(meta.date, { locale: "ar", digitForm: "western" })}}`);
5655
5808
  return parts.join("\n");
5656
5809
  }
5657
5810
  function articleFrontMatterLatex(meta) {
@@ -5683,7 +5836,7 @@ function document2Latex(document2, options = {}) {
5683
5836
  ${body}` : body;
5684
5837
  }
5685
5838
  const preamble = getArabicXeLatexPreamble({
5686
- digitsMapping: options.digitsMapping ?? "arabicdigits",
5839
+ digitsMapping: options.digitsMapping ?? digitsMappingFromDigitForm(options.digitForm),
5687
5840
  twocolumn
5688
5841
  }) + "\n" + articleMaketitlePreamble(meta, twocolumn);
5689
5842
  return `${preamble}
@@ -5939,8 +6092,8 @@ function remapSelectionAfterRangeMove(selection, direction) {
5939
6092
  }
5940
6093
 
5941
6094
  // src/document2/previewModel.ts
5942
- function mathTex(token, equationSide) {
5943
- return mathTokenSourceForSide(token, equationSide);
6095
+ function mathTex(token, equationSide, digitForm) {
6096
+ return mathTokenSourceForSide(token, equationSide, digitForm);
5944
6097
  }
5945
6098
  function previewInlines(field, islands, output, equationSide, document2, previewOptions) {
5946
6099
  return field.tokens.map((token) => {
@@ -5972,7 +6125,7 @@ function previewInlines(field, islands, output, equationSide, document2, preview
5972
6125
  }
5973
6126
  const island = {
5974
6127
  id: token.id,
5975
- tex: mathTex(token, equationSide),
6128
+ tex: mathTex(token, equationSide, previewOptions.digitForm),
5976
6129
  display: token.display,
5977
6130
  output,
5978
6131
  editable: token.editable