Skip to content

Commit

Permalink
fix floor and ceil when wrapped with \left,\rifht
Browse files Browse the repository at this point in the history
  • Loading branch information
qwinsi committed Aug 17, 2024
1 parent 8669574 commit cf1d924
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 3 additions & 2 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions test/symbol.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cf1d924

Please sign in to comment.