import { tex2typst, typst2tex } from 'tex2typst';
let tex = "e \overset{\text{def}}{=} \lim_{{n \to \infty}} \left(1 + \frac{1}{n}\right)^n";
let typst = tex2typst(tex);
console.log(typst);
// e eq.def lim_(n -> infinity)(1 + 1/n)^n
let tex_recovered = typst2tex(typst);
console.log(tex_recovered);
// e \overset{\text{def}}{=} \lim_{n \rightarrow \infty} \left(1 + \frac{1}{n} \right)^n
tex2typst
function accepts an optional second argument, which is an object containing options to customize the conversion.
interface Tex2TypstOptions {
preferShorthands?: boolean;
fracToSlash?: boolean;
inftyToOo?: boolean;
}
preferShorthands
: If set totrue
, the function will prefer using shorthands in Typst (e.g.,->
instead ofarrow.r
,<<
instead oflt.double
) when converting TeX to Typst. Default isture
.
let tex = "a \\rightarrow b \\ll c";
let typst1 = tex2typst(tex, { preferShorthands: false });
console.log(typst1);
// a arrow.r b lt.double c
let typst2 = tex2typst(tex, { preferShorthands: true });
console.log(typst2);
// a -> b << c
fracToSlash
: If set totrue
, the Typst result will use the slash notation for fractions. Default istrue
.
let tex = "\\frac{a}{b}";
let tpyst1 = tex2typst(tex, { fracToSlash: false });
console.log(typst1);
// frac(a, b)
let typst2 = tex2typst(tex, { fracToSlash: true });
console.log(typst2);
// a / b
inftyToOo
: If set totrue
,\\infty
converts tooo
instead ofinfinity
. Default isfalse
.
let tex = "\\infty";
let typst1 = tex2typst(tex, { inftyToOo: false });
console.log(typst1);
// infinity
let typst2 = tex2typst(tex, { inftyToOo: true });
console.log(typst2);
// oo