I have a macro lVars, defined using foreach from the pgffor package (part of PGF) as:
\newcommand{\lVars}[1]{\foreach \x [count=\ii] in {#1}{
\ifnum\ii=1{} \else {,} \fi \lVar[\x]}
}
The intended use is in terms like \exists \lVars{a, b, c, d}, which produces the result \exists \lVar[a], \lVar[b], \lVar[c], \lVar[d]. The command \lVar[a] is another custom command of the form \newcommand{\lVar}[1][x]{\textsc{#1}}, but may become more complex shortly. I then use the newly quantified \lVar elements inside larger forumlae.
However, I'm extremely lazy. I'd quite like this macro to expose each list element as a new command of the form \lA, \lB etc, which themselves expand to the actual underlying \lVar[A], \lVar[B].... These new commands would make my formula notation significantly less verbose. These new commands should last until the next time a, b,... are used in the list parameter to the lVars macro. So, the overall usage will be situations like:
\begin{displaymath}
\begin{array}{l}
\exists \lVars{a, b, c}.~ \lA = \lB \implies \lA = \lC \\
\lC = 0 \implies \lA = 0
\exists \lVars{a, b}.~ \lA \neq \lB
\end{array}
\end{displaymath}
And, as we see in the term $\lA = \lB$, the implication...
I've experimented with various permutations on \newcommand and \def within the body of the foreach, without any luck. Any advice or tips?


foreachseems to be more appropriate – Alain Matthes Apr 13 '13 at 19:25