tex2typst 0.3.0-beta-5 → 0.3.0-beta-6

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 CHANGED
@@ -1,5 +1,7 @@
1
1
  # tex2typst
2
- JavaScript library for converting TeX / LaTeX math formula code to Typst
2
+ JavaScript library for conversion between TeX/LaTeX and Typst math formula code.
3
+
4
+ Despite the name `tex2typst` due to the initial goal of converting TeX to Typst, the library can also convert Typst to TeX since version 0.3.0.
3
5
 
4
6
  ## Try it online
5
7
 
@@ -16,55 +18,35 @@ npm install tex2typst
16
18
  ## Or just loading it in a web page
17
19
 
18
20
  ```html
19
- <script src="https://cdn.jsdelivr.net/npm/tex2typst@0.2.7/dist/tex2typst.min.js"></script>
21
+ <script src="https://cdn.jsdelivr.net/npm/tex2typst@0.3.0-beta-5/dist/tex2typst.min.js"></script>
20
22
  <!-- or -->
21
- <script src="https://unpkg.com/tex2typst@0.2.7/dist/tex2typst.min.js"></script>
23
+ <script src="https://unpkg.com/tex2typst@0.3.0-beta-5/dist/tex2typst.min.js"></script>
22
24
  ```
23
25
 
24
- Replace `0.2.7` with the latest version number in case this README is outdated.
26
+ Replace `0.3.0-beta-5` with the latest version number in case this README is outdated.
25
27
 
26
- The size of minimized library `tex2typst.min.js` is about 23 KB.
27
28
 
28
29
  ## Usage
29
30
 
30
- ### Basic usage
31
31
 
32
32
  ```javascript
33
- import { tex2typst } from 'tex2typst';
34
-
35
- let output = tex2typst("\\zeta(s) = \\sum_{n=1}^{\\infty}\\frac{1}{n^s}");
36
- console.log(output);
37
- // zeta(s) = sum_(n = 1)^infinity frac(1, n^s)
38
- ```
39
-
40
- If you are using the library in a web page via a `<script>` tag, you don't need the line of `import`, function `tex2typst` should be available in the global scope.
33
+ import { tex2typst, typst2tex } from 'tex2typst';
41
34
 
35
+ let tex = "e \overset{\text{def}}{=} \lim_{{n \to \infty}} \left(1 + \frac{1}{n}\right)^n";
36
+ let typst = tex2typst(tex);
37
+ console.log(typst);
38
+ // e eq.def lim_(n arrow.r infinity)(1 + frac(1, n))^n
42
39
 
43
- ### Advanced options
44
-
45
- - custom TeX macros/commands
46
-
47
- For example,
48
- ```javascript
49
- let macros = {
50
- "\\sgn": "\\operatorname{sgn}"
51
- };
52
- let input = "y = \\sgn(x)";
53
- let output = tex2typst(input, {customTexMacros: macros});
54
- console.log(output);
55
- // y = op("sgn")(x)
40
+ let tex_recovered = typst2tex(typst);
41
+ console.log(tex_recovered);
42
+ // e \overset{\text{def}}{=} \lim_{n \rightarrow \infty} \left(1 + \frac{1}{n} \right)^n
56
43
  ```
57
44
 
58
- ## How it works
45
+ If you are using the library in a web page via a `<script>` tag, you don't need the line of `import`, function `tex2typst` and `typst2tex` should be available in the global scope.
59
46
 
60
- ```mermaid
61
- graph LR
62
- tex[TeX code] --parser--> tex_ast[TeX AST] --converter--> typst_ast[Typst AST] --writer--> typst[Typst code]
63
- ```
47
+ ## Open-source license
64
48
 
65
- - parser: Implemented in class `LatexParser`.
66
- - converter: Implemented in function `convertTree`.
67
- - writer: Implemented in class `TypstWriter`.
49
+ GPL v3. See [LICENSE](LICENSE) for details.
68
50
 
69
51
  ## Contributing
70
52
 
@@ -0,0 +1,3 @@
1
+ import { TexNode, TypstNode, Tex2TypstOptions } from "./types";
2
+ export declare function convert_tex_node_to_typst(node: TexNode, options?: Tex2TypstOptions): TypstNode;
3
+ export declare function convert_typst_node_to_tex(node: TypstNode): TexNode;