Comparing version 0.0.11 to 0.0.13
@@ -1,7 +0,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.tex2typst = tex2typst; | ||
const parser_1 = require("./parser"); | ||
const writer_1 = require("./writer"); | ||
function tex2typst(tex, options) { | ||
import { parseTex } from "./parser"; | ||
import { TypstWriter } from "./writer"; | ||
export function tex2typst(tex, options) { | ||
const opt = { | ||
@@ -23,6 +20,6 @@ nonStrict: false, | ||
} | ||
const t = (0, parser_1.parseTex)(tex, opt.customTexMacros); | ||
const writer = new writer_1.TypstWriter(opt.nonStrict, opt.preferTypstIntrinsic); | ||
const t = parseTex(tex, opt.customTexMacros); | ||
const writer = new TypstWriter(opt.nonStrict, opt.preferTypstIntrinsic); | ||
writer.append(t); | ||
return writer.finalize(); | ||
} |
@@ -1,7 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.symbolMap = void 0; | ||
exports.symbolMap = new Map([ | ||
export const symbolMap = new Map([ | ||
['gets', 'arrow.l'], | ||
['infty', 'infinity'], // infinity | ||
['nonumber', ''], | ||
@@ -47,32 +43,2 @@ ['vec', 'arrow'], | ||
['boxtimes', 'times.square'], | ||
/* symbols in mathematical logic */ | ||
['neg', 'not'], | ||
['land', 'and'], | ||
['lor', 'or'], | ||
['varnothing', 'diameter'], // empty set | ||
/* symbols about comparing numbers */ | ||
// tex: \neq \leq \geq \ll \gg \prec \succ \preceq \succeq | ||
// typst: eq.not lt.eq gt.eq lt.double gt.double prec succ prec.eq succ.eq | ||
['neq', 'eq.not'], | ||
['leq', 'lt.eq'], | ||
['geq', 'gt.eq'], | ||
['ll', 'lt.double'], | ||
['gg', 'gt.double'], | ||
['prec', 'prec'], | ||
['succ', 'succ'], | ||
['preceq', 'prec.eq'], | ||
['succeq', 'succ.eq'], | ||
/* symbols about differential */ | ||
['Delta', 'Delta'], | ||
['nabla', 'nabla'], | ||
['partial', 'diff'], | ||
/* symbols about integral */ | ||
// tex: \int \oint \iint \oiint \iiint \oiiint | ||
// typst: integral integral.cont integral.double integral.surf integral.triple integral.vol | ||
['int', 'integral'], | ||
['oint', 'integral.cont'], | ||
['iint', 'integral.double'], | ||
['oiint', 'integral.surf'], | ||
['iiint', 'integral.triple'], | ||
['oiiint', 'integral.vol'], | ||
/* wave */ | ||
@@ -98,3 +64,2 @@ // tex: \sim \approx \cong \simeq \asymp \equiv \propto | ||
['rightrightarrows', 'arrows.rr'], | ||
['binom', 'binom'], | ||
/* left and right floor,ceil */ | ||
@@ -186,2 +151,3 @@ // tex: \lfloor \rfloor \lceil \rceil | ||
['in', 'in'], | ||
['infty', 'infinity'], | ||
['int', 'integral'], | ||
@@ -193,2 +159,3 @@ ['intercal', 'top'], // 'top' or 'tack.b' | ||
['lambda', 'lambda'], | ||
['land', 'and'], | ||
['langle', 'angle.l'], | ||
@@ -209,2 +176,3 @@ ['lbrace', 'brace.l'], | ||
['longrightarrow', 'arrow.long'], | ||
['lor', 'or'], | ||
['ltimes', 'times.l'], | ||
@@ -223,10 +191,21 @@ ['mapsto', 'arrow.bar'], | ||
['neq', 'eq.not'], | ||
['nexists', 'exists.not'], | ||
['ni', "in.rev"], | ||
['nleftarrow', "arrow.l.not"], | ||
['nleq', "lt.eq.not"], | ||
['nparallel', "parallel.not"], | ||
['ngeq', 'gt.eq.not'], | ||
['nmid', 'divides.not'], | ||
['notin', 'in.not'], | ||
['nleftarrow', 'arrow.l.not'], | ||
['nrightarrow', 'arrow.not'], | ||
['nsim', 'tilde.not'], | ||
['nsubseteq', 'subset.eq.not'], | ||
['nu', 'nu'], | ||
['ntriangleleft', 'lt.tri.not'], | ||
['ntriangleright', 'gt.tri.not'], | ||
['nwarrow', 'arrow.tl'], | ||
['odot', 'dot.circle'], | ||
['oint', 'integral.cont'], | ||
['oiint', 'integral.surf'], | ||
['oiiint', 'integral.vol'], | ||
['omega', 'omega'], | ||
@@ -243,2 +222,3 @@ // ['omicron', 'omicron'], | ||
['pm', 'plus.minus'], | ||
['pounds', 'pound'], | ||
['prec', 'prec'], | ||
@@ -262,5 +242,10 @@ ['preceq', 'prec.eq'], | ||
['simeq', 'tilde.eq'], | ||
['slash', 'slash'], | ||
['smallsetminus', 'without'], | ||
// ['smile', 'paren.b'], | ||
['spadesuit', 'suit.spade'], | ||
['sqcap', 'sect.sq'], | ||
['sqcup', 'union.sq'], | ||
['sqsubseteq', 'subset.eq.sq'], | ||
['sqsupseteq', 'supset.eq.sq'], | ||
['star', 'star'], | ||
@@ -276,2 +261,3 @@ ['subset', 'subset'], | ||
['supsetneq', 'supset.neq'], | ||
['swarrow', 'arrow.bl'], | ||
['tau', 'tau'], | ||
@@ -281,5 +267,8 @@ ['theta', 'theta'], | ||
['to', 'arrow.r'], | ||
['top', 'top'], | ||
['triangle', 'triangle.t'], | ||
['triangledown', 'triangle.b.small'], | ||
['triangleleft', 'triangle.l.small'], | ||
['triangleright', 'triangle.small'], | ||
['triangleright', 'triangle.r.small'], | ||
['twoheadrightarrow', 'arrow.r.twohead'], | ||
['uparrow', 'arrow.t'], | ||
@@ -291,2 +280,3 @@ ['updownarrow', 'arrow.t.b'], | ||
['varepsilon', 'epsilon'], | ||
['varnothing', 'diameter'], // empty set | ||
['varphi', 'phi'], | ||
@@ -303,3 +293,8 @@ ['varpi', 'pi.alt'], | ||
['xi', 'xi'], | ||
['yen', 'yen'], | ||
['zeta', 'zeta'], | ||
// extended | ||
['mathscr', 'scr'], | ||
['LaTeX', '#LaTeX'], | ||
['TeX', '#TeX'], | ||
]); |
@@ -1,13 +0,5 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.KatexNodeToTexNodeError = void 0; | ||
exports.katexNodeToTexNode = katexNodeToTexNode; | ||
exports.parseTex = parseTex; | ||
// @ts-ignore | ||
const katex_1 = __importDefault(require("katex")); | ||
const generateParseTree = katex_1.default.__parse; | ||
class KatexNodeToTexNodeError extends Error { | ||
import katex from 'katex'; | ||
const generateParseTree = katex.__parse; | ||
export class KatexNodeToTexNodeError extends Error { | ||
constructor(message, node) { | ||
@@ -19,4 +11,3 @@ super(message); | ||
} | ||
exports.KatexNodeToTexNodeError = KatexNodeToTexNodeError; | ||
function katexNodeToTexNode(node) { | ||
export function katexNodeToTexNode(node) { | ||
try { | ||
@@ -246,7 +237,7 @@ if (node.loc) { | ||
} | ||
function parseTex(tex, customTexMacros) { | ||
export function parseTex(tex, customTexMacros) { | ||
// displayMode=true. Otherwise, "KaTeX parse error: {align*} can be used only in display mode." | ||
const macros = Object.assign({ | ||
// KaTeX parse these commands so complicatedly that we need some hacks to keep things simple. | ||
'\\mod': '\\operatorname{SyMb01-mod}', '\\liminf': '\\operatorname{SyMb01-liminf}', '\\limsup': '\\operatorname{SyMb01-limsup}', '\\qquad': '\\operatorname{SyMb01-qquad}', '\\quad': '\\operatorname{SyMb01-quad}', '\\cdots': '\\operatorname{SyMb01-cdots}', '\\colon': '\\operatorname{SyMb01-colon}', '\\imath': '\\operatorname{SyMb01-imath}', '\\\iiiint': '\\operatorname{SyMb01-iiiint}', '\\jmath': '\\operatorname{SyMb01-jmath}', '\\vdots': '\\operatorname{SyMb01-vdots}', '\\notin': '\\operatorname{SyMb01-notin}' }, customTexMacros); | ||
'\\mod': '\\operatorname{SyMb01-mod}', '\\liminf': '\\operatorname{SyMb01-liminf}', '\\limsup': '\\operatorname{SyMb01-limsup}', '\\qquad': '\\operatorname{SyMb01-qquad}', '\\quad': '\\operatorname{SyMb01-quad}', '\\cdots': '\\operatorname{SyMb01-cdots}', '\\colon': '\\operatorname{SyMb01-colon}', '\\imath': '\\operatorname{SyMb01-imath}', '\\\iiiint': '\\operatorname{SyMb01-iiiint}', '\\jmath': '\\operatorname{SyMb01-jmath}', '\\vdots': '\\operatorname{SyMb01-vdots}', '\\notin': '\\operatorname{SyMb01-notin}', '\\slash': '\\operatorname{SyMb01-slash}', '\\LaTeX': '\\operatorname{SyMb01-LaTeX}', '\\TeX': '\\operatorname{SyMb01-TeX}' }, customTexMacros); | ||
const options = { | ||
@@ -253,0 +244,0 @@ macros: macros, |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
export {}; |
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TypstWriter = exports.TypstWriterError = void 0; | ||
const map_1 = require("./map"); | ||
import { symbolMap } from "./map"; | ||
// symbols that are supported by Typst but not by KaTeX | ||
@@ -16,3 +13,3 @@ const TYPST_INTRINSIC_SYMBOLS = [ | ||
]; | ||
class TypstWriterError extends Error { | ||
export class TypstWriterError extends Error { | ||
constructor(message, node) { | ||
@@ -24,4 +21,3 @@ super(message); | ||
} | ||
exports.TypstWriterError = TypstWriterError; | ||
class TypstWriter { | ||
export class TypstWriter { | ||
constructor(nonStrict, preferTypstIntrinsic) { | ||
@@ -318,3 +314,2 @@ this.buffer = ""; | ||
} | ||
exports.TypstWriter = TypstWriter; | ||
function convertToken(token) { | ||
@@ -327,6 +322,9 @@ if (/^[a-zA-Z0-9]$/.test(token)) { | ||
} | ||
else if (['\\$', '\\#', '\\&', '\\_'].includes(token)) { | ||
return token; | ||
} | ||
else if (token.startsWith('\\')) { | ||
const symbol = token.slice(1); | ||
if (map_1.symbolMap.has(symbol)) { | ||
return map_1.symbolMap.get(symbol); | ||
if (symbolMap.has(symbol)) { | ||
return symbolMap.get(symbol); | ||
} | ||
@@ -333,0 +331,0 @@ else { |
{ | ||
"name": "tex2typst", | ||
"version": "0.0.11", | ||
"version": "0.0.13", | ||
"description": "JavaScript library for converting TeX code to Typst", | ||
"type": "module", | ||
"main": "dist/index.js", | ||
@@ -6,0 +7,0 @@ "types": "dist/index.d.ts", |
export const symbolMap = new Map<string, string>([ | ||
['gets', 'arrow.l'], | ||
['infty', 'infinity'], // infinity | ||
['nonumber', ''], | ||
@@ -49,37 +48,3 @@ ['vec', 'arrow'], | ||
/* symbols in mathematical logic */ | ||
['neg', 'not'], | ||
['land', 'and'], | ||
['lor', 'or'], | ||
['varnothing', 'diameter'], // empty set | ||
/* symbols about comparing numbers */ | ||
// tex: \neq \leq \geq \ll \gg \prec \succ \preceq \succeq | ||
// typst: eq.not lt.eq gt.eq lt.double gt.double prec succ prec.eq succ.eq | ||
['neq', 'eq.not'], | ||
['leq', 'lt.eq'], | ||
['geq', 'gt.eq'], | ||
['ll', 'lt.double'], | ||
['gg', 'gt.double'], | ||
['prec', 'prec'], | ||
['succ', 'succ'], | ||
['preceq', 'prec.eq'], | ||
['succeq', 'succ.eq'], | ||
/* symbols about differential */ | ||
['Delta', 'Delta'], | ||
['nabla', 'nabla'], | ||
['partial', 'diff'], | ||
/* symbols about integral */ | ||
// tex: \int \oint \iint \oiint \iiint \oiiint | ||
// typst: integral integral.cont integral.double integral.surf integral.triple integral.vol | ||
['int', 'integral'], | ||
['oint', 'integral.cont'], | ||
['iint', 'integral.double'], | ||
['oiint', 'integral.surf'], | ||
['iiint', 'integral.triple'], | ||
['oiiint', 'integral.vol'], | ||
/* wave */ | ||
@@ -107,3 +72,2 @@ // tex: \sim \approx \cong \simeq \asymp \equiv \propto | ||
['binom', 'binom'], | ||
@@ -198,2 +162,3 @@ /* left and right floor,ceil */ | ||
['in', 'in'], | ||
['infty', 'infinity'], | ||
['int', 'integral'], | ||
@@ -205,2 +170,3 @@ ['intercal', 'top'], // 'top' or 'tack.b' | ||
['lambda', 'lambda'], | ||
['land', 'and'], | ||
['langle', 'angle.l'], | ||
@@ -221,2 +187,3 @@ ['lbrace', 'brace.l'], | ||
['longrightarrow', 'arrow.long'], | ||
['lor', 'or'], | ||
['ltimes', 'times.l'], | ||
@@ -235,10 +202,21 @@ ['mapsto', 'arrow.bar'], | ||
['neq', 'eq.not'], | ||
['nexists', 'exists.not'], | ||
['ni', "in.rev"], | ||
['nleftarrow', "arrow.l.not"], | ||
['nleq', "lt.eq.not"], | ||
['nparallel', "parallel.not"], | ||
['ngeq', 'gt.eq.not'], | ||
['nmid', 'divides.not'], | ||
['notin', 'in.not'], | ||
['nleftarrow', 'arrow.l.not'], | ||
['nrightarrow', 'arrow.not'], | ||
['nsim', 'tilde.not'], | ||
['nsubseteq', 'subset.eq.not'], | ||
['nu', 'nu'], | ||
['ntriangleleft', 'lt.tri.not'], | ||
['ntriangleright', 'gt.tri.not'], | ||
['nwarrow', 'arrow.tl'], | ||
['odot', 'dot.circle'], | ||
['oint', 'integral.cont'], | ||
['oiint', 'integral.surf'], | ||
['oiiint', 'integral.vol'], | ||
['omega', 'omega'], | ||
@@ -255,2 +233,3 @@ // ['omicron', 'omicron'], | ||
['pm', 'plus.minus'], | ||
['pounds', 'pound'], | ||
['prec', 'prec'], | ||
@@ -274,5 +253,10 @@ ['preceq', 'prec.eq'], | ||
['simeq', 'tilde.eq'], | ||
['slash', 'slash'], | ||
['smallsetminus', 'without'], | ||
// ['smile', 'paren.b'], | ||
['spadesuit', 'suit.spade'], | ||
['sqcap', 'sect.sq'], | ||
['sqcup', 'union.sq'], | ||
['sqsubseteq', 'subset.eq.sq'], | ||
['sqsupseteq', 'supset.eq.sq'], | ||
['star', 'star'], | ||
@@ -288,2 +272,3 @@ ['subset', 'subset'], | ||
['supsetneq', 'supset.neq'], | ||
['swarrow', 'arrow.bl'], | ||
['tau', 'tau'], | ||
@@ -293,5 +278,8 @@ ['theta', 'theta'], | ||
['to', 'arrow.r'], | ||
['top', 'top'], | ||
['triangle', 'triangle.t'], | ||
['triangledown', 'triangle.b.small'], | ||
['triangleleft', 'triangle.l.small'], | ||
['triangleright', 'triangle.small'], | ||
['triangleright', 'triangle.r.small'], | ||
['twoheadrightarrow', 'arrow.r.twohead'], | ||
['uparrow', 'arrow.t'], | ||
@@ -303,2 +291,3 @@ ['updownarrow', 'arrow.t.b'], | ||
['varepsilon', 'epsilon'], | ||
['varnothing', 'diameter'], // empty set | ||
['varphi', 'phi'], | ||
@@ -315,3 +304,9 @@ ['varpi', 'pi.alt'], | ||
['xi', 'xi'], | ||
['yen', 'yen'], | ||
['zeta', 'zeta'], | ||
// extended | ||
['mathscr', 'scr'], | ||
['LaTeX', '#LaTeX'], | ||
['TeX', '#TeX'], | ||
]); |
@@ -256,2 +256,5 @@ // @ts-ignore | ||
'\\notin': '\\operatorname{SyMb01-notin}', | ||
'\\slash': '\\operatorname{SyMb01-slash}', | ||
'\\LaTeX': '\\operatorname{SyMb01-LaTeX}', | ||
'\\TeX': '\\operatorname{SyMb01-TeX}', | ||
...customTexMacros | ||
@@ -258,0 +261,0 @@ }; |
@@ -325,2 +325,4 @@ import { symbolMap } from "./map"; | ||
return '\\\n'; | ||
} else if (['\\$', '\\#', '\\&', '\\_'].includes(token)) { | ||
return token; | ||
} else if (token.startsWith('\\')) { | ||
@@ -327,0 +329,0 @@ const symbol = token.slice(1); |
@@ -28,3 +28,3 @@ { | ||
/* Modules */ | ||
"module": "commonjs", /* Specify what module code is generated. */ | ||
"module": "esnext", /* Specify what module code is generated. */ | ||
// "rootDir": "./", /* Specify the root folder within your source files. */ | ||
@@ -31,0 +31,0 @@ // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ |
Unpublished package
Supply chain riskPackage version was not found on the registry. It may exist on a different registry and need to be configured to pull from that registry.
Found 1 instance in 1 package
Unpopular package
QualityThis package is not very popular.
Found 1 instance in 1 package
20
0
Yes
86221
2001
1