I am having hard time finding how to do In Typst what in LaTeX can be done with \newcommand with parameters. Are there examples online of custom shorthand notations with parameters that work in math and text mode? Did I miss a documentation section about this?
Say, I want to use a “macro” with a parameter to simplify
If you want to only pass in a single argument, I suppose you can pass in an equation:
$intervaloo( #$0, infinity$ )$
But to be clear, arguments are separated by commas in typst (unlike wrapping each of them in {...} as in LaTeX). If you want to avoid unnecessary overhead when calling your function, I’d suggest using the argument sink as shown above.
I don’t know if the #$...$ is explicitly mentioned in the documentation, but the hash prefix can be used in non-code mode to add expressions, which in addition to functions can also be content blocks such as #[Hello world!] or equations #$x^2$ (see also the “blocks” section in the link above).
Well, sure. If you really feel this way, semantically the correct choice would be to escape the commas (or define a variable to use instead of commas #let sep = $,$.body), since to me it makes even less sense to have equations inside of equations. But, if you’re happy with this then okay.
I’ve just searched through the PDF documentation for Typst 0.15.1, and #$...$ does not appear there at all, and #[...] appears 4 times, without explanation.
These are both examples of telling the compiler which mode the text should be interpreted as. This information is shown on the Syntax page of the documentation. It’s not really mentioned elsewhere (I guess) since it is so fundamental.
Here’s a table showing how to get from one mode to another: