@drghaliasri/butex 6.1.3 → 6.1.4
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 +2 -2
- package/dist/document2.js +109 -28
- package/dist/document2.js.map +1 -1
- package/dist/document2.mjs +109 -28
- package/dist/document2.mjs.map +1 -1
- package/dist/react-document2.js +107 -34
- package/dist/react-document2.js.map +1 -1
- package/dist/react-document2.mjs +107 -34
- package/dist/react-document2.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react-document2.mjs
CHANGED
|
@@ -75,11 +75,6 @@ function butexFontDisplayTex(macro, text) {
|
|
|
75
75
|
function butexMaghribiDisplayTex(text) {
|
|
76
76
|
return butexFontDisplayTex("\\butexmaghribi", text);
|
|
77
77
|
}
|
|
78
|
-
function butexMaghribiDisplayLatex(text) {
|
|
79
|
-
return `\\[
|
|
80
|
-
${butexMaghribiDisplayTex(text)}
|
|
81
|
-
\\]`;
|
|
82
|
-
}
|
|
83
78
|
var BASMALA_LINES = [BUTEX_BASMALA_LINE1, BUTEX_BASMALA_LINE2, BUTEX_BASMALA_SALAWAT];
|
|
84
79
|
function butexBasmalaDisplayTex() {
|
|
85
80
|
return BASMALA_LINES.map((line) => butexMaghribiDisplayTex(line)).join(" \\\\ ");
|
|
@@ -9642,7 +9637,43 @@ function styledTextLatex(text, style) {
|
|
|
9642
9637
|
}
|
|
9643
9638
|
return output;
|
|
9644
9639
|
}
|
|
9645
|
-
function
|
|
9640
|
+
function semanticRefPrefix(kind) {
|
|
9641
|
+
if (kind === "fig") {
|
|
9642
|
+
return "\u0627\u0644\u0634\u0643\u0644";
|
|
9643
|
+
}
|
|
9644
|
+
if (kind === "tab") {
|
|
9645
|
+
return "\u0627\u0644\u062C\u062F\u0648\u0644";
|
|
9646
|
+
}
|
|
9647
|
+
return "\u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629";
|
|
9648
|
+
}
|
|
9649
|
+
function semanticRefNames(kind) {
|
|
9650
|
+
if (kind === "fig") {
|
|
9651
|
+
return ["\u0627\u0644\u0634\u0643\u0644", "\u0634\u0643\u0644", "Figure", "figure"];
|
|
9652
|
+
}
|
|
9653
|
+
if (kind === "tab") {
|
|
9654
|
+
return ["\u0627\u0644\u062C\u062F\u0648\u0644", "\u062C\u062F\u0648\u0644", "Table", "table"];
|
|
9655
|
+
}
|
|
9656
|
+
return ["\u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629", "\u0645\u0639\u0627\u062F\u0644\u0629", "Equation", "equation"];
|
|
9657
|
+
}
|
|
9658
|
+
function previousTextAlreadyNamesKind(previousToken, kind) {
|
|
9659
|
+
if (previousToken?.kind !== "text") {
|
|
9660
|
+
return false;
|
|
9661
|
+
}
|
|
9662
|
+
const text = previousToken.text.trimEnd();
|
|
9663
|
+
return semanticRefNames(kind).some((name) => text.endsWith(name));
|
|
9664
|
+
}
|
|
9665
|
+
function refTokenLatexForDocument(token, labelKinds, previousToken) {
|
|
9666
|
+
const reference = refTokenLatex(token.keys, token.refCommand);
|
|
9667
|
+
if (!labelKinds || token.keys.length !== 1) {
|
|
9668
|
+
return reference;
|
|
9669
|
+
}
|
|
9670
|
+
const kind = labelKinds.get(token.keys[0]);
|
|
9671
|
+
if (!kind || previousTextAlreadyNamesKind(previousToken, kind)) {
|
|
9672
|
+
return reference;
|
|
9673
|
+
}
|
|
9674
|
+
return `${semanticRefPrefix(kind)}~${reference}`;
|
|
9675
|
+
}
|
|
9676
|
+
function tokenLatex(token, labelKinds, previousToken) {
|
|
9646
9677
|
if (token.kind === "text") {
|
|
9647
9678
|
return styledTextLatex(token.text, token.style);
|
|
9648
9679
|
}
|
|
@@ -9650,7 +9681,7 @@ function tokenLatex(token) {
|
|
|
9650
9681
|
return citeTokenLatex(token.keys);
|
|
9651
9682
|
}
|
|
9652
9683
|
if (token.kind === "ref") {
|
|
9653
|
-
return
|
|
9684
|
+
return refTokenLatexForDocument(token, labelKinds, previousToken);
|
|
9654
9685
|
}
|
|
9655
9686
|
if (token.display && token.labelEnabled && token.label && token.label.trim().length > 0) {
|
|
9656
9687
|
const body = mathBodyLatex(token);
|
|
@@ -9667,11 +9698,11 @@ ${body}
|
|
|
9667
9698
|
}
|
|
9668
9699
|
return renderMathNodeLatex(token.math);
|
|
9669
9700
|
}
|
|
9670
|
-
function
|
|
9671
|
-
return field.tokens.map((token) => tokenLatex(token)).join("");
|
|
9701
|
+
function inlineFieldLatexWithLabelKinds(field, labelKinds) {
|
|
9702
|
+
return field.tokens.map((token, index) => tokenLatex(token, labelKinds, field.tokens[index - 1])).join("");
|
|
9672
9703
|
}
|
|
9673
|
-
function textBlockLatex(block) {
|
|
9674
|
-
const content =
|
|
9704
|
+
function textBlockLatex(block, labelKinds) {
|
|
9705
|
+
const content = inlineFieldLatexWithLabelKinds(block.field, labelKinds);
|
|
9675
9706
|
const body = block.command === "\\paragraph" ? `\\par
|
|
9676
9707
|
${content}` : `${block.command}{${content}}`;
|
|
9677
9708
|
if (block.command === "\\paragraph" && block.centered) {
|
|
@@ -9684,38 +9715,61 @@ ${body}
|
|
|
9684
9715
|
function indent(value) {
|
|
9685
9716
|
return value.split("\n").map((line) => ` ${line}`).join("\n");
|
|
9686
9717
|
}
|
|
9687
|
-
function listBlockLatex(block, references) {
|
|
9718
|
+
function listBlockLatex(block, references, labelKinds, fixedFloats) {
|
|
9688
9719
|
const items = block.items.map((item) => {
|
|
9689
|
-
const nested = item.blocks.map((child) => "\n" + indent(blockLatex(child, references))).join("");
|
|
9690
|
-
return ` \\item ${
|
|
9720
|
+
const nested = item.blocks.map((child) => "\n" + indent(blockLatex(child, references, labelKinds, fixedFloats))).join("");
|
|
9721
|
+
return ` \\item ${inlineFieldLatexWithLabelKinds(item.field, labelKinds)}${nested}`;
|
|
9691
9722
|
}).join("\n");
|
|
9692
9723
|
return `${block.command}
|
|
9693
9724
|
${items}
|
|
9694
9725
|
${block.closing}`;
|
|
9695
9726
|
}
|
|
9696
|
-
function
|
|
9697
|
-
const
|
|
9727
|
+
function defaultGridColumnSpec(block) {
|
|
9728
|
+
const compact = block.columns.replace(/\s+/g, "");
|
|
9729
|
+
const columnCount = block.rows[0]?.length ?? 0;
|
|
9730
|
+
if (columnCount === 0 || compact.length !== columnCount || !/^[lcr]+$/.test(compact)) {
|
|
9731
|
+
return null;
|
|
9732
|
+
}
|
|
9733
|
+
return `|${compact.split("").join("|")}|`;
|
|
9734
|
+
}
|
|
9735
|
+
function tabularInnerLatex(block, labelKinds) {
|
|
9736
|
+
const rows = block.rows.map(
|
|
9737
|
+
(row) => ` ${row.map((cell) => inlineFieldLatexWithLabelKinds(cell, labelKinds)).join(" & ")}`
|
|
9738
|
+
);
|
|
9739
|
+
const gridColumns = defaultGridColumnSpec(block);
|
|
9740
|
+
if (gridColumns) {
|
|
9741
|
+
const griddedRows = rows.map((row) => `${row} \\\\ \\hline`).join("\n");
|
|
9742
|
+
return `${block.command}{${gridColumns}}
|
|
9743
|
+
\\hline
|
|
9744
|
+
${griddedRows}
|
|
9745
|
+
${block.closing}`;
|
|
9746
|
+
}
|
|
9698
9747
|
return `${block.command}{${block.columns}}
|
|
9699
|
-
${rows}
|
|
9748
|
+
${rows.join(" \\\\\n")}
|
|
9700
9749
|
${block.closing}`;
|
|
9701
9750
|
}
|
|
9702
|
-
function floatCaptionLabelLines(block) {
|
|
9751
|
+
function floatCaptionLabelLines(block, counter) {
|
|
9703
9752
|
const lines = [];
|
|
9704
|
-
|
|
9753
|
+
const hasCaption = block.captionEnabled && block.caption.trim().length > 0;
|
|
9754
|
+
if (hasCaption) {
|
|
9705
9755
|
lines.push(` \\caption{${block.caption.trim()}}`);
|
|
9706
9756
|
}
|
|
9707
9757
|
if (block.labelEnabled && block.label.trim().length > 0) {
|
|
9758
|
+
if (!hasCaption) {
|
|
9759
|
+
lines.push(` \\refstepcounter{${counter}}`);
|
|
9760
|
+
}
|
|
9708
9761
|
lines.push(` \\label{${block.label.trim()}}`);
|
|
9709
9762
|
}
|
|
9710
9763
|
return lines;
|
|
9711
9764
|
}
|
|
9712
|
-
function tableBlockLatex(block) {
|
|
9713
|
-
const
|
|
9765
|
+
function tableBlockLatex(block, labelKinds, fixedFloats) {
|
|
9766
|
+
const placement = fixedFloats ? "H" : "htbp";
|
|
9767
|
+
const lines = [`\\begin{table}[${placement}]`];
|
|
9714
9768
|
if (block.centered) {
|
|
9715
9769
|
lines.push(" \\centering");
|
|
9716
9770
|
}
|
|
9717
|
-
lines.push(...floatCaptionLabelLines(block));
|
|
9718
|
-
lines.push(indent(tabularInnerLatex(block)));
|
|
9771
|
+
lines.push(...floatCaptionLabelLines(block, "table"));
|
|
9772
|
+
lines.push(indent(tabularInnerLatex(block, labelKinds)));
|
|
9719
9773
|
lines.push("\\end{table}");
|
|
9720
9774
|
return lines.join("\n");
|
|
9721
9775
|
}
|
|
@@ -9734,28 +9788,29 @@ function imageOptionsLatex(block, constrainToColumn) {
|
|
|
9734
9788
|
}
|
|
9735
9789
|
return `[${entries.map(([key, value]) => `${key}=${value}`).join(",")}]`;
|
|
9736
9790
|
}
|
|
9737
|
-
function imageBlockLatex(block) {
|
|
9738
|
-
const
|
|
9791
|
+
function imageBlockLatex(block, fixedFloats) {
|
|
9792
|
+
const placement = fixedFloats ? "H" : "htbp";
|
|
9793
|
+
const lines = [`\\begin{figure}[${placement}]`];
|
|
9739
9794
|
if (block.centered) {
|
|
9740
9795
|
lines.push(" \\centering");
|
|
9741
9796
|
}
|
|
9742
9797
|
lines.push(` ${block.command}${imageOptionsLatex(block, true)}{${block.value}}`);
|
|
9743
|
-
lines.push(...floatCaptionLabelLines(block));
|
|
9798
|
+
lines.push(...floatCaptionLabelLines(block, "figure"));
|
|
9744
9799
|
lines.push("\\end{figure}");
|
|
9745
9800
|
return lines.join("\n");
|
|
9746
9801
|
}
|
|
9747
|
-
function blockLatex(block, references) {
|
|
9802
|
+
function blockLatex(block, references, labelKinds, fixedFloats) {
|
|
9748
9803
|
if (block.kind === "textBlock") {
|
|
9749
|
-
return textBlockLatex(block);
|
|
9804
|
+
return textBlockLatex(block, labelKinds);
|
|
9750
9805
|
}
|
|
9751
9806
|
if (block.kind === "list") {
|
|
9752
|
-
return listBlockLatex(block, references);
|
|
9807
|
+
return listBlockLatex(block, references, labelKinds, fixedFloats);
|
|
9753
9808
|
}
|
|
9754
9809
|
if (block.kind === "table") {
|
|
9755
|
-
return tableBlockLatex(block);
|
|
9810
|
+
return tableBlockLatex(block, labelKinds, fixedFloats);
|
|
9756
9811
|
}
|
|
9757
9812
|
if (block.kind === "image") {
|
|
9758
|
-
return imageBlockLatex(block);
|
|
9813
|
+
return imageBlockLatex(block, fixedFloats);
|
|
9759
9814
|
}
|
|
9760
9815
|
if (block.kind === "bibliography") {
|
|
9761
9816
|
const width = String(Math.max(references.length, 9));
|
|
@@ -9797,12 +9852,29 @@ ${meta.abstract.trim()}
|
|
|
9797
9852
|
}
|
|
9798
9853
|
return parts;
|
|
9799
9854
|
}
|
|
9855
|
+
function documentLabelKindMap(document2) {
|
|
9856
|
+
const map = /* @__PURE__ */ new Map();
|
|
9857
|
+
for (const entry of collectDocument2Labels(document2)) {
|
|
9858
|
+
if (!map.has(entry.key)) {
|
|
9859
|
+
map.set(entry.key, entry.kind);
|
|
9860
|
+
}
|
|
9861
|
+
}
|
|
9862
|
+
return map;
|
|
9863
|
+
}
|
|
9864
|
+
function closingHamdalaLatex() {
|
|
9865
|
+
return `\\begin{center}
|
|
9866
|
+
\\maghribi{${BUTEX_CLOSING_HAMDALA}}
|
|
9867
|
+
\\end{center}`;
|
|
9868
|
+
}
|
|
9800
9869
|
function document2Latex(document2, options = {}) {
|
|
9801
9870
|
const meta = document2.meta ?? emptyDocument2Meta();
|
|
9802
9871
|
const twocolumn = options.twocolumn === true;
|
|
9803
9872
|
const front = articleFrontMatterLatex(meta);
|
|
9804
|
-
const
|
|
9805
|
-
const
|
|
9873
|
+
const labelKinds = documentLabelKindMap(document2);
|
|
9874
|
+
const bodyBlocks = document2.blocks.map(
|
|
9875
|
+
(block) => blockLatex(block, document2.references, labelKinds, twocolumn)
|
|
9876
|
+
);
|
|
9877
|
+
const closing = closingHamdalaLatex();
|
|
9806
9878
|
const body = [...front, ...bodyBlocks, closing].filter((part) => part.length > 0).join("\n\n");
|
|
9807
9879
|
const wrapDocument = options.wrapDocument !== false;
|
|
9808
9880
|
if (!wrapDocument) {
|
|
@@ -9811,10 +9883,11 @@ function document2Latex(document2, options = {}) {
|
|
|
9811
9883
|
|
|
9812
9884
|
${body}` : body;
|
|
9813
9885
|
}
|
|
9886
|
+
const floatPackage = twocolumn ? "\n\\usepackage{float}\n" : "\n";
|
|
9814
9887
|
const preamble = getArabicXeLatexPreamble({
|
|
9815
9888
|
digitsMapping: options.digitsMapping ?? digitsMappingFromDigitForm(options.digitForm),
|
|
9816
9889
|
twocolumn
|
|
9817
|
-
}) +
|
|
9890
|
+
}) + floatPackage + articleMaketitlePreamble(meta, twocolumn);
|
|
9818
9891
|
return `${preamble}
|
|
9819
9892
|
\\begin{document}
|
|
9820
9893
|
|