Eu tenho uma macro lVars
, definida usando foreach
o pgffor
pacote (parte doPGF) como:
\newcommand{\lVars}[1]{\foreach \x [count=\ii] in {#1}{
\ifnum\ii=1{} \else {,} \fi \lVar[\x]}
}
O uso pretendido é em termos como \exists \lVars{a, b, c, d}
, que produz o resultado \exists \lVar[a], \lVar[b], \lVar[c], \lVar[d]
. O comando \lVar[a]
é outro comando personalizado do formulário \newcommand{\lVar}[1][x]{\textsc{#1}}
, mas pode se tornar mais complexo em breve. Em seguida, uso os \lVar
elementos recentemente quantificados dentro de fóruns maiores.
No entanto, sou extremamente preguiçoso. Eu gostaria que esta macro expusesse cada elemento da lista como um novo comando do formulário \lA
, \lB
etc, que se expandisse para o subjacente real \lVar[A]
, \lVar[B]
.... Esses novos comandos tornariam minha notação de fórmula significativamente menos detalhada. Esses novos comandos devem durar até a próxima vez que a
... b,
forem usados no parâmetro de lista da lVars
macro. Portanto, o uso geral será em situações como:
\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...
Eu experimentei várias permutações dentro \newcommand
e \def
dentro do corpo do foreach
, sem sorte. Algum conselho ou dica?
Responder1
\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\lVars}{m}
{
% cycle through the argument
\clist_map_inline:nn { #1 }
{
% print the variable
\lVar[##1]
% if the variable is a, define \lA
\tl_to_uppercase:n
{
\cs_gset_protected:cpn { \c_wright_prefix_tl ##1 }
}
{ \lVar[##1] }
}
}
% We need to store the `l' prefix in a control sequence to hide it from \uppercase
\tl_const:Nn \c_wright_prefix_tl { l }
\ExplSyntaxOff
\newcommand{\lVar}[1][x]{\textsc{#1}}
\begin{document}
\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...
\end{document}
Contudo, a definição de \lC
sobreviverá para sempre; se você planeja usá-lo em células diferentes de uma array
definição global, é necessária.
Uma versão que aceita variáveis multiletras e define \lFoo
from \lVars{foo}
:
\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\lVars}{m}
{
% cycle through the argument
\clist_map_inline:nn { #1 }
{
% print the variable
\lVar[##1]
% build the name with the first letter uppercase
\wright_make_var_name:n { ##1 }
\cs_gset_protected:cpn { \l__wright_var_name_tl } { \lVar[##1] }
}
}
\tl_const:Nn \c_wright_prefix_tl { l }
\cs_new:Npn \wright_make_var_name:n #1
{
% get the first letter and uppercase it
\tl_to_uppercase:n
{
\tl_set:Nx \l__wright_var_name_tl { \tl_head:n {#1} }
}
% add the rest
\tl_put_right:Nx \l__wright_var_name_tl { \tl_tail:n {#1} }
% add the prefix
\tl_put_left:Nx \l__wright_var_name_tl { \c_wright_prefix_tl }
}
\ExplSyntaxOff
\newcommand{\lVar}[1][x]{\textsc{#1}}
\begin{document}
\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...
Now $\forall\lVars{foo}\;\lFoo=0$
\end{document}