diff --git a/package.json b/package.json index bf44c3e..10823cb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tex2typst", - "version": "0.0.16", + "version": "0.0.17", "description": "JavaScript library for converting TeX code to Typst", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/parser.ts b/src/parser.ts index 1039844..0f65a75 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -101,10 +101,11 @@ export function katexNodeToTexNode(node: KatexParseNode): TexNode { if (right === "\\}") { right = "}"; } + const is_atom = (str:string) => (['(', ')', '[', ']', '{', '}'].includes(str)); res.args = [ - { type: 'atom', content: left }, + { type: is_atom(left)? 'atom': 'symbol', content: left }, body, - { type: 'atom', content: right} + { type: is_atom(right)? 'atom': 'symbol', content: right} ]; break; } diff --git a/src/writer.ts b/src/writer.ts index 7a094ef..b9eff47 100644 --- a/src/writer.ts +++ b/src/writer.ts @@ -132,7 +132,7 @@ export class TypstWriter { } else if (node.type === 'leftright') { const [left, body, right] = node.args!; // These pairs will be handled by Typst compiler by default. No need to add lr() - if (["[]", "()", "{}"].includes(left.content + right.content)) { + if (["[]", "()", "{}", "\\lfloor\\rfloor", "\\lceil\\rceil"].includes(left.content + right.content)) { this.append(left); this.append(body); this.append(right); diff --git a/test/symbol.yml b/test/symbol.yml index 3965483..fa9324a 100644 --- a/test/symbol.yml +++ b/test/symbol.yml @@ -79,14 +79,14 @@ cases: tex: \binom{n}{k} typst: binom(n, k) - title: unpaired left and right floor, ceil 1 - tex: \lfloor \rceil - typst: ⌊ ⌉ + tex: \lfloor \rceil \left \lfloor \frac{1}{2} \right \rceil + typst: ⌊ ⌉ lr(⌊ frac(1, 2) ⌉) - title: unpaired left and right floor,ceil 2 - tex: \rfloor \lceil - typst: ⌋ ⌈ + tex: \rfloor \lceil \left\lceil \frac{1}{2} \right \rfloor + typst: ⌋ ⌈ lr(⌈ frac(1, 2) ⌋) - title: paired left and right floor,ceil - tex: \lfloor x \rfloor \lceil x \rceil - typst: floor(x) ceil(x) + tex: \lfloor x \rfloor \lceil x \rceil \left\lceil \frac{1}{2} \right \rceil + typst: floor(x) ceil(x) ceil(frac(1, 2)) - title: trigonometric functions tex: \sin \cos \tan \cot \sec \csc typst: sin cos tan cot sec csc