I am working on a React project where I need to replicate the behavior of the NewDocumentCommand in KaTeX. As an example, I’d like to replicate the following LaTeX command definition:
NewDocumentCommand{nder}{ m O{} O{x}}{frac{mathrm{d}^{#1} #2}{mathrm{d} #3^{#1}}}
.
This command allows for optional parameters with default values.
In a first attempt, I added "\nder": String.raw`frac{mathrm{d}^{#1} #2}{mathrm{d} #3^{#1}}`
to the options.macros
object in the katex.render
. Even though it works, it isn’t enough as it doesn’t account for optional parameters and doesn’t contemplate their default values.
The KaTeX’s options documentation does mention that each property of macros
may have as a value either a string, a function or a MacroExpansion
object, which gives me hope that it might be possible to replicate the command. However, the documentation is too technical for me to grasp fully.
I would greatly appreciate any advice from someone familiar with the KaTeX codebase on how to handle optional parameters with default values in custom macros.
Federico Melo Barrero is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.