Skip to main content

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 \textbf and \textit. Also deals with = Section and == 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_theorem with \ref{thm:main_theorem}. If a bibliography file is specified in the text or as a command-line argument, switches to \cite when necessary.
  • Comments: converts // comment into % 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) into x^{n+1} expected by LaTeX.
  • Math mode: quoted to mathrm: converts x + "something" + y into x + \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_i is 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-list command 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 to f_(a(1)) instead of f_(a)(1) even when a is not a command accepting arguments, unlike LaTeX.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

typsytex-1.0.1.tar.gz (55.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

typsytex-1.0.1-py3-none-any.whl (42.6 kB view details)

Uploaded Python 3

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

Hashes for typsytex-1.0.1.tar.gz
Algorithm Hash digest
SHA256 59201a0bafc236eb0288e053a07f9bf50b03e4056aea6cb9eb6524ca770b944e
MD5 511643d4dccb5140e3ac7231888ed196
BLAKE2b-256 46deec745291d9efabac1d1b593b8c1261ad0cfc4fd5071ddaa1e879a1c27baa

See more details on using hashes here.

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

Hashes for typsytex-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a879030219f1787ecf8d31fa99be27b6f4f95bca118fc0a32bb470911806987c
MD5 b33b024ebde564e95699409d20948af0
BLAKE2b-256 c51bf482c97bbce98feb1bf790b52c8b7dbcecf9ade451c1f405798d27cb65dc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page