¿Usar matriz/lista/secuencia para código repetitivo?

¿Usar matriz/lista/secuencia para código repetitivo?

Para una plantilla de portada de tesis doctoral en nuestra universidad, existe el siguiente código:

%%% Jury member n1 (Président) %%%
\newcommand{\jurynameA}{M. Cabot}
\newcommand{\juryadressA}{Someplace}
\newcommand{\jurygradeA}{Somerank}
\newcommand{\juryroleA}{Président du jury}
%%% Jury member n2 (Rapporteur) %%%
\newcommand{\jurynameB}{M. Blonde}
\newcommand{\juryadressB}{Anotherplace}
\newcommand{\jurygradeB}{Anotherrank}
\newcommand{\juryroleB}{Rapporteur} % 
%%% Jury member n3 (Rapporteur) %%%
\newcommand{\jurynameC}{M. Blue}
\newcommand{\juryadressC}{Someotherplace}
\newcommand{\jurygradeC}{Someotherrank}
\newcommand{\juryroleC}{Rapporteur}
%%% Jury member n4 (Examinateur) %%%
\newcommand{\jurynameD}{M. Brown}
\newcommand{\juryadressD}{Yetanotherplace}
\newcommand{\jurygradeD}{Yetanotherrank}
\newcommand{\juryroleD}{Examinateur}
%%% Jury member n5 (Examinateur) %%%
\newcommand{\jurynameE}{M. Orange}
\newcommand{\juryadressE}{Onemoreplace}
\newcommand{\jurygradeE}{One more rank}
\newcommand{\juryroleE}{Examinateur}
%%% Jury member n6 (Directeur) %%%
\newcommand{\jurynameF}{M. Pink}
\newcommand{\juryadressF}{Yourplace}
\newcommand{\jurygradeF}{HDR}
\newcommand{\juryroleF}{Directeur de thèse}
%%% Jury member n7 (Co-Directeur) %%%
\newcommand{\jurynameG}{M. White}
\newcommand{\juryadressG}{Yourotherplace}
\newcommand{\jurygradeG}{HDR?}
\newcommand{\juryroleG}{Co-Directeur de thèse}
\begin{tabular}{lll}

    \textsc{\jurynameA}  & \jurygradeA & (\juryroleA) \\
    \null  & \textit{\juryadressA} & \\

    \textsc{\jurynameB}  & \jurygradeB & (\juryroleB) \\
    \null  & \textit{\juryadressB} & \\

    \textsc{\jurynameC}  & \jurygradeC & (\juryroleC) \\
    \null  & \textit{\juryadressC} & \\

    \textsc{\jurynameD}  & \jurygradeD & (\juryroleD) \\
    \null  & \textit{\juryadressD} & \\

    \textsc{\jurynameE}  & \jurygradeE & (\juryroleE) \\
    \null  & \textit{\juryadressE} & \\

    \textsc{\jurynameF}  & \jurygradeF & (\juryroleF) \\
    \null  & \textit{\juryadressF} & \\

    \textsc{\jurynameG}  & \jurygradeG & (\juryroleG) \\
    \null  & \textit{\juryadressG} & \\

\end{tabular}

Me preguntaba si sería posible ingresar datos más fácilmente (algo así \addmember{M. Pink}{Yourplace}{HDR}{Directeur de thèse}) y luego generar la tabla automáticamente sin preocuparme por la cantidad de miembros del jurado (algunas personas pueden tener 4 miembros, otras hasta 8).

En Python, por ejemplo, habría usado una lista de dict (o solo de listas si no me importara la semántica), cada dict describiendo a un miembro del jurado, y habría iterado sobre esa lista para escribir la tabla. ¿Es posible hacer algo así con LaTeX?

Respuesta1

Aquí hay una forma de hacerlo usando métodos estándar de LaTeX de etoolboxy pgffor.

\documentclass{article}
\usepackage{pgffor,etoolbox,array}
\newcounter{members}
\newcommand{\addmember}[4]{%
\ifnum\value{members}=8
    \typeout{Warning: your committee has too many members! Extra members ignored.}
\else
    \stepcounter{members}
    \csgdef{juryname\themembers}{#1}
    \csgdef{juryadress\themembers}{#2}
    \csgdef{jurygrade\themembers}{#3}
    \csgdef{juryrole\themembers}{#4}
\fi
}
\newcommand{\thecommitee}{}
\makeatletter
\newcommand{\makecommittee}{%
\foreach \x in {1,...,\value{members}}{
\protected@xappto{\thecommittee}{%
\csuse{juryname\x} &
\csuse{jurygrade\x} &
(\csuse{juryrole\x})\tabularnewline
&\itshape\csuse{juryadress\x} &\tabularnewline
}
}
\begin{tabular}{>{\scshape}lll}
\thecommittee
\end{tabular}
}
\makeatother
\begin{document}
\addmember{M. Cabot}{Montréal}{PhD}{Président du jury}
\addmember{M. Blonde}{Trois Rivières}{PhD}{Rapporteur}
\addmember{M. Brun}{Québec}{PhD}{Examinateur}
\addmember{M. Vert}{Paris}{PhD}{Examinateur}
\addmember{M. Gris}{Montréal}{PhD}{Directeur de thèse}
\makecommittee
\end{document}

salida de código

información relacionada