I wrote something like that some time ago to assist in another project of mine. Some internal macros started to have too many arguments and I was changing their order too often, so keeping track of the argument numbers was becoming a nuisance (and often lead to errors).
To solve that, I wrote the namedef
package, that allows you to change from (an admittedly boring example):
\def\Say#1 to #2%
{#1, #2!}
to
\named\def\Say#[greeting] to #[whom]%
{#[greeting], #[whom]!}
The advantage I saw in this syntax is that if you decide to swap the order of #[greeting]
and #[whom]
in the parameter text, you don't have to change them in the replacement text—the advantage of semantics over syntax :-)
The code works by scanning the definition for #6[⟨name⟩]
, replacing them by numbers, and then handing the translated tokens for TeX to perform the definition.
The code is hosted at https://github.com/PhelypeOleinik/namedef. To build the .sty
file, run tex namedef.ins
, and to build the documentation, run pdflatex namedef.ins
. The generated .sty
file can be used in LaTeX with \usepackage{namedef}
, or in other formats with \input namedef.sty
.
\def\foo[#1]#2{#1 ... #2 ...} %where #1=parameters, %2=content
seems to be enough clear.pdflatex namedef.ins
, and a.sty
file should be generated.