
Estoy usando una lista de propiedades y me gustaría poder crear un comando que produzca la lista de claves que se usarán para generar un bucle for. Actualmente estoy usando \prop_map_inline para generar todas las claves, pero si uso esto en el bucle for, se interpreta como un solo elemento y no como una colección de varios elementos.
Este es un código de ejemplo:
\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}
Respuesta1
También puedes asignar las claves en 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}