mitex README

The project's README from github.com/mitex-rs/mitex. As one markdown file: README.md.

MiTeX

LaTeX support for Typst, powered by Rust and WASM.

MiTeX processes LaTeX code into an abstract syntax tree (AST). Then it transforms the AST into Typst code and evaluates code into Typst content by eval function.

MiTeX has been proved to be practical on a large project. It has already correctly converted 32.5k equations from OI Wiki. Compared to texmath, MiTeX has a better display effect and performance in that wiki project. It is also more easy to use, since importing MiTeX to Typst is just one line of code, while texmath is an external program.

In addition, MiTeX is not only SMALL but also FAST! MiTeX has a size of just about 185 KB, comparing that texmath has a size of 17 MB. A not strict but intuitive comparison is shown below. To convert 32.5k equations from OI Wiki, texmath takes about 109s, while MiTeX WASM takes only 2.28s and MiTeX x86 takes merely 0.085s.

Thanks to @Myriad-Dreamin, he completed the most complex development work: developing the parser for generating AST.

MiTeX as a Typst Package

PS: #set math.equation(numbering: "(1)") is also valid for MiTeX.

Following is a simple example of using MiTeX in Typst:

#import "@preview/mitex:0.2.7": *

Write inline equations like #mi(`x`).

Also block equations (this case is from #text(blue.lighten(20%), link("https://katex.org/")[katex.org])):

#mitex(`
  \newcommand{\f}[2]{#1f(#2)}
  \f\relax{x} = \int_{-\infty}^\infty
    \f\hat\xi\,e^{2 \pi i \xi x}
    \,d\xi
`)

We also support text mode (in development):

#mitext(`
  \iftypst
    #set math.equation(numbering: "(1)", supplement: "equation")
  \fi

  \section{Title}

  A \textbf{strong} text, a \emph{emph} text and inline equation $x + y$.

  Also block \eqref{eq:pythagoras}.

  \begin{equation}
    a^2 + b^2 = c^2 \label{eq:pythagoras}
  \end{equation}
`)

MiTeX example showing LaTeX equations rendered in Typst

MiTeX as a CLI Tool

Installation

Install the latest nightly version by cargo install --git https://github.com/mitex-rs/mitex mitex-cli.

Usage

mitex compile main.tex
# or (same as above)
mitex compile main.tex mitex.typ

MiTeX as a Web App

MiTeX Online Math Converter

We can convert LaTeX equations to Typst equations in web by wasm. https://mitex-rs.github.io/mitex/

Underleaf

We made a proof of concept online tex editor to show our conversion speed in text mode. The PoC loads files from a git repository and then runs typst compile in browser. As you see, each keystroking get response in preview quickly.

https://mitex-rs.github.io/mitex/tools/underleaf.html

https://github.com/mitex-rs/mitex/assets/34951714/0ce77a2c-0a7d-445f-b26d-e139f3038f83

Implemented Features

Features to Implement

To achieve the latter two goals, we need a well-structured architecture for the text mode, along with intricate work. Currently, we don't have very clear ideas yet. If you are willing to contribute by discussing in the issues or even submitting pull requests, your contribution is highly welcome.

Differences between MiTeX and other solutions

MiTeX has different objectives compared to texmath (a.k.a. pandoc):

For example, MiTeX transforms \frac{1}{2}_3 into frac(1, 2)_3, while texmath converts it into 1 / 2_3. The latter's display is not entirely correct, whereas the former ensures consistency in display.

Another example is that MiTeX transforms (\frac{1}{2}) into \(frac(1, 2)\) instead of (frac(1, 2)), avoiding the use of automatic Left/Right to achieve consistency with LaTeX rendering.

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

Adding new commands

There are two kinds of commands to add:

Submitting Issues

If you find missing commands or bugs of MiTeX, please feel free to submit an issue here.

Contributing

See CONTRIBUTING.md.

mitex (mitex-rs/mitex)

Searching Database…

634 ·GitHub
这是做什么的?MiTeX 为 Typst 带来 LaTeX 支持:它把 LaTeX 解析成抽象语法树,转换成 Typst 代码,再求值成 Typst 内容,这样你就可以直接在 Typst 文档里写 LaTeX 数学公式。
它是 Typst 包、命令行工具,还是网站?三种都是。它既是一个在 .typ 文件里导入的 Typst 包,也是一个叫 mitex-cli 的命令行工具,还是一个基于 WASM 的网页应用,可以直接在浏览器里转换公式。
在 Typst 文档里怎么用?先导入这个包,然后把 LaTeX 代码包起来:mi 用于行内公式,mitex(...) 或 mimath 用于块级公式,mitext 用于 LaTeX 文本,mitex-convert 会把转换后的 Typst 代码以字符串形式返回。
用它的前需要装 Rust 或其他东西吗?只有命令行工具需要 Rust 工具链,通过 cargo install --git mitex-cli 安装。Typst 包通过 WASM 在 Typst 内部运行,网页应用更是只需要一个浏览器。
它到底支持多少 LaTeX?数学部分覆盖得不错:公式、aligned/matrix/cases 环境、颜色命令、\ref 和 \label,以及用户自定义的 \newcommand 宏。文本模式还只是初级的草稿级支持,像 algorithm 这样的环境也尚未实现。
和 texmath 相比,它有多快、多小?MiTeX 大约 185 KB,而 texmath 有 17 MB。把 OI Wiki 的 32.5k 个公式转换一遍,MiTeX 的 WASM 版本用了 2.28 秒,本地 x86 编译版只要 0.085 秒,而 texmath 大约需要 109 秒。
后续还计划做哪些功能?支持动态地向插件传入命令规范、提供包支持以便更换命令集,以及更完善的文本模式,包括 figure、algorithm 和 description 环境。
Creator
mitex-rs
Size
1 MB
Stars
634
Age
2y
Commits · 90 Days