Skip to content

Commit

Permalink
improve logic for \\operatorname
Browse files Browse the repository at this point in the history
  • Loading branch information
qwinsi committed Sep 8, 2024
1 parent 8028e91 commit 4ac14df
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ export function tokenize(latex: string): Token[] {

tokens.push(token);

if (token.type === TokenType.COMMAND && ['\\text', '\\begin', '\\end'].includes(token.value)) {
if (token.type === TokenType.COMMAND && ['\\text', '\\operatorname', '\\begin', '\\end'].includes(token.value)) {
if (pos >= latex.length || latex[pos] !== '{') {
throw new LatexParserError(`No content for ${token.value} command`);
}
Expand Down
11 changes: 3 additions & 8 deletions src/writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,10 @@ export class TypstWriter {
// Fall through
} else if (node.content === '\\operatorname') {
let body = node.args!;
if (body.length === 1 && body[0].type == 'ordgroup') {
body = body[0].args!;
if (body.length !== 1 || body[0].type !== 'text') {
throw new TypstWriterError(`Expecting body of \\operatorname to be text but got`, node);
}
const text = body.reduce((buff, n) => {
// Hope convertToken() will not throw an error
// If it does, the input is bad.
buff += convertToken(n.content);
return buff;
}, "" as string);
const text = body[0].content;

if (this.preferTypstIntrinsic && TYPST_INTRINSIC_SYMBOLS.includes(text)) {
// e.g. we prefer just sech over op("sech")
Expand Down

0 comments on commit 4ac14df

Please sign in to comment.