27 points · by democat · 10mo ago · 9 comments
I built Tylax because I wanted to migrate my old LaTeX papers to Typst but found existing regex-based scripts too fragile for nested environments.
Tylax parses LaTeX into an AST (using mitex-parser) and converts it to Typst code. It supports: - Full document structure (not just math snippets) - Complex math (matrices, integrals) - Experimental TikZ -> CeTZ graphics conversion - Runs in browser via WASM
Repo: https://github.com/scipenai/tylax Web Demo: https://convert.silkyai.cn/
Happy to answer any questions!
\newcommand{\foo}[1]{\bar{#1}} \renewcommand{\bar}[1]{\foo{#1}} % mutual recursion \foo{x} \def\x{\y}\def\y{z}\x % chained expansion
+>
#set page(paper: "a4") #set heading(numbering: "1.") #set math.equation(numbering: "(1)") /* \foo / / \y /
\foo{x} → \bar{x} → \foo{x} → ∞ Expected: hit depth limit, emit warning, output either x or the unexpanded \foo{x} Actual: /
\foo */ — silently converted to a comment, lost the argument x entirelyI've traced the issue in the codebase: 1. The recursion depth limit *is* triggering correctly (preventing an infinite loop). 2. However, when it bails out, it returns the partially expanded macro call (e.g., `\foo{x}`). 3. Since the macro definition was removed during the preprocessing step, the parser then sees `\foo` as an unknown command and converts it into an error comment, accidentally discarding the argument `{x}` in the process.
*The intended behavior* should definitely be to preserve the content (the `x`) even if the macro logic fails. I will fix the fallback logic to ensure it fails gracefully without eating the arguments.
Thanks again for the sharp eye! These kinds of checks are super helpful.
\newcommand{\pair}[2]{\langle #1, #2\rangle}
$$\pair{a^2}{\frac{\pi}{2}}$$
pandoc will give you the Typst $ chevron.l a^2 \, pi / 2 chevron.r $
which is correct. Tylax, on the other hand, seems to have problems with this example, producing $ angle.l^()frac(pi,)angle.r $
which does not compile with typst. Going the other direction, pandoc also understands typst scripting. For example, from #let count = 8
#let nums = range(1, count + 1)
#let fib(n) = (
if n <= 2 { 1 }
else { fib(n - 1) + fib(n - 2) }
)
The first #count numbers of the sequence are:
#align(center, table(
columns: count,
..nums.map(n => $F_#n$),
..nums.map(n => str(fib(n))),
))
pandoc produces this LaTeX: The first 8 numbers of the sequence are:
{\def\LTcaptype{none} % do not increment counter
\begin{longtable}[]{@{}llllllll@{}}
\toprule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
\(F_{1}\) & \(F_{2}\) & \(F_{3}\) & \(F_{4}\) & \(F_{5}\) & \(F_{6}\) &
\(F_{7}\) & \(F_{8}\) \\
1 & 1 & 2 & 3 & 5 & 8 & 13 & 21 \\
\end{longtable}
}
With the same input, Tylax produces: The first 8 numbers of the sequence are:
\begin{center}
\begin{tabular}{|c|}
\hline
\hline
\end{tabular}\end{center}
which is just an empty table.This is not to say that pandoc isn’t a fantastic tool.