I'd like to make a shortcut macro to prefix function names in formulae to decorate them in some way depending on the function type. Using "normal" macros would lead to an abundance of braces and I'm looking for something cleaner.
I was trying to define a macro that would chop everything until the next space (or, if possible, until the next non-letter token), and treat that as argument. Is it possible?
Example (don't focus on the macro body):
\def\f <what goes here?> {\mathop{\mathrm{#1}}}
\def\kw <what goes here?> {\mathop{\color{red} #1}}
...
Consider the following:
\[
\kw return \f isBool x \kw or \f isString x
\]
would be equivalent to:
Consider the following:
\[
\mathop{\color{red} return}
\mathop{\mathrm{isBool}} x
\mathop{\color{red} or}
\mathop{\mathrm{isString}} x
\]
And, if possible, such a macro should be able to understand if it's receiving a braced argument so \kw{return}
would take return
as argument regardless of spaces, so that it can be used like a normal macro for who do not know its special behavior.
Any TeX/LaTeX solution is welcome...
\def
& co. rather than\newcommand
so I putplain
. Is it the wrong tag?