Use array/list/sequence for repetitive code?












3















For a PhD thesis cover template in our university, there is some code as follow:



%%% 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}


I was wondering if it would be possible to input data more easily (something like addmember{M. Pink}{Yourplace}{HDR}{Directeur de thèse}), and then have the table generated automatically without worrying about the number of jury members (some people may have 4 members, some up to 8).



In Python for instance, I would have used a list of dict (or just of lists if I did not care about semantics), each dict describing a jury member, and would have iterated over that list to write the table. Is it possible to do something like that with LaTeX?










share|improve this question























  • pgfplotstable allows you to typeset a table from a dataset you load.

    – marmot
    Feb 28 at 0:18
















3















For a PhD thesis cover template in our university, there is some code as follow:



%%% 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}


I was wondering if it would be possible to input data more easily (something like addmember{M. Pink}{Yourplace}{HDR}{Directeur de thèse}), and then have the table generated automatically without worrying about the number of jury members (some people may have 4 members, some up to 8).



In Python for instance, I would have used a list of dict (or just of lists if I did not care about semantics), each dict describing a jury member, and would have iterated over that list to write the table. Is it possible to do something like that with LaTeX?










share|improve this question























  • pgfplotstable allows you to typeset a table from a dataset you load.

    – marmot
    Feb 28 at 0:18














3












3








3








For a PhD thesis cover template in our university, there is some code as follow:



%%% 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}


I was wondering if it would be possible to input data more easily (something like addmember{M. Pink}{Yourplace}{HDR}{Directeur de thèse}), and then have the table generated automatically without worrying about the number of jury members (some people may have 4 members, some up to 8).



In Python for instance, I would have used a list of dict (or just of lists if I did not care about semantics), each dict describing a jury member, and would have iterated over that list to write the table. Is it possible to do something like that with LaTeX?










share|improve this question














For a PhD thesis cover template in our university, there is some code as follow:



%%% 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}


I was wondering if it would be possible to input data more easily (something like addmember{M. Pink}{Yourplace}{HDR}{Directeur de thèse}), and then have the table generated automatically without worrying about the number of jury members (some people may have 4 members, some up to 8).



In Python for instance, I would have used a list of dict (or just of lists if I did not care about semantics), each dict describing a jury member, and would have iterated over that list to write the table. Is it possible to do something like that with LaTeX?







programming






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Feb 28 at 0:13









ArchangeArchange

335




335













  • pgfplotstable allows you to typeset a table from a dataset you load.

    – marmot
    Feb 28 at 0:18



















  • pgfplotstable allows you to typeset a table from a dataset you load.

    – marmot
    Feb 28 at 0:18

















pgfplotstable allows you to typeset a table from a dataset you load.

– marmot
Feb 28 at 0:18





pgfplotstable allows you to typeset a table from a dataset you load.

– marmot
Feb 28 at 0:18










1 Answer
1






active

oldest

votes


















4














Here's one way to do it using standard LaTeX methods from etoolbox and pgffor.



documentclass{article}
usepackage{pgffor,etoolbox,array}
newcounter{members}
newcommand{addmember}[4]{%
ifnumvalue{members}=8
typeout{Warning: your committee has too many members! Extra members ignored.}
else
stepcounter{members}
csgdef{jurynamethemembers}{#1}
csgdef{juryadressthemembers}{#2}
csgdef{jurygradethemembers}{#3}
csgdef{juryrolethemembers}{#4}
fi
}
newcommand{thecommitee}{}
makeatletter
newcommand{makecommittee}{%
foreach x in {1,...,value{members}}{
protected@xappto{thecommittee}{%
csuse{jurynamex} &
csuse{jurygradex} &
(csuse{juryrolex})tabularnewline
&itshapecsuse{juryadressx} &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}


output of code






share|improve this answer

























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "85"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f477055%2fuse-array-list-sequence-for-repetitive-code%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    4














    Here's one way to do it using standard LaTeX methods from etoolbox and pgffor.



    documentclass{article}
    usepackage{pgffor,etoolbox,array}
    newcounter{members}
    newcommand{addmember}[4]{%
    ifnumvalue{members}=8
    typeout{Warning: your committee has too many members! Extra members ignored.}
    else
    stepcounter{members}
    csgdef{jurynamethemembers}{#1}
    csgdef{juryadressthemembers}{#2}
    csgdef{jurygradethemembers}{#3}
    csgdef{juryrolethemembers}{#4}
    fi
    }
    newcommand{thecommitee}{}
    makeatletter
    newcommand{makecommittee}{%
    foreach x in {1,...,value{members}}{
    protected@xappto{thecommittee}{%
    csuse{jurynamex} &
    csuse{jurygradex} &
    (csuse{juryrolex})tabularnewline
    &itshapecsuse{juryadressx} &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}


    output of code






    share|improve this answer






























      4














      Here's one way to do it using standard LaTeX methods from etoolbox and pgffor.



      documentclass{article}
      usepackage{pgffor,etoolbox,array}
      newcounter{members}
      newcommand{addmember}[4]{%
      ifnumvalue{members}=8
      typeout{Warning: your committee has too many members! Extra members ignored.}
      else
      stepcounter{members}
      csgdef{jurynamethemembers}{#1}
      csgdef{juryadressthemembers}{#2}
      csgdef{jurygradethemembers}{#3}
      csgdef{juryrolethemembers}{#4}
      fi
      }
      newcommand{thecommitee}{}
      makeatletter
      newcommand{makecommittee}{%
      foreach x in {1,...,value{members}}{
      protected@xappto{thecommittee}{%
      csuse{jurynamex} &
      csuse{jurygradex} &
      (csuse{juryrolex})tabularnewline
      &itshapecsuse{juryadressx} &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}


      output of code






      share|improve this answer




























        4












        4








        4







        Here's one way to do it using standard LaTeX methods from etoolbox and pgffor.



        documentclass{article}
        usepackage{pgffor,etoolbox,array}
        newcounter{members}
        newcommand{addmember}[4]{%
        ifnumvalue{members}=8
        typeout{Warning: your committee has too many members! Extra members ignored.}
        else
        stepcounter{members}
        csgdef{jurynamethemembers}{#1}
        csgdef{juryadressthemembers}{#2}
        csgdef{jurygradethemembers}{#3}
        csgdef{juryrolethemembers}{#4}
        fi
        }
        newcommand{thecommitee}{}
        makeatletter
        newcommand{makecommittee}{%
        foreach x in {1,...,value{members}}{
        protected@xappto{thecommittee}{%
        csuse{jurynamex} &
        csuse{jurygradex} &
        (csuse{juryrolex})tabularnewline
        &itshapecsuse{juryadressx} &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}


        output of code






        share|improve this answer















        Here's one way to do it using standard LaTeX methods from etoolbox and pgffor.



        documentclass{article}
        usepackage{pgffor,etoolbox,array}
        newcounter{members}
        newcommand{addmember}[4]{%
        ifnumvalue{members}=8
        typeout{Warning: your committee has too many members! Extra members ignored.}
        else
        stepcounter{members}
        csgdef{jurynamethemembers}{#1}
        csgdef{juryadressthemembers}{#2}
        csgdef{jurygradethemembers}{#3}
        csgdef{juryrolethemembers}{#4}
        fi
        }
        newcommand{thecommitee}{}
        makeatletter
        newcommand{makecommittee}{%
        foreach x in {1,...,value{members}}{
        protected@xappto{thecommittee}{%
        csuse{jurynamex} &
        csuse{jurygradex} &
        (csuse{juryrolex})tabularnewline
        &itshapecsuse{juryadressx} &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}


        output of code







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Feb 28 at 6:13

























        answered Feb 28 at 4:40









        Alan MunnAlan Munn

        162k28431706




        162k28431706






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f477055%2fuse-array-list-sequence-for-repetitive-code%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

            ComboBox Display Member on multiple fields

            Is it possible to collect Nectar points via Trainline?