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:
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})-
|
I want to create a macro macros: {
'\\tabs': (arg1) => '\\quad'.repeat(arg1),
}Or is there any way to do what I want? |
Beta Was this translation helpful? Give feedback.
-
|
Yes, it's possible, but I don't think it's documented currently. See 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)
}
}
}) |
Beta Was this translation helpful? Give feedback.
Yes, it's possible, but I don't think it's documented currently. See
src/macros.jsfor 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: