Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
qwinsi committed Jan 26, 2025
1 parent 666820d commit 2393c20
Showing 1 changed file with 17 additions and 35 deletions.
52 changes: 17 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# tex2typst
JavaScript library for converting TeX / LaTeX math formula code to Typst
JavaScript library for conversion between TeX/LaTeX and Typst math formula code.

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.

## Try it online

Expand All @@ -16,55 +18,35 @@ npm install tex2typst
## Or just loading it in a web page

```html
<script src="https://cdn.jsdelivr.net/npm/tex2typst@0.2.7/dist/tex2typst.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/tex2typst@0.3.0-beta-5/dist/tex2typst.min.js"></script>
<!-- or -->
<script src="https://unpkg.com/tex2typst@0.2.7/dist/tex2typst.min.js"></script>
<script src="https://unpkg.com/tex2typst@0.3.0-beta-5/dist/tex2typst.min.js"></script>
```

Replace `0.2.7` with the latest version number in case this README is outdated.
Replace `0.3.0-beta-5` with the latest version number in case this README is outdated.

The size of minimized library `tex2typst.min.js` is about 23 KB.

## Usage

### Basic usage

```javascript
import { tex2typst } from 'tex2typst';

let output = tex2typst("\\zeta(s) = \\sum_{n=1}^{\\infty}\\frac{1}{n^s}");
console.log(output);
// zeta(s) = sum_(n = 1)^infinity frac(1, n^s)
```

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.
import { tex2typst, typst2tex } from 'tex2typst';

let tex = "e \overset{\text{def}}{=} \lim_{{n \to \infty}} \left(1 + \frac{1}{n}\right)^n";
let typst = tex2typst(tex);
console.log(typst);
// e eq.def lim_(n arrow.r infinity)(1 + frac(1, n))^n

### Advanced options

- custom TeX macros/commands

For example,
```javascript
let macros = {
"\\sgn": "\\operatorname{sgn}"
};
let input = "y = \\sgn(x)";
let output = tex2typst(input, {customTexMacros: macros});
console.log(output);
// y = op("sgn")(x)
let tex_recovered = typst2tex(typst);
console.log(tex_recovered);
// e \overset{\text{def}}{=} \lim_{n \rightarrow \infty} \left(1 + \frac{1}{n} \right)^n
```

## How it works
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.

```mermaid
graph LR
tex[TeX code] --parser--> tex_ast[TeX AST] --converter--> typst_ast[Typst AST] --writer--> typst[Typst code]
```
## Open-source license

- parser: Implemented in class `LatexParser`.
- converter: Implemented in function `convertTree`.
- writer: Implemented in class `TypstWriter`.
GPL v3. See [LICENSE](LICENSE) for details.

## Contributing

Expand Down

0 comments on commit 2393c20

Please sign in to comment.