tex2typst 0.3.16 → 0.3.18
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/index.js +176 -85
- package/dist/tex2typst.min.js +12 -12
- package/dist/types.d.ts +14 -7
- package/dist/typst-writer.d.ts +3 -1
- package/package.json +1 -1
- package/src/convert.ts +178 -62
- package/src/index.ts +1 -0
- package/src/map.ts +2 -0
- package/src/tex-parser.ts +17 -4
- package/src/types.ts +21 -7
- package/src/typst-writer.ts +17 -26
- package/TODO.md +0 -1
- package/docs/api-reference.md +0 -64
- package/tools/make-shorthand-map.py +0 -33
- package/tools/make-symbol-map.py +0 -35
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import urllib.request
|
|
2
|
-
import html
|
|
3
|
-
from bs4 import BeautifulSoup
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if __name__ == '__main__':
|
|
7
|
-
shorthand_map = []
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
url = "https://typst.app/docs/reference/symbols/"
|
|
11
|
-
with urllib.request.urlopen(url) as response:
|
|
12
|
-
html_text = response.read().decode('utf-8')
|
|
13
|
-
|
|
14
|
-
soup = BeautifulSoup(html_text, 'html.parser')
|
|
15
|
-
|
|
16
|
-
# <ul class="symbol-grid">
|
|
17
|
-
ul_list = soup.find_all('ul', class_='symbol-grid')
|
|
18
|
-
# ul_shorthands_markup = ul_list[0]
|
|
19
|
-
ul_shorthands_math = ul_list[1]
|
|
20
|
-
|
|
21
|
-
li_list = ul_shorthands_math.find_all('li')
|
|
22
|
-
for li in li_list:
|
|
23
|
-
# e.g. <li id="symbol-arrow.r" data-math-shorthand="->"><button>...</button></li>
|
|
24
|
-
# ==> typst = "arrow.r"
|
|
25
|
-
# ==> shorthand = "->"
|
|
26
|
-
typst = li['id'][7:]
|
|
27
|
-
shorthand = html.unescape(li['data-math-shorthand'])
|
|
28
|
-
shorthand_map.append((typst, shorthand))
|
|
29
|
-
|
|
30
|
-
# Sort by length of shorthand, order from longest to shortest
|
|
31
|
-
shorthand_map.sort(key=lambda x: len(x[1]), reverse=True)
|
|
32
|
-
for typst, shorthand in shorthand_map:
|
|
33
|
-
print(f"['{typst}', '{shorthand}'],")
|
package/tools/make-symbol-map.py
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import urllib.request
|
|
2
|
-
from bs4 import BeautifulSoup
|
|
3
|
-
|
|
4
|
-
if __name__ == '__main__':
|
|
5
|
-
symbol_map = {}
|
|
6
|
-
|
|
7
|
-
url = "https://typst.app/docs/reference/symbols/sym/"
|
|
8
|
-
with urllib.request.urlopen(url) as response:
|
|
9
|
-
html_text = response.read().decode('utf-8')
|
|
10
|
-
|
|
11
|
-
soup = BeautifulSoup(html_text, 'html.parser')
|
|
12
|
-
# <ul class="symbol-grid">
|
|
13
|
-
ul = soup.find('ul', class_='symbol-grid')
|
|
14
|
-
li_list = ul.find_all('li')
|
|
15
|
-
for li in li_list:
|
|
16
|
-
# e.g. <li id="symbol-brace.r.double" data-latex-name="\rBrace" data-codepoint="10628"><button>...</button></li>
|
|
17
|
-
# ==> latex = rBrace
|
|
18
|
-
# ==> typst = brace.r.double
|
|
19
|
-
# ==> unicode = 10628 = \u2984
|
|
20
|
-
latex = li.get('data-latex-name', None)
|
|
21
|
-
typst = li['id'][7:]
|
|
22
|
-
unicode = int(li['data-codepoint'])
|
|
23
|
-
if latex is not None:
|
|
24
|
-
# some latex macro can be associated with multiple typst
|
|
25
|
-
# e.g. \equiv can be mapped to equal or equiv.triple
|
|
26
|
-
# We only keep the first one
|
|
27
|
-
if latex not in symbol_map:
|
|
28
|
-
symbol_map[latex] = typst
|
|
29
|
-
|
|
30
|
-
# sort the pairs with alphabetical order of latex
|
|
31
|
-
sorted_keys = sorted(list(symbol_map.keys()), key=str.lower)
|
|
32
|
-
sorted_symbol_map = [(key, symbol_map[key]) for key in sorted_keys]
|
|
33
|
-
for latex, typst in sorted_symbol_map:
|
|
34
|
-
print(f" ['{latex[1:]}', '{typst}'],")
|
|
35
|
-
# print(f'{latex[1:]} = "{typst}"')
|