Skip to content
\n

Or is there any way to do what I want?

","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"

Yes, it's possible, but I don't think it's documented currently. See src/macros.js for a bunch of examples. Dealing with numbers is unfortunately a bit painful, because each character becomes its own token, and the tokens are in reverse order. This should do what you want:

\n
katex.renderToString('\\\\tabs{10}', {\n  macros: {\n    '\\\\tabs': (context) => {\n      let [arg] = context.consumeArgs(1);\n      arg = arg.reverse().map(token => token.text).join('');\n      arg = Number(arg);\n      return '\\\\quad'.repeat(arg)\n    }\n  }\n})
","upvoteCount":2,"url":"https://github.com/KaTeX/KaTeX/discussions/3943#discussioncomment-9011824"}}}
Discussion options

You must be logged in to vote

Yes, it's possible, but I don't think it's documented currently. See src/macros.js for a bunch of examples. Dealing with numbers is unfortunately a bit painful, because each character becomes its own token, and the tokens are in reverse order. This should do what you want:

katex.renderToString('\\tabs{10}', {
  macros: {
    '\\tabs': (context) => {
      let [arg] = context.consumeArgs(1);
      arg = arg.reverse().map(token => token.text).join('');
      arg = Number(arg);
      return '\\quad'.repeat(arg)
    }
  }
})

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@fmorroni
Comment options

Answer selected by fmorroni
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants