tex2typst 0.0.15 → 0.0.16
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/dist/writer.js +16 -0
- package/package.json +1 -1
- package/src/writer.ts +16 -0
package/dist/writer.js
CHANGED
|
@@ -310,6 +310,22 @@ class TypstWriter {
|
|
|
310
310
|
}
|
|
311
311
|
finalize() {
|
|
312
312
|
this.flushQueue();
|
|
313
|
+
const smartFloorPass = function (input) {
|
|
314
|
+
// Use regex to replace all "⌊ xxx ⌋" with "floor(xxx)"
|
|
315
|
+
let res = input.replace(/⌊\s*(.*?)\s*⌋/g, "floor($1)");
|
|
316
|
+
// Typst disallow "floor()" with empty argument, so add am empty string inside if it's empty.
|
|
317
|
+
res = res.replace(/floor\(\)/g, 'floor("")');
|
|
318
|
+
return res;
|
|
319
|
+
};
|
|
320
|
+
const smartCeilPass = function (input) {
|
|
321
|
+
// Use regex to replace all "⌈ xxx ⌉" with "ceil(xxx)"
|
|
322
|
+
let res = input.replace(/⌈\s*(.*?)\s*⌉/g, "ceil($1)");
|
|
323
|
+
// Typst disallow "ceil()" with empty argument, so add an empty string inside if it's empty.
|
|
324
|
+
res = res.replace(/ceil\(\)/g, 'ceil("")');
|
|
325
|
+
return res;
|
|
326
|
+
};
|
|
327
|
+
this.buffer = smartFloorPass(this.buffer);
|
|
328
|
+
this.buffer = smartCeilPass(this.buffer);
|
|
313
329
|
return this.buffer;
|
|
314
330
|
}
|
|
315
331
|
}
|
package/package.json
CHANGED
package/src/writer.ts
CHANGED
|
@@ -312,6 +312,22 @@ export class TypstWriter {
|
|
|
312
312
|
|
|
313
313
|
public finalize(): string {
|
|
314
314
|
this.flushQueue();
|
|
315
|
+
const smartFloorPass = function (input: string): string {
|
|
316
|
+
// Use regex to replace all "⌊ xxx ⌋" with "floor(xxx)"
|
|
317
|
+
let res = input.replace(/⌊\s*(.*?)\s*⌋/g, "floor($1)");
|
|
318
|
+
// Typst disallow "floor()" with empty argument, so add am empty string inside if it's empty.
|
|
319
|
+
res = res.replace(/floor\(\)/g, 'floor("")');
|
|
320
|
+
return res;
|
|
321
|
+
};
|
|
322
|
+
const smartCeilPass = function (input: string): string {
|
|
323
|
+
// Use regex to replace all "⌈ xxx ⌉" with "ceil(xxx)"
|
|
324
|
+
let res = input.replace(/⌈\s*(.*?)\s*⌉/g, "ceil($1)");
|
|
325
|
+
// Typst disallow "ceil()" with empty argument, so add an empty string inside if it's empty.
|
|
326
|
+
res = res.replace(/ceil\(\)/g, 'ceil("")');
|
|
327
|
+
return res;
|
|
328
|
+
}
|
|
329
|
+
this.buffer = smartFloorPass(this.buffer);
|
|
330
|
+
this.buffer = smartCeilPass(this.buffer);
|
|
315
331
|
return this.buffer;
|
|
316
332
|
}
|
|
317
333
|
}
|