
Estou usando uma lista de propriedades e gostaria de poder criar um comando que produza a lista de chaves a serem usadas para gerar um loop for. Atualmente estou usando \prop_map_inline para gerar todas as chaves, mas se eu usar isso no loop for, ele será interpretado como um único item e não como uma coleção de vários itens.
Este é um código de exemplo:
\documentclass{article}
\usepackage{ifthen}
\usepackage{xparse}
\ExplSyntaxOn
\prop_new:N \g_persons_prop
% Create a new person
\NewDocumentCommand{\CreatePerson}{m} {
\prop_gput:Nnn \g_persons_prop { #1 }
}
% Gets all persons
\NewDocumentCommand{\GetAllPersonKeys}{}{
\prop_map_inline:Nn \g_persons_prop {
##1,
}
}
\ExplSyntaxOff
\CreatePerson{jd}{John Doe}
\CreatePerson{ad}{Albert Dull}
\CreatePerson{bu}{Ben Under}
\begin{document}
I would like to have this:
\makeatletter
\begin{itemize}
\@for\sun:={jd, ad, bu}\do{\item We have person: \sun. }
\end{itemize}
\makeatother
But I get this instead:
\makeatletter
\begin{itemize}
\@for\sun:={\GetAllPersonKeys}\do{\item We have person: \sun. }
\end{itemize}
\makeatother
\end{document}
Responder1
Você também pode mapear as chaves em expl3:
\documentclass{article}
\usepackage{ifthen}
\usepackage{xparse}
\ExplSyntaxOn
\prop_new:N \g_persons_prop
% Create a new person
\NewDocumentCommand{\CreatePerson}{m} {
\prop_gput:Nnn \g_persons_prop { #1 }
}
\NewDocumentCommand{\MapAllPersonKeys}{m}{
\prop_map_inline:Nn \g_persons_prop {
#1
}
}
\ExplSyntaxOff
\CreatePerson{jd}{John Doe}
\CreatePerson{ad}{Albert Dull}
\CreatePerson{bu}{Ben Under}
\begin{document}
I would like to have this:
\makeatletter
\begin{itemize}
\@for\sun:={jd, ad, bu}\do{\item We have person: \sun. }
\end{itemize}
\makeatother
\begin{itemize}
\MapAllPersonKeys{\item we have person: #1!}
\end{itemize}
\end{document}