@drghaliasri/butex 6.1.2 → 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 +153 -48
- package/dist/react-document2.js.map +1 -1
- package/dist/react-document2.mjs +153 -48
- package/dist/react-document2.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -254,13 +254,13 @@ const latex = document2Latex(documentNode);
|
|
|
254
254
|
const preview = document2Preview(documentNode, 'svg');
|
|
255
255
|
```
|
|
256
256
|
|
|
257
|
-
`document2Latex(doc)` emits a **complete Arabic XeLaTeX document** by default (preamble + `\begin{document}` + body + `\end{document}`). Structured and editor-authored Arabic roots serialize with the canonical `\arsqrt`; the bundled preamble also accepts raw legacy `\arabsqrt` with the same optional-index signature. It defines BuTeX font wrappers (`\butextakween`, `\butexdiwani`, `\butexdiwanioutline`, `\butexmaghribi`) and the MathJax-compatible `\butexmirror` bridge. The
|
|
257
|
+
`document2Latex(doc)` emits a **complete Arabic XeLaTeX document** by default (preamble + `\begin{document}` + body + `\end{document}`). Structured and editor-authored Arabic roots serialize with the canonical `\arsqrt`; the bundled preamble also accepts raw legacy `\arabsqrt` with the same optional-index signature. It defines BuTeX font wrappers (`\butextakween`, `\butexdiwani`, `\butexdiwanioutline`, `\butexmaghribi`) and the MathJax-compatible `\butexmirror` bridge. The title-path basmala keeps its Maghribi title styling; the fixed closing hamdala is emitted as normal centered `\maghribi` text rather than display math so it participates in ordinary column/page flow. Pass `{ wrapDocument: false }` for body-only blocks. Paragraph blocks export as `\par` followed by the inline content, so prose, citations, and math are not wrapped inside `\paragraph{...}`. Optional `digitsMapping: 'arabicdigits' | 'digits'` controls eastern vs western digit font mapping in the preamble (default `'arabicdigits'`). Pass `{ twocolumn: true }` for `\documentclass[12pt,a4paper,notitlepage,twocolumn]{article}`; title content stays in-column and Document2 figure/table floats use fixed `[H]` placement (with the `float` package) so source block order remains predictable. Figures continue to use `\columnwidth`. See [`examples/example-latex-export.tex`](examples/example-latex-export.tex) for a full sample (regenerated by the wrap vitest). Hosts can also call `getArabicXeLatexPreamble()` alone.
|
|
258
258
|
|
|
259
259
|
For XeLaTeX compiler images, install `src/fonts/Almaghribi-Warsh-Quran.otf` as a system font and refresh fontconfig (`fc-cache -f -v`). Verify with `fc-match "Almaghribi Warsh Quran"`; the preamble uses that installed family name.
|
|
260
260
|
|
|
261
261
|
To add another character font, add its metadata to `src/editor/characterFonts.ts` and its browser `@font-face` asset to `src/diwani-font.ts`.
|
|
262
262
|
|
|
263
|
-
Figures and tables
|
|
263
|
+
Figures and tables export as centered `figure` / `table` environments. In one-column export they retain normal `[htbp]` float placement; in `twocolumn` export they use fixed `[H]` placement to avoid unexpected reordering/gaps. Simple editor table column specifications made only from `l`, `c`, and `r` (for example `lll`) receive a visible grid by default (`|l|l|l|` plus `\hline`); explicitly structured specifications such as `c|c` are preserved. Optional caption/label fields emit `\caption` / `\label`; a labeled figure/table without a caption uses `\refstepcounter{figure}` / `\refstepcounter{table}` before its label so the reference owns the correct counter. Display math stays `\[…\]` unless an equation label is enabled, then export uses `\begin{equation}…\label{…}\end{equation}`. Internal cross-refs still store `\ref` / `\eqref` tokens separately from bibliography `\cite`, but LaTeX export adds the known Arabic object type (`الشكل`, `الجدول`, or `المعادلة`) when the reference target is known and the prose immediately before the token has not already named that type.
|
|
264
264
|
|
|
265
265
|
V2 exports Arabic TeX by default for equations saved from the embedded editor. Imported raw-only math is preserved as raw source and marked non-editable until a structured equation object is attached.
|
|
266
266
|
|
package/dist/document2.js
CHANGED
|
@@ -6994,7 +6994,43 @@ function styledTextLatex(text, style) {
|
|
|
6994
6994
|
}
|
|
6995
6995
|
return output;
|
|
6996
6996
|
}
|
|
6997
|
-
function
|
|
6997
|
+
function semanticRefPrefix(kind) {
|
|
6998
|
+
if (kind === "fig") {
|
|
6999
|
+
return "\u0627\u0644\u0634\u0643\u0644";
|
|
7000
|
+
}
|
|
7001
|
+
if (kind === "tab") {
|
|
7002
|
+
return "\u0627\u0644\u062C\u062F\u0648\u0644";
|
|
7003
|
+
}
|
|
7004
|
+
return "\u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629";
|
|
7005
|
+
}
|
|
7006
|
+
function semanticRefNames(kind) {
|
|
7007
|
+
if (kind === "fig") {
|
|
7008
|
+
return ["\u0627\u0644\u0634\u0643\u0644", "\u0634\u0643\u0644", "Figure", "figure"];
|
|
7009
|
+
}
|
|
7010
|
+
if (kind === "tab") {
|
|
7011
|
+
return ["\u0627\u0644\u062C\u062F\u0648\u0644", "\u062C\u062F\u0648\u0644", "Table", "table"];
|
|
7012
|
+
}
|
|
7013
|
+
return ["\u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629", "\u0645\u0639\u0627\u062F\u0644\u0629", "Equation", "equation"];
|
|
7014
|
+
}
|
|
7015
|
+
function previousTextAlreadyNamesKind(previousToken, kind) {
|
|
7016
|
+
if (previousToken?.kind !== "text") {
|
|
7017
|
+
return false;
|
|
7018
|
+
}
|
|
7019
|
+
const text = previousToken.text.trimEnd();
|
|
7020
|
+
return semanticRefNames(kind).some((name) => text.endsWith(name));
|
|
7021
|
+
}
|
|
7022
|
+
function refTokenLatexForDocument(token, labelKinds, previousToken) {
|
|
7023
|
+
const reference = refTokenLatex(token.keys, token.refCommand);
|
|
7024
|
+
if (!labelKinds || token.keys.length !== 1) {
|
|
7025
|
+
return reference;
|
|
7026
|
+
}
|
|
7027
|
+
const kind = labelKinds.get(token.keys[0]);
|
|
7028
|
+
if (!kind || previousTextAlreadyNamesKind(previousToken, kind)) {
|
|
7029
|
+
return reference;
|
|
7030
|
+
}
|
|
7031
|
+
return `${semanticRefPrefix(kind)}~${reference}`;
|
|
7032
|
+
}
|
|
7033
|
+
function tokenLatex(token, labelKinds, previousToken) {
|
|
6998
7034
|
if (token.kind === "text") {
|
|
6999
7035
|
return styledTextLatex(token.text, token.style);
|
|
7000
7036
|
}
|
|
@@ -7002,7 +7038,7 @@ function tokenLatex(token) {
|
|
|
7002
7038
|
return citeTokenLatex(token.keys);
|
|
7003
7039
|
}
|
|
7004
7040
|
if (token.kind === "ref") {
|
|
7005
|
-
return
|
|
7041
|
+
return refTokenLatexForDocument(token, labelKinds, previousToken);
|
|
7006
7042
|
}
|
|
7007
7043
|
if (token.display && token.labelEnabled && token.label && token.label.trim().length > 0) {
|
|
7008
7044
|
const body = mathBodyLatex(token);
|
|
@@ -7019,11 +7055,14 @@ ${body}
|
|
|
7019
7055
|
}
|
|
7020
7056
|
return renderMathNodeLatex(token.math);
|
|
7021
7057
|
}
|
|
7058
|
+
function inlineFieldLatexWithLabelKinds(field, labelKinds) {
|
|
7059
|
+
return field.tokens.map((token, index) => tokenLatex(token, labelKinds, field.tokens[index - 1])).join("");
|
|
7060
|
+
}
|
|
7022
7061
|
function inlineFieldLatex(field) {
|
|
7023
|
-
return field
|
|
7062
|
+
return inlineFieldLatexWithLabelKinds(field);
|
|
7024
7063
|
}
|
|
7025
|
-
function textBlockLatex(block) {
|
|
7026
|
-
const content =
|
|
7064
|
+
function textBlockLatex(block, labelKinds) {
|
|
7065
|
+
const content = inlineFieldLatexWithLabelKinds(block.field, labelKinds);
|
|
7027
7066
|
const body = block.command === "\\paragraph" ? `\\par
|
|
7028
7067
|
${content}` : `${block.command}{${content}}`;
|
|
7029
7068
|
if (block.command === "\\paragraph" && block.centered) {
|
|
@@ -7036,38 +7075,61 @@ ${body}
|
|
|
7036
7075
|
function indent(value) {
|
|
7037
7076
|
return value.split("\n").map((line) => ` ${line}`).join("\n");
|
|
7038
7077
|
}
|
|
7039
|
-
function listBlockLatex(block, references) {
|
|
7078
|
+
function listBlockLatex(block, references, labelKinds, fixedFloats) {
|
|
7040
7079
|
const items = block.items.map((item) => {
|
|
7041
|
-
const nested = item.blocks.map((child) => "\n" + indent(blockLatex(child, references))).join("");
|
|
7042
|
-
return ` \\item ${
|
|
7080
|
+
const nested = item.blocks.map((child) => "\n" + indent(blockLatex(child, references, labelKinds, fixedFloats))).join("");
|
|
7081
|
+
return ` \\item ${inlineFieldLatexWithLabelKinds(item.field, labelKinds)}${nested}`;
|
|
7043
7082
|
}).join("\n");
|
|
7044
7083
|
return `${block.command}
|
|
7045
7084
|
${items}
|
|
7046
7085
|
${block.closing}`;
|
|
7047
7086
|
}
|
|
7048
|
-
function
|
|
7049
|
-
const
|
|
7087
|
+
function defaultGridColumnSpec(block) {
|
|
7088
|
+
const compact = block.columns.replace(/\s+/g, "");
|
|
7089
|
+
const columnCount = block.rows[0]?.length ?? 0;
|
|
7090
|
+
if (columnCount === 0 || compact.length !== columnCount || !/^[lcr]+$/.test(compact)) {
|
|
7091
|
+
return null;
|
|
7092
|
+
}
|
|
7093
|
+
return `|${compact.split("").join("|")}|`;
|
|
7094
|
+
}
|
|
7095
|
+
function tabularInnerLatex(block, labelKinds) {
|
|
7096
|
+
const rows = block.rows.map(
|
|
7097
|
+
(row) => ` ${row.map((cell) => inlineFieldLatexWithLabelKinds(cell, labelKinds)).join(" & ")}`
|
|
7098
|
+
);
|
|
7099
|
+
const gridColumns = defaultGridColumnSpec(block);
|
|
7100
|
+
if (gridColumns) {
|
|
7101
|
+
const griddedRows = rows.map((row) => `${row} \\\\ \\hline`).join("\n");
|
|
7102
|
+
return `${block.command}{${gridColumns}}
|
|
7103
|
+
\\hline
|
|
7104
|
+
${griddedRows}
|
|
7105
|
+
${block.closing}`;
|
|
7106
|
+
}
|
|
7050
7107
|
return `${block.command}{${block.columns}}
|
|
7051
|
-
${rows}
|
|
7108
|
+
${rows.join(" \\\\\n")}
|
|
7052
7109
|
${block.closing}`;
|
|
7053
7110
|
}
|
|
7054
|
-
function floatCaptionLabelLines(block) {
|
|
7111
|
+
function floatCaptionLabelLines(block, counter) {
|
|
7055
7112
|
const lines = [];
|
|
7056
|
-
|
|
7113
|
+
const hasCaption = block.captionEnabled && block.caption.trim().length > 0;
|
|
7114
|
+
if (hasCaption) {
|
|
7057
7115
|
lines.push(` \\caption{${block.caption.trim()}}`);
|
|
7058
7116
|
}
|
|
7059
7117
|
if (block.labelEnabled && block.label.trim().length > 0) {
|
|
7118
|
+
if (!hasCaption) {
|
|
7119
|
+
lines.push(` \\refstepcounter{${counter}}`);
|
|
7120
|
+
}
|
|
7060
7121
|
lines.push(` \\label{${block.label.trim()}}`);
|
|
7061
7122
|
}
|
|
7062
7123
|
return lines;
|
|
7063
7124
|
}
|
|
7064
|
-
function tableBlockLatex(block) {
|
|
7065
|
-
const
|
|
7125
|
+
function tableBlockLatex(block, labelKinds, fixedFloats) {
|
|
7126
|
+
const placement = fixedFloats ? "H" : "htbp";
|
|
7127
|
+
const lines = [`\\begin{table}[${placement}]`];
|
|
7066
7128
|
if (block.centered) {
|
|
7067
7129
|
lines.push(" \\centering");
|
|
7068
7130
|
}
|
|
7069
|
-
lines.push(...floatCaptionLabelLines(block));
|
|
7070
|
-
lines.push(indent(tabularInnerLatex(block)));
|
|
7131
|
+
lines.push(...floatCaptionLabelLines(block, "table"));
|
|
7132
|
+
lines.push(indent(tabularInnerLatex(block, labelKinds)));
|
|
7071
7133
|
lines.push("\\end{table}");
|
|
7072
7134
|
return lines.join("\n");
|
|
7073
7135
|
}
|
|
@@ -7086,28 +7148,29 @@ function imageOptionsLatex(block, constrainToColumn) {
|
|
|
7086
7148
|
}
|
|
7087
7149
|
return `[${entries.map(([key, value]) => `${key}=${value}`).join(",")}]`;
|
|
7088
7150
|
}
|
|
7089
|
-
function imageBlockLatex(block) {
|
|
7090
|
-
const
|
|
7151
|
+
function imageBlockLatex(block, fixedFloats) {
|
|
7152
|
+
const placement = fixedFloats ? "H" : "htbp";
|
|
7153
|
+
const lines = [`\\begin{figure}[${placement}]`];
|
|
7091
7154
|
if (block.centered) {
|
|
7092
7155
|
lines.push(" \\centering");
|
|
7093
7156
|
}
|
|
7094
7157
|
lines.push(` ${block.command}${imageOptionsLatex(block, true)}{${block.value}}`);
|
|
7095
|
-
lines.push(...floatCaptionLabelLines(block));
|
|
7158
|
+
lines.push(...floatCaptionLabelLines(block, "figure"));
|
|
7096
7159
|
lines.push("\\end{figure}");
|
|
7097
7160
|
return lines.join("\n");
|
|
7098
7161
|
}
|
|
7099
|
-
function blockLatex(block, references) {
|
|
7162
|
+
function blockLatex(block, references, labelKinds, fixedFloats) {
|
|
7100
7163
|
if (block.kind === "textBlock") {
|
|
7101
|
-
return textBlockLatex(block);
|
|
7164
|
+
return textBlockLatex(block, labelKinds);
|
|
7102
7165
|
}
|
|
7103
7166
|
if (block.kind === "list") {
|
|
7104
|
-
return listBlockLatex(block, references);
|
|
7167
|
+
return listBlockLatex(block, references, labelKinds, fixedFloats);
|
|
7105
7168
|
}
|
|
7106
7169
|
if (block.kind === "table") {
|
|
7107
|
-
return tableBlockLatex(block);
|
|
7170
|
+
return tableBlockLatex(block, labelKinds, fixedFloats);
|
|
7108
7171
|
}
|
|
7109
7172
|
if (block.kind === "image") {
|
|
7110
|
-
return imageBlockLatex(block);
|
|
7173
|
+
return imageBlockLatex(block, fixedFloats);
|
|
7111
7174
|
}
|
|
7112
7175
|
if (block.kind === "bibliography") {
|
|
7113
7176
|
const width = String(Math.max(references.length, 9));
|
|
@@ -7149,12 +7212,29 @@ ${meta.abstract.trim()}
|
|
|
7149
7212
|
}
|
|
7150
7213
|
return parts;
|
|
7151
7214
|
}
|
|
7215
|
+
function documentLabelKindMap(document2) {
|
|
7216
|
+
const map = /* @__PURE__ */ new Map();
|
|
7217
|
+
for (const entry of collectDocument2Labels(document2)) {
|
|
7218
|
+
if (!map.has(entry.key)) {
|
|
7219
|
+
map.set(entry.key, entry.kind);
|
|
7220
|
+
}
|
|
7221
|
+
}
|
|
7222
|
+
return map;
|
|
7223
|
+
}
|
|
7224
|
+
function closingHamdalaLatex() {
|
|
7225
|
+
return `\\begin{center}
|
|
7226
|
+
\\maghribi{${BUTEX_CLOSING_HAMDALA}}
|
|
7227
|
+
\\end{center}`;
|
|
7228
|
+
}
|
|
7152
7229
|
function document2Latex(document2, options = {}) {
|
|
7153
7230
|
const meta = document2.meta ?? emptyDocument2Meta();
|
|
7154
7231
|
const twocolumn = options.twocolumn === true;
|
|
7155
7232
|
const front = articleFrontMatterLatex(meta);
|
|
7156
|
-
const
|
|
7157
|
-
const
|
|
7233
|
+
const labelKinds = documentLabelKindMap(document2);
|
|
7234
|
+
const bodyBlocks = document2.blocks.map(
|
|
7235
|
+
(block) => blockLatex(block, document2.references, labelKinds, twocolumn)
|
|
7236
|
+
);
|
|
7237
|
+
const closing = closingHamdalaLatex();
|
|
7158
7238
|
const body = [...front, ...bodyBlocks, closing].filter((part) => part.length > 0).join("\n\n");
|
|
7159
7239
|
const wrapDocument = options.wrapDocument !== false;
|
|
7160
7240
|
if (!wrapDocument) {
|
|
@@ -7163,10 +7243,11 @@ function document2Latex(document2, options = {}) {
|
|
|
7163
7243
|
|
|
7164
7244
|
${body}` : body;
|
|
7165
7245
|
}
|
|
7246
|
+
const floatPackage = twocolumn ? "\n\\usepackage{float}\n" : "\n";
|
|
7166
7247
|
const preamble = getArabicXeLatexPreamble({
|
|
7167
7248
|
digitsMapping: options.digitsMapping ?? digitsMappingFromDigitForm(options.digitForm),
|
|
7168
7249
|
twocolumn
|
|
7169
|
-
}) +
|
|
7250
|
+
}) + floatPackage + articleMaketitlePreamble(meta, twocolumn);
|
|
7170
7251
|
return `${preamble}
|
|
7171
7252
|
\\begin{document}
|
|
7172
7253
|
|