@drghaliasri/butex 5.2.0 → 5.3.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.
@@ -35,7 +35,12 @@ function formatDigits(value, digitForm = "western") {
35
35
  }
36
36
 
37
37
  // src/document2/articleMeta.ts
38
- var BUTEX_BASMALA = "\u0628\u0650\u0633\u0652\u0645\u0650 \u0627\u0644\u0644\u064E\u0651\u0647\u0650 \u0627\u0644\u0631\u064E\u0651\u062D\u0652\u0645\u064E\u0670\u0646\u0650 \u0627\u0644\u0631\u064E\u0651\u062D\u0650\u064A\u0645\u0650 \u0648\u064E\u0627\u0644\u0635\u064E\u0651\u0644\u064E\u0627\u0629\u064F \u0648\u064E\u0627\u0644\u0633\u064E\u0651\u0644\u064E\u0627\u0645\u064F \u0639\u064E\u0644\u064E\u0649\u0670 \u0631\u064E\u0633\u064F\u0648\u0644\u0650 \u0627\u0644\u0644\u064E\u0651\u0647\u0650 \uFDFA";
38
+ var BUTEX_BASMALA_LINE1 = "\u0628\u0650\u0633\u0652\u0645\u0650 \u0671\u0644\u0644\u064E\u0651\u0670\u0647\u0650 \u0671\u0644\u0631\u064E\u0651\u062D\u0652\u0645\u064E\u0670\u0646\u0650 \u0671\u0644\u0631\u064E\u0651\u062D\u0650\u064A\u0645\u0650";
39
+ var BUTEX_BASMALA_LINE2 = "\u0648\u064E\u0671\u0644\u0635\u064E\u0651\u0644\u064E\u0627\u0629\u064F \u0648\u064E\u0671\u0644\u0633\u064E\u0651\u0644\u064E\u0627\u0645\u064F \u0639\u064E\u0644\u064E\u0649\u0670 \u0631\u064E\u0633\u064F\u0648\u0644\u0650 \u0671\u0644\u0644\u064E\u0651\u0670\u0647\u0650";
40
+ var BUTEX_BASMALA_SALAWAT = "\u0635\u064E\u0644\u064E\u0651\u0649 \u0671\u0644\u0644\u064E\u0651\u0647\u064F \u0639\u064E\u0644\u064E\u064A\u0652\u0647\u0650 \u0648\u064E\u0633\u064E\u0644\u064E\u0651\u0645\u064E";
41
+ var BUTEX_BASMALA = `${BUTEX_BASMALA_LINE1}
42
+ ${BUTEX_BASMALA_LINE2}
43
+ ${BUTEX_BASMALA_SALAWAT}`;
39
44
  var BUTEX_CLOSING_HAMDALA = "\u0627\u0644\u0652\u062D\u064E\u0645\u0652\u062F\u064F \u0644\u0650\u0644\u064E\u0651\u0647\u0650 \u0646\u064E\u0641\u064E\u0639\u064E\u0646\u064E\u0627 \u0628\u0650\u0639\u0650\u0644\u0652\u0645\u0650\u0647\u0650";
40
45
  function escapeButexTextArg(text) {
41
46
  return text.replace(/\\/g, "\\textbackslash{}").replace(/[{}]/g, "\\$&");
@@ -48,6 +53,61 @@ function butexDiwaniDisplayLatex(text) {
48
53
  ${butexDiwaniDisplayTex(text)}
49
54
  \\]`;
50
55
  }
56
+ var BASMALA_LINES = [BUTEX_BASMALA_LINE1, BUTEX_BASMALA_LINE2, BUTEX_BASMALA_SALAWAT];
57
+ function butexBasmalaDisplayTex() {
58
+ return BASMALA_LINES.map((line) => butexDiwaniDisplayTex(line)).join(" \\\\ ");
59
+ }
60
+ function butexBasmalaDisplayLatex() {
61
+ return `\\[
62
+ ${butexBasmalaDisplayTex()}
63
+ \\]`;
64
+ }
65
+ function butexInColumnMaketitleHook() {
66
+ return String.raw`\makeatletter
67
+ \renewcommand{\maketitle}{%
68
+ \par
69
+ \begingroup
70
+ \renewcommand\thefootnote{\@fnsymbol\c@footnote}%
71
+ \def\@makefnmark{\rlap{\@textsuperscript{\normalfont\@thefnmark}}}%
72
+ \long\def\@makefntext##1{\parindent 1em\noindent
73
+ \hb@xt@1.8em{\hss\@textsuperscript{\normalfont\@thefnmark}}##1}%
74
+ \@maketitle
75
+ \thispagestyle{plain}\@thanks
76
+ \endgroup
77
+ \setcounter{footnote}{0}%
78
+ \global\let\thanks\relax
79
+ \global\let\maketitle\relax
80
+ \global\let\@maketitle\relax
81
+ \global\let\@thanks\@empty
82
+ \global\let\@author\@empty
83
+ \global\let\@date\@empty
84
+ \global\let\@title\@empty
85
+ \global\let\title\relax
86
+ \global\let\author\relax
87
+ \global\let\date\relax
88
+ \global\let\and\relax
89
+ }
90
+ \makeatother`;
91
+ }
92
+ function butexBasmalaTitlingPreamble(options = {}) {
93
+ const lines = [
94
+ "\\usepackage{titling}",
95
+ "\\pretitle{%",
96
+ " \\begin{center}",
97
+ ...BASMALA_LINES.map((line, index) => {
98
+ const suffix = index < BASMALA_LINES.length - 1 ? "\\\\" : "";
99
+ return ` ${butexDiwaniDisplayTex(line)}${suffix}`;
100
+ }),
101
+ " \\par\\vspace{1.5em}",
102
+ " \\LARGE",
103
+ "}",
104
+ "\\posttitle{\\par\\end{center}}"
105
+ ];
106
+ if (options.twocolumn) {
107
+ lines.push(butexInColumnMaketitleHook());
108
+ }
109
+ return lines.join("\n");
110
+ }
51
111
  var HIJRI_YEAR_MIN = 1400;
52
112
  var HIJRI_YEAR_MAX = 1500;
53
113
  var HIJRI_MONTH_IDS = [
@@ -3923,7 +3983,7 @@ function addDocument2ImageBlock(document2, src = "", afterBlockId) {
3923
3983
  kind: "image",
3924
3984
  command: "\\includegraphics",
3925
3985
  value: src,
3926
- options: { width: "0.8\\textwidth" },
3986
+ options: { width: "0.8\\columnwidth" },
3927
3987
  ...defaultFloatMeta()
3928
3988
  };
3929
3989
  return insertDocument2BlockAfter(document2, afterBlockId, block);
@@ -4248,7 +4308,7 @@ function updateDocument2Meta(document2, patch) {
4248
4308
 
4249
4309
  // src/document2/arabicPreamble.ts
4250
4310
  function arabicXeLatexPreamblePkg(twocolumn = false) {
4251
- const classOptions = twocolumn ? "12pt,a4paper,twocolumn" : "12pt,a4paper";
4311
+ const classOptions = twocolumn ? "12pt,a4paper,notitlepage,twocolumn" : "12pt,a4paper,notitlepage";
4252
4312
  return `
4253
4313
  \\documentclass[${classOptions}]{article}
4254
4314
  ` + String.raw`\usepackage{amsmath,amsfonts,amssymb,mathrsfs,tikz,fancyhdr, mathtools}
@@ -4528,8 +4588,16 @@ function tableBlockLatex(block) {
4528
4588
  lines.push("\\end{table}");
4529
4589
  return lines.join("\n");
4530
4590
  }
4531
- function imageOptionsLatex(block) {
4532
- const entries = Object.entries(block.options);
4591
+ function remapImageWidthForColumns(value) {
4592
+ return value.replace(/\\textwidth\b/g, "\\columnwidth");
4593
+ }
4594
+ function imageOptionsLatex(block, constrainToColumn) {
4595
+ const entries = Object.entries(block.options).map(([key, value]) => {
4596
+ if (constrainToColumn && key === "width") {
4597
+ return [key, remapImageWidthForColumns(value)];
4598
+ }
4599
+ return [key, value];
4600
+ });
4533
4601
  if (entries.length === 0) {
4534
4602
  return "";
4535
4603
  }
@@ -4540,7 +4608,7 @@ function imageBlockLatex(block) {
4540
4608
  if (block.centered) {
4541
4609
  lines.push(" \\centering");
4542
4610
  }
4543
- lines.push(` ${block.command}${imageOptionsLatex(block)}{${block.value}}`);
4611
+ lines.push(` ${block.command}${imageOptionsLatex(block, true)}{${block.value}}`);
4544
4612
  lines.push(...floatCaptionLabelLines(block));
4545
4613
  lines.push("\\end{figure}");
4546
4614
  return lines.join("\n");
@@ -4570,17 +4638,26 @@ ${block.closing}`;
4570
4638
  function authorLatex(authors) {
4571
4639
  return authors.split(/\n+/).map((line) => line.trim()).filter((line) => line.length > 0).join(" \\\\ ");
4572
4640
  }
4641
+ function articleMaketitlePreamble(meta, twocolumn = false) {
4642
+ if (!document2HasMaketitle(meta)) {
4643
+ return "";
4644
+ }
4645
+ const parts = [butexBasmalaTitlingPreamble({ twocolumn })];
4646
+ if (meta.title.trim().length > 0) {
4647
+ parts.push(`\\title{${meta.title.trim()}}`);
4648
+ }
4649
+ if (meta.authors.trim().length > 0) {
4650
+ parts.push(`\\author{${authorLatex(meta.authors)}}`);
4651
+ }
4652
+ parts.push(`\\date{${formatHijriDate(meta.date, { locale: "ar", digitForm: "arabicIndic" })}}`);
4653
+ return parts.join("\n");
4654
+ }
4573
4655
  function articleFrontMatterLatex(meta) {
4574
- const parts = [butexDiwaniDisplayLatex(BUTEX_BASMALA)];
4656
+ const parts = [];
4575
4657
  if (document2HasMaketitle(meta)) {
4576
- if (meta.title.trim().length > 0) {
4577
- parts.push(`\\title{${meta.title.trim()}}`);
4578
- }
4579
- if (meta.authors.trim().length > 0) {
4580
- parts.push(`\\author{${authorLatex(meta.authors)}}`);
4581
- }
4582
- parts.push(`\\date{${formatHijriDate(meta.date, { locale: "ar", digitForm: "arabicIndic" })}}`);
4583
4658
  parts.push("\\maketitle");
4659
+ } else {
4660
+ parts.push(butexBasmalaDisplayLatex());
4584
4661
  }
4585
4662
  if (document2HasAbstract(meta)) {
4586
4663
  parts.push(`\\begin{abstract}
@@ -4591,18 +4668,22 @@ ${meta.abstract.trim()}
4591
4668
  }
4592
4669
  function document2Latex(document2, options = {}) {
4593
4670
  const meta = document2.meta ?? emptyDocument2Meta();
4671
+ const twocolumn = options.twocolumn === true;
4594
4672
  const front = articleFrontMatterLatex(meta);
4595
4673
  const bodyBlocks = document2.blocks.map((block) => blockLatex(block, document2.references));
4596
4674
  const closing = butexDiwaniDisplayLatex(BUTEX_CLOSING_HAMDALA);
4597
4675
  const body = [...front, ...bodyBlocks, closing].filter((part) => part.length > 0).join("\n\n");
4598
4676
  const wrapDocument = options.wrapDocument !== false;
4599
4677
  if (!wrapDocument) {
4600
- return body;
4678
+ const metaPreamble = articleMaketitlePreamble(meta, twocolumn);
4679
+ return metaPreamble.length > 0 ? `${metaPreamble}
4680
+
4681
+ ${body}` : body;
4601
4682
  }
4602
4683
  const preamble = getArabicXeLatexPreamble({
4603
4684
  digitsMapping: options.digitsMapping ?? "arabicdigits",
4604
- twocolumn: options.twocolumn === true
4605
- });
4685
+ twocolumn
4686
+ }) + "\n" + articleMaketitlePreamble(meta, twocolumn);
4606
4687
  return `${preamble}
4607
4688
  \\begin{document}
4608
4689
 
@@ -4845,7 +4926,7 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
4845
4926
  function articleChromePreview(document2, uiLocale, previewOptions) {
4846
4927
  const meta = document2.meta ?? emptyDocument2Meta();
4847
4928
  const blocks = [
4848
- { kind: "basmala", id: "article-basmala", text: BUTEX_BASMALA, tex: butexDiwaniDisplayTex(BUTEX_BASMALA) }
4929
+ { kind: "basmala", id: "article-basmala", text: BUTEX_BASMALA, tex: butexBasmalaDisplayTex() }
4849
4930
  ];
4850
4931
  if (document2HasMaketitle(meta)) {
4851
4932
  blocks.push({
@@ -4883,6 +4964,9 @@ function document2Preview(document2, output = "svg", equationSide = "arabic", pr
4883
4964
  }
4884
4965
  export {
4885
4966
  BUTEX_BASMALA,
4967
+ BUTEX_BASMALA_LINE1,
4968
+ BUTEX_BASMALA_LINE2,
4969
+ BUTEX_BASMALA_SALAWAT,
4886
4970
  BUTEX_CLOSING_HAMDALA,
4887
4971
  DEFAULT_DOCUMENT2_HISTORY_MAX_DEPTH,
4888
4972
  DEFAULT_HIJRI_DATE,
@@ -4900,8 +4984,12 @@ export {
4900
4984
  arabicXeLatexPreambleFont,
4901
4985
  arabicXeLatexPreamblePkg,
4902
4986
  bibliographyEntryLatex,
4987
+ butexBasmalaDisplayLatex,
4988
+ butexBasmalaDisplayTex,
4989
+ butexBasmalaTitlingPreamble,
4903
4990
  butexDiwaniDisplayLatex,
4904
4991
  butexDiwaniDisplayTex,
4992
+ butexInColumnMaketitleHook,
4905
4993
  citeTokenLatex,
4906
4994
  cloneDocument2Meta,
4907
4995
  cloneDocument2Node,