I'd like to create a LaTeX3 function, \my_func
, that has a single parameter, #1
, which is expected to be initialized to a LaTeX3 string. \my_func
is to create a new document command using xparse
's \NewDocumentCommand
, whose name is the one passed as argument to \my_func
. How can I do so?
To give a concrete usage example, there's a bunch of mathematical functions that I wish to define. I'm still not sure what symbols I wish to use to represent them, though. So I define macros \func1
, \func2
, etc. with rather long and expressive names, e.g. \LeftProjectionOfTheSecondDegree
. These names won't change, but the symbols that represent them on paper may change later on.
Each of these functions can appear either standalone, or inside a bigger expression. When used inside a bigger expression, the functions always take arguments. However when they are used on their own, I need to express how many arguments they take, so I use subscripts, but these subscripts should not appear when the functions are part of a larger expression, because then the number of arguments can be easily deduced from the context.
\exp_args:Nc \NewDocumentCommand {#1}{...}{...}
should do as code in\my_func:n
\use:c {foo}
inside the\foo
command? That gives you an infinite loop. And, apart from that, are you looking precisely for a way of having a macro that works out and in of math mode? You have\ensuremath
for that.