tex2typst 0.2.11 → 0.2.12

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/src/writer.ts CHANGED
@@ -267,22 +267,22 @@ export class TypstWriter {
267
267
  public finalize(): string {
268
268
  this.flushQueue();
269
269
  const smartFloorPass = function (input: string): string {
270
- // Use regex to replace all " xxx " with "floor(xxx)"
271
- let res = input.replace(/⌊\s*(.*?)\s*⌋/g, "floor($1)");
270
+ // Use regex to replace all "floor.l xxx floor.r" with "floor(xxx)"
271
+ let res = input.replace(/floor\.l\s*(.*?)\s*floor\.r/g, "floor($1)");
272
272
  // Typst disallow "floor()" with empty argument, so add am empty string inside if it's empty.
273
273
  res = res.replace(/floor\(\)/g, 'floor("")');
274
274
  return res;
275
275
  };
276
276
  const smartCeilPass = function (input: string): string {
277
- // Use regex to replace all " xxx " with "ceil(xxx)"
278
- let res = input.replace(/⌈\s*(.*?)\s*⌉/g, "ceil($1)");
277
+ // Use regex to replace all "ceil.l xxx ceil.r" with "ceil(xxx)"
278
+ let res = input.replace(/ceil\.l\s*(.*?)\s*ceil\.r/g, "ceil($1)");
279
279
  // Typst disallow "ceil()" with empty argument, so add an empty string inside if it's empty.
280
280
  res = res.replace(/ceil\(\)/g, 'ceil("")');
281
281
  return res;
282
282
  }
283
283
  const smartRoundPass = function (input: string): string {
284
- // Use regex to replace all " xxx " with "round(xxx)"
285
- let res = input.replace(/⌊\s*(.*?)\s*⌉/g, "round($1)");
284
+ // Use regex to replace all "floor.l xxx ceil.r" with "round(xxx)"
285
+ let res = input.replace(/floor\.l\s*(.*?)\s*ceil\.r/g, "round($1)");
286
286
  // Typst disallow "round()" with empty argument, so add an empty string inside if it's empty.
287
287
  res = res.replace(/round\(\)/g, 'round("")');
288
288
  return res;
@@ -0,0 +1,29 @@
1
+ import requests
2
+ from bs4 import BeautifulSoup
3
+
4
+
5
+ if __name__ == '__main__':
6
+ symbol_map = {}
7
+
8
+ url = "https://typst.app/docs/reference/symbols/sym/"
9
+ html_text = requests.get(url).text
10
+ soup = BeautifulSoup(html_text, 'html.parser')
11
+ # <ul class="symbol-grid">
12
+ ul = soup.find('ul', class_='symbol-grid')
13
+ li_list = ul.find_all('li')
14
+ for li in li_list:
15
+ # e.g. <li id="symbol-brace.r.double" data-latex-name="\rBrace" data-codepoint="10628"><button>...</button></li>
16
+ # ==> latex = rBrace
17
+ # ==> typst = brace.r.double
18
+ # ==> unicode = 10628 = \u2984
19
+ latex = li.get('data-latex-name', None)
20
+ typst = li['id'][7:]
21
+ unicode = int(li['data-codepoint'])
22
+ if latex is not None:
23
+ # some latex macro can be associated with multiple typst
24
+ # e.g. \equiv can be mapped to equal or equiv.triple
25
+ # We only keep the first one
26
+ if latex not in symbol_map:
27
+ symbol_map[latex] = typst
28
+ # print(f" ['{latex[1:]}', '{typst}'],")
29
+ print(f'{latex[1:]} = "{typst}"')