Skip to content

Commit

Permalink
docs: add preamble docs and move the internal docs to CONTRIBUTING.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Myriad-Dreamin committed Jan 18, 2025
1 parent 5fc83b6 commit e8480ab
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 22 deletions.
24 changes: 24 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# Contributing to MiTeX

Currently, MiTeX maintains following three parts of code:

- A TeX parser library written in **Rust**, see [mitex-lexer](https://github.com/mitex-rs/mitex/tree/main/crates/mitex-lexer) and [mitex-parser](https://github.com/mitex-rs/mitex/tree/main/crates/mitex-parser).
- A TeX to Typst converter library written in **Rust**, see [mitex](https://github.com/mitex-rs/mitex/tree/main/crates/mitex).
- A list of TeX packages and commands written in **Typst**, which then used by the typst package, see [MiTeX Command Specification](https://github.com/mitex-rs/mitex/tree/main/packages/mitex/specs).

For a translation process, for example, we have:

```
\frac{1}{2}
===[parser]===> AST ===[converter]===>
#eval("$frac(1, 2)$", scope: (frac: (num, den) => $(num)/(den)$))
```

You can use the `#mitex-convert()` function to get the Typst Code generated from LaTeX Code.

### Adding missing TeX commands

Even if you don't know Rust at all, you can still add missing TeX commands to MiTeX by modifying [specification files](https://github.com/mitex-rs/mitex/tree/main/packages/mitex/specs), since they are written in typst! You can open an issue to acquire the commands you want to add, or you can edit the files and submit a pull request.

In the future, we will provide the ability to customize TeX commands, which will make it easier for you to use the commands you create for yourself.

## Installing Dependencies

You should install [Typst](https://github.com/typst/typst?tab=readme-ov-file#installation) and [Rust](https://www.rust-lang.org/tools/install) for running the build script.
Expand Down
47 changes: 25 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,36 +118,39 @@ Another example is that MiTeX transforms `(\frac{1}{2})` into `\(frac(1, 2)\)` i

**Certainly, the greatest advantage is that you can directly write LaTeX content in Typst without the need for manual conversion!**

## Submitting Issues

If you find missing commands or bugs of MiTeX, please feel free to submit an issue [here](https://github.com/mitex-rs/mitex/issues).

## Contributing to MiTeX
### Adding customized commands

Currently, MiTeX maintains following three parts of code:
There are two kinds of commands to add:

- A TeX parser library written in **Rust**, see [mitex-lexer](https://github.com/mitex-rs/mitex/tree/main/crates/mitex-lexer) and [mitex-parser](https://github.com/mitex-rs/mitex/tree/main/crates/mitex-parser).
- A TeX to Typst converter library written in **Rust**, see [mitex](https://github.com/mitex-rs/mitex/tree/main/crates/mitex).
- A list of TeX packages and commands written in **Typst**, which then used by the typst package, see [MiTeX Command Specification](https://github.com/mitex-rs/mitex/tree/main/packages/mitex/specs).
- **Commonly used commands**: If you find there are some builtin or commonly used commands missing in MiTeX, you can submit an issue or contribute them according to [Adding missing TeX commands.](./CONTRIBUTING.md#adding-missing-tex-commands)

For a translation process, for example, we have:
- **Special commands (Preambles)**: If you want to add some special commands (preambles) for your own use, you can define them by `\newcommand` or `\newenvironment` and override the mitex function in your. Example:

```
\frac{1}{2}
````typ
#let preamble = ```tex
\newcommand{\f}[2]{#1f(#2)}
```
===[parser]===> AST ===[converter]===>
#let mitex = (it, ..args) => mitex.with(..args)({
(preamble, it).map(it => it.text).join("\n")
})
````

#eval("$frac(1, 2)$", scope: (frac: (num, den) => $(num)/(den)$))
```
And use them in your Typst code:

You can use the `#mitex-convert()` function to get the Typst Code generated from LaTeX Code.

### Add missing TeX commands
````typ
#show raw.where(lang: "mitex"): mitex
```mitex
\f\relax{x} = \int_{-\infty}^\infty
\f\hat\xi\,e^{2 \pi i \xi x}
\,d\xi
```
````

Even if you don't know Rust at all, you can still add missing TeX commands to MiTeX by modifying [specification files](https://github.com/mitex-rs/mitex/tree/main/packages/mitex/specs), since they are written in typst! You can open an issue to acquire the commands you want to add, or you can edit the files and submit a pull request.
## Submitting Issues

In the future, we will provide the ability to customize TeX commands, which will make it easier for you to use the commands you create for yourself.
If you find missing commands or bugs of MiTeX, please feel free to submit an issue [here](https://github.com/mitex-rs/mitex/issues).

### Develop the parser and the converter
## Contributing

See [CONTRIBUTING.md](https://github.com/mitex-rs/mitex/blob/main/CONTRIBUTING.md).
See [CONTRIBUTING.md](./CONTRIBUTING.md).
15 changes: 15 additions & 0 deletions packages/mitex/examples/preamble.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#import "../lib.typ": *

#let preamble = ```tex
\newcommand{\f}[2]{#1f(#2)}
```
#let mitex = (it, ..args) => mitex.with(..args)({
(preamble, it).map(it => it.text).join("\n")
})
#mitex(```latex
\f\relax{x} = \int_{-\infty}^\infty
\f\hat\xi\,e^{2 \pi i \xi x}
\,d\xi
```)

0 comments on commit e8480ab

Please sign in to comment.