A tool that converts typst markup to an equivalent LaTeX code.
Project description
typsytex
typsytex is a tool that converts typst markup to an equivalent LaTeX code. It's intended for
smallish text fragments and only handles syntax, no scripting or command definitions.
Typst is a document typesetting system, an attempt to create a new generation LaTeX.
One of its features is a much less noisy syntax.
typsytex is a tool that replaces all syntax sugar
from typst-formatted documents by their LaTeX equivalents.
This is a very dumb tool, a bunch of regular expressions with some glue code. It only works for properly indented documents with no unbalanced brackets. It's very easy to write a valid typst document that will be converted to a broken LaTeX code if you try.
Showcase
Converts this:
= Section name <sec:section_label>
Here is a *very important* result:
#theorem[
The following two objects are both zero:
- $binom(4, 2) dot 3 - dim(ker(CC^(18) ->^("zero") CC))$;
- $mat(1, 0; 0, 1) - mat(1, cal(F) \/ cal(F); 0, 1)$
] <thm:main_theorem>
To prove theorem~@thm:main_theorem we need the vanishing of
$ QQ times.circle ZZ \/ n ZZ = 0, $ <eq:torsion_and_divisible>
which we discussed last time. Recall the morphism
$ f: x arrow.bar 2x $
used above.
To this:
\section{Section name}
\label{sec:section_label}
Here is a \textbf{very important} result:
\begin{theorem}
\label{thm:main_theorem}
The following two objects are both zero:
\begin{itemize}
\item $\binom{4}{2} \cdot 3 - \dim(\ker(\CC^{18} \xrightarrow{\mathrm{zero}} \CC))$;
\item $\left(\begin{matrix} 1 & 0 \\ 0 & 1 \end{matrix}\right) - \left(\begin{matrix} 1 & \mathcal{F} / \mathcal{F} \\ 0 & 1 \end{matrix}\right)$
\end{itemize}
\end{theorem}
To prove theorem~\ref{thm:main_theorem} we need the vanishing of
\begin{equation}
\label{eq:torsion_and_divisible}
\QQ \otimes \ZZ / n \ZZ = 0,
\end{equation}
which we discussed last time. Recall the morphism
\[ f\colon x \mapsto 2x \]
used above.
Usage
Install
Locally: just download the typsytex.py file from this repository and make it executable.
Globally: run pip3 install typsytex, then use typsytex command.
Converting files
Run
typsytex typst_source.typ latex_output.tex
to convert the
contents of typst_source.typ and save the LaTeX code to latex_output.tex file. Run without arguments to read from stdin
and output to stdout.
For more details, run typsytex -h.
Supported features
- Markdown-style formatting: the
*bold*and_italic_text is replaced with\textbfand\textit. Also deals with= Sectionand== Subsection, handles labeled (sub)sections. - Lists: typst-style lists (
- first item (line break) - second item (line break)) are converted to\begin{itemize}etc. Only works for correctly indented lists. Also works for the automatically numbered lists (the ones where items start with+, not markdown-style with numbers). - Environments: converts fragments like
#theorem[
Contents
] <thm:main_theorem>
to LaTeX-style
\begin{theorem}
\label{thm:main_theorem}
Contents
\end{theorem}
Only works for correctly indented multiline environments. Environments with arguments, like #theorem(argument)[...] are kind of supported, but not automatically, you'll need to modify typsytex source code to handle them properly.
- References: replaces
@thm:main_theoremwith\ref{thm:main_theorem}. If a bibliography file is specified in the text or as a command-line argument, switches to\citewhen necessary. - Comments: converts
// commentinto% comment. (Beware: typst code in the commented lines will mostly be translated to LaTeX anyway.) - Math mode: display equations: convert
$ equation $into\[ equation \]. Handles display equations with labels, detects whether alignment operators are used and converts them accordingly. - Math mode: braces for sup/sub: converts typst-style
x^(n+1)intox^{n+1}expected by LaTeX. - Math mode: quoted to mathrm: converts
x + "something" + yintox + \mathrm{something} + y. - Math mode: command translation: converts functions calling from typst math mode to their LaTeX equivalents:
Psi + binom(3, 2) in union.big U_iis transformed into\Psi + \binom{3}{2} \in \bigcup U_i. Unknown commands are translated by adding backslashes. Other custom translations can be specified using--math-commands-listcommand line argument. - Math mode: magic symbols to commands: detects the use of things like
->,>>and converts them to\to,\gg, respectively. Converts->^(a)into\xrightarrow{a}.
Unsupported features
The following features are NOT supported:
- anything involving scripting, definition of new commands, etc.
- the math mode slash transforming into
\frac(too difficult to determine the numerator and denumerator properly) - typst-conforming subscript precedence order:
f_a(1)in Typst is equivalent tof_(a(1))instead off_(a)(1)even whenais not a command accepting arguments, unlike LaTeX.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file typsytex-1.0.1.tar.gz.
File metadata
- Download URL: typsytex-1.0.1.tar.gz
- Upload date:
- Size: 55.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59201a0bafc236eb0288e053a07f9bf50b03e4056aea6cb9eb6524ca770b944e
|
|
| MD5 |
511643d4dccb5140e3ac7231888ed196
|
|
| BLAKE2b-256 |
46deec745291d9efabac1d1b593b8c1261ad0cfc4fd5071ddaa1e879a1c27baa
|
File details
Details for the file typsytex-1.0.1-py3-none-any.whl.
File metadata
- Download URL: typsytex-1.0.1-py3-none-any.whl
- Upload date:
- Size: 42.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a879030219f1787ecf8d31fa99be27b6f4f95bca118fc0a32bb470911806987c
|
|
| MD5 |
b33b024ebde564e95699409d20948af0
|
|
| BLAKE2b-256 |
c51bf482c97bbce98feb1bf790b52c8b7dbcecf9ade451c1f405798d27cb65dc
|