\def\foo#1{a#1b}
creates \foo
that expects for a mandatory argument when used.
I'm trying to create so called "anonymous" or "lambda" macro that is essentially a token list with a suspended expansion.
The idea is to have something like
{a#1b}{CCC}
which will output aCCCb
.
My real use case is related to enumitem
's format key
\documentclass{article}
\usepackage{enumitem}
\newcommand\mydesclabel[1]{\normalfont#1\quad ---}
\setlist[description]{format=\mydesclabel}
\begin{document}
\begin{description}
\item[A] foo
\item[B] bar
\end{description}
\end{document}
I want to avoid using \mydesclabel
temporary macro and specify format
directly.
I've tried so far:
\setlist[description]{format={\unexpanded{\normalfont#1\quad ---}}}
\setlist[description]{format={\aftergroup{\normalfont#1\quad ---}}}
Neither worked
enumitem
doesn't support this usage offormat
, you need a macro for that.titlesec
. You can define format with\titleformat
literally specifying#1
there and all that gets suspended for expansion and stored in a token list which is used later during all section creation. MWE: pastebin.com/f3XP5pxK, demo: imgur.com/a/GU9uvvk. So it should definitely be possible.#1
there is just a normal macro parameter there is no anonymous function involved, unless you mean that\titleformat
itself is a macro definition which takes a name and a macro body using#
which is of course the case, it is basically\def\ttl@format@si#1#2#3#4#5#6#7{% \@namedef{ttlf@\ttl@a}{#1{#7}{#3}{#4}{#5}{#6}}}
#1
(and many packages do so), but that's far from an anonymous function, that's just a frontend defining an internal macro.