I wish to create two macros: one that takes a known number, and another that takes an unknown number of arguments that are comma-separated and does something with them. There have been a few answers to this question before see (here and here), but they always use modern LaTeX packages such as xparse
. For example, I could create a new fraction command (known number of args) by doing
\ExplSyntaxOn
\makeatletter
\def\numargs{2}
\NewDocumentCommand{\frc}{>{\SplitArgument{\numargs-1}{,}}m}{\@frc@#1}
\NewDocumentCommand{\@frc@}{mm}{\frac{#1}{#2}}
\makeatother
\ExplSyntaxOff
and using it with \frc{1,2}
, effectively doing the same as \frac{1}{2}
. Another example would be to create a bolded list (unknown number of args) with
\ExplSyntaxOn
\NewDocumentCommand{\bflist}{m}{\clist_map_inline:nn{#1}{\@bflist@{##1}}}
\newcommand{\@bflist@}[1]{\bf #1}
\ExplSyntaxOff
and using it with \bflist{a, b, c, d, e, f}
, etc, which would create the bolded list a b c d e f. Both of these solutions use modern LaTeX tools; I am wondering, is there a way to create these commands in plain TeX? Or at the very least, in LaTeX without using external packages?
xparse
in plain TeX.\NewDocumentCommand
or\SplitArgument
in latex (unless you have an old release)