Global variable Array

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












5















I have control_array.tex and 10 templateA.tex, templateB.tex, ... TeX files. In control_array.tex:



  • ArrayName = [Name1,Name2,...Name10]

  • ArrayColor = [Color1,Color2,...Color10]

With Array in control_array.tex I can change all variable only one time in all templates: templateA.tex, templateB.tex, ...



Here's my MWE:



documentclass[a4paper,twoside,12pt]article
usepackagexcolor
begindocument
%Call Name1, Nam10...Color 1, Color2...Color10
beginenumerate
item textcolorcolor1Name1
item textcolorcolor2Name2
item textcolorcolor3Name3
endenumerate
textcolorcolor4Name9 \
textcolorcolor5Name8
enddocument


How can I do it with LaTeX? Any ideas are welcome.










share|improve this question
























  • Constant arrays are easy, variable arrays use things like csname nametheindexendcsname.

    – John Kormylo
    Feb 14 at 4:51















5















I have control_array.tex and 10 templateA.tex, templateB.tex, ... TeX files. In control_array.tex:



  • ArrayName = [Name1,Name2,...Name10]

  • ArrayColor = [Color1,Color2,...Color10]

With Array in control_array.tex I can change all variable only one time in all templates: templateA.tex, templateB.tex, ...



Here's my MWE:



documentclass[a4paper,twoside,12pt]article
usepackagexcolor
begindocument
%Call Name1, Nam10...Color 1, Color2...Color10
beginenumerate
item textcolorcolor1Name1
item textcolorcolor2Name2
item textcolorcolor3Name3
endenumerate
textcolorcolor4Name9 \
textcolorcolor5Name8
enddocument


How can I do it with LaTeX? Any ideas are welcome.










share|improve this question
























  • Constant arrays are easy, variable arrays use things like csname nametheindexendcsname.

    – John Kormylo
    Feb 14 at 4:51













5












5








5








I have control_array.tex and 10 templateA.tex, templateB.tex, ... TeX files. In control_array.tex:



  • ArrayName = [Name1,Name2,...Name10]

  • ArrayColor = [Color1,Color2,...Color10]

With Array in control_array.tex I can change all variable only one time in all templates: templateA.tex, templateB.tex, ...



Here's my MWE:



documentclass[a4paper,twoside,12pt]article
usepackagexcolor
begindocument
%Call Name1, Nam10...Color 1, Color2...Color10
beginenumerate
item textcolorcolor1Name1
item textcolorcolor2Name2
item textcolorcolor3Name3
endenumerate
textcolorcolor4Name9 \
textcolorcolor5Name8
enddocument


How can I do it with LaTeX? Any ideas are welcome.










share|improve this question
















I have control_array.tex and 10 templateA.tex, templateB.tex, ... TeX files. In control_array.tex:



  • ArrayName = [Name1,Name2,...Name10]

  • ArrayColor = [Color1,Color2,...Color10]

With Array in control_array.tex I can change all variable only one time in all templates: templateA.tex, templateB.tex, ...



Here's my MWE:



documentclass[a4paper,twoside,12pt]article
usepackagexcolor
begindocument
%Call Name1, Nam10...Color 1, Color2...Color10
beginenumerate
item textcolorcolor1Name1
item textcolorcolor2Name2
item textcolorcolor3Name3
endenumerate
textcolorcolor4Name9 \
textcolorcolor5Name8
enddocument


How can I do it with LaTeX? Any ideas are welcome.







color external-files






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 14 at 2:53









Werner

447k699891693




447k699891693










asked Feb 14 at 2:14









tisaigontisaigon

3117




3117












  • Constant arrays are easy, variable arrays use things like csname nametheindexendcsname.

    – John Kormylo
    Feb 14 at 4:51

















  • Constant arrays are easy, variable arrays use things like csname nametheindexendcsname.

    – John Kormylo
    Feb 14 at 4:51
















Constant arrays are easy, variable arrays use things like csname nametheindexendcsname.

– John Kormylo
Feb 14 at 4:51





Constant arrays are easy, variable arrays use things like csname nametheindexendcsname.

– John Kormylo
Feb 14 at 4:51










4 Answers
4






active

oldest

votes


















6














You could use pgffor for that.



documentclass[a4paper,twoside,12pt]article
usepackagepgffor
usepackagexcolor
begindocument
defArrayNames"koala","duck","marmot","penguin","bear"
defArrayColors"gray","yellow","blue","red","brown"
beginenumerate
foreach X in 0,...,4
pgfmathsetmacromynameArrayNames[X]
pgfmathsetmacromycolorArrayColors[X]
item textcolormycolormyname
endenumerate
enddocument


enter image description here



Or with an external file (which I create here for the convenience of others in the MWE, but you may drop the filecontents stuff as long you have a data file).



documentclass[a4paper,twoside,12pt]article
usepackagefilecontents
beginfilecontents*myarrays.tex
defArrayNames"koala","duck","marmot","penguin","bear"
defArrayColors"gray","yellow","blue","red","brown"
endfilecontents*
usepackagepgffor
usepackagexcolor
begindocument
inputmyarrays.tex
beginenumerate
foreach X in ArrayNames
foreach Y [count=Z starting from 0]in X
pgfmathsetmacromycolorArrayColors[Z]
pgfmathsetmacromynameArrayNames[Z]
item textcolormycolormyname
endenumerate
enddocument


And of course you can install any mapping. Here is an example (in which I assume you already have created myarrays.tex, if not uncomment the corresponding lines).



documentclass[a4paper,twoside,12pt]article
% usepackagefilecontents
% beginfilecontents*myarrays.tex
% defArrayNames"koala","duck","marmot","penguin","bear"
% defArrayColors"gray","yellow","blue","red","brown"
% endfilecontents*
usepackagepgffor
usepackagexcolor
begindocument
inputmyarrays.tex
pgfkeys/pgf/declare function=mymap(x)=int(mod(1+x*x,4));
beginenumerate
foreach X in ArrayNames
foreach Y [count=Z starting from 0]in X
pgfmathsetmacromycolorArrayColors[mymap(Z)]
pgfmathsetmacromynameArrayNames[Z]
item textcolormycolormyname
endenumerate
enddocument


enter image description here



As you can see, this function is chosen such that it distinguishes between birds on the one hand and mammals and beings on the other hand.






share|improve this answer

























  • thank for your quick reply. I know that pgffor in same file.tex can do it. Can you solution/idea set variable array in control file, not in template file? defArrayNames"koala","duck","marmot","penguin","bear" defArrayColors"gray","yellow","blue","red","brown" Thanks

    – tisaigon
    Feb 14 at 2:25






  • 1





    @tisaigon myarrays.tex needs only to have defArrayNames"koala","duck","marmot","penguin","bear" defArrayColors"gray","yellow","blue","red","brown" in it.

    – marmot
    Feb 14 at 4:52






  • 1





    @tisaigon I added a mapping function (the flexibility of adding this very easily may be an advantage of this approach), which you can adjust to your needs.

    – marmot
    Feb 14 at 6:36






  • 1





    @tisaigon What does documentclass[a4paper,twoside,12pt]article usepackagepgffor usepackagexcolor begindocument inputmyarrays.tex pgfmathsetmacromynameArrayNames[3] myname enddocument give you?

    – marmot
    Feb 14 at 7:12






  • 1





    @tisaigon Could you please ask a new question for that. I am just about to go to bed and others will help you more quickly. If you are lucky, Christian Hupfer sees your question, then you will get an excellent answer.

    – marmot
    Feb 14 at 7:47


















3














Trivial with listofitems.



documentclassarticle
usepackagelistofitems,xcolor
newcommandArrayNamesName1,Name2,N3,N4,N5,N6,N7,N8,N9,Name10
newcommandArrayColorsred,blue,cyan,cyan!50!red,red!50,
purple,green,yellow,blue!50,magenta
readlist*arraynameArrayNames
readlist*arraycolorArrayColors
begindocument
beginenumerate
foreachitemxinarraynameitem textcolorarraycolor[xcnt]x
endenumerate

textcolorarraycolor[4]arrayname[9]

textcolorarraycolor[5]arrayname[8]
enddocument


enter image description here






share|improve this answer






























    3














    You can have files with the following structure



    colorlist
    red
    green
    blue
    green!40!yellow
    -green!40!yellow
    rgb:-green!40!yellow,3;green!40!yellow,2;red,1
    red>wheel,12



    It would also be possible to have the simpler structure



    red
    green
    blue
    green!40!yellow


    - green!40!yellow
    rgb:-green!40!yellow,3;green!40!yellow,2;red,1
    red>wheel,12



    if preferred. Then in the document you call



    assigncolors<filename><list of names for the colors>


    Here's the code, using filecontents for making the example self-contained; the name for the color list file can be whatever you prefer.



    beginfilecontentsjobname.colors
    colorlist
    red
    green
    blue
    green!40!yellow
    -green!40!yellow
    rgb:-green!40!yellow,3;green!40!yellow,2;red,1
    red>wheel,12

    endfilecontents

    documentclassarticle
    usepackagexcolor
    usepackagexparse

    ExplSyntaxOn
    NewDocumentCommandassigncolorsmm
    % #1 = file name, #2 = list of names
    clist_set:Nn l__tisaigon_colornames_clist #2
    file_input:n #1

    NewDocumentCommandcolorlistm

    int_zero:N l__tisaigon_colornames_int
    tl_map_inline:nn #1

    int_incr:N l__tisaigon_colornames_int
    colorlet

    clist_item:Nn l__tisaigon_colornames_clist l__tisaigon_colornames_int


    ##1



    clist_new:N l__tisaigon_colornames_clist
    int_new:N l__tisaigon_colornames_int
    ExplSyntaxOff

    assigncolorsjobname.colors
    color1,
    color2,
    color3,
    header,
    body,
    footer,
    fancy,


    begindocument

    textcolorcolor1Abc

    textcolorcolor2Abc

    textcolorcolor3Abc

    textcolorheaderAbc

    textcolorbodyAbc

    textcolorfooterAbc

    textcolorfancyAbc

    enddocument


    enter image description here






    share|improve this answer






























      2














      In a very simplistic way you can place a number of color definitions using (say) colorletcolorX<colour> inside color_array.tex and load them within the document preamble:



      enter image description here



      documentclassarticle

      % Just for this example, create control_array.tex that contains all the colour definitions
      usepackagefilecontents
      beginfilecontents*control_array.tex
      usepackagexcolor
      colorletcolor1blue
      colorletcolor2green
      colorletcolor3red!30!yellow
      colorletcolor4rgb:black,1;red,2;orange,3
      colorletcolor5black!50
      endfilecontents*

      inputcontrol_array% Input colour definitions

      begindocument

      beginenumerate
      item textcolorcolor1Name1
      item textcolorcolor2Name2
      item textcolorcolor3Name3
      endenumerate

      textcolorcolor4Name9

      textcolorcolor5Name8

      enddocument


      Note that inputcolor_array is called within the preamble since color_array.tex includes a call to load xcolor which can only be called within the preamble.






      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%2f474792%2fglobal-variable-array%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        6














        You could use pgffor for that.



        documentclass[a4paper,twoside,12pt]article
        usepackagepgffor
        usepackagexcolor
        begindocument
        defArrayNames"koala","duck","marmot","penguin","bear"
        defArrayColors"gray","yellow","blue","red","brown"
        beginenumerate
        foreach X in 0,...,4
        pgfmathsetmacromynameArrayNames[X]
        pgfmathsetmacromycolorArrayColors[X]
        item textcolormycolormyname
        endenumerate
        enddocument


        enter image description here



        Or with an external file (which I create here for the convenience of others in the MWE, but you may drop the filecontents stuff as long you have a data file).



        documentclass[a4paper,twoside,12pt]article
        usepackagefilecontents
        beginfilecontents*myarrays.tex
        defArrayNames"koala","duck","marmot","penguin","bear"
        defArrayColors"gray","yellow","blue","red","brown"
        endfilecontents*
        usepackagepgffor
        usepackagexcolor
        begindocument
        inputmyarrays.tex
        beginenumerate
        foreach X in ArrayNames
        foreach Y [count=Z starting from 0]in X
        pgfmathsetmacromycolorArrayColors[Z]
        pgfmathsetmacromynameArrayNames[Z]
        item textcolormycolormyname
        endenumerate
        enddocument


        And of course you can install any mapping. Here is an example (in which I assume you already have created myarrays.tex, if not uncomment the corresponding lines).



        documentclass[a4paper,twoside,12pt]article
        % usepackagefilecontents
        % beginfilecontents*myarrays.tex
        % defArrayNames"koala","duck","marmot","penguin","bear"
        % defArrayColors"gray","yellow","blue","red","brown"
        % endfilecontents*
        usepackagepgffor
        usepackagexcolor
        begindocument
        inputmyarrays.tex
        pgfkeys/pgf/declare function=mymap(x)=int(mod(1+x*x,4));
        beginenumerate
        foreach X in ArrayNames
        foreach Y [count=Z starting from 0]in X
        pgfmathsetmacromycolorArrayColors[mymap(Z)]
        pgfmathsetmacromynameArrayNames[Z]
        item textcolormycolormyname
        endenumerate
        enddocument


        enter image description here



        As you can see, this function is chosen such that it distinguishes between birds on the one hand and mammals and beings on the other hand.






        share|improve this answer

























        • thank for your quick reply. I know that pgffor in same file.tex can do it. Can you solution/idea set variable array in control file, not in template file? defArrayNames"koala","duck","marmot","penguin","bear" defArrayColors"gray","yellow","blue","red","brown" Thanks

          – tisaigon
          Feb 14 at 2:25






        • 1





          @tisaigon myarrays.tex needs only to have defArrayNames"koala","duck","marmot","penguin","bear" defArrayColors"gray","yellow","blue","red","brown" in it.

          – marmot
          Feb 14 at 4:52






        • 1





          @tisaigon I added a mapping function (the flexibility of adding this very easily may be an advantage of this approach), which you can adjust to your needs.

          – marmot
          Feb 14 at 6:36






        • 1





          @tisaigon What does documentclass[a4paper,twoside,12pt]article usepackagepgffor usepackagexcolor begindocument inputmyarrays.tex pgfmathsetmacromynameArrayNames[3] myname enddocument give you?

          – marmot
          Feb 14 at 7:12






        • 1





          @tisaigon Could you please ask a new question for that. I am just about to go to bed and others will help you more quickly. If you are lucky, Christian Hupfer sees your question, then you will get an excellent answer.

          – marmot
          Feb 14 at 7:47















        6














        You could use pgffor for that.



        documentclass[a4paper,twoside,12pt]article
        usepackagepgffor
        usepackagexcolor
        begindocument
        defArrayNames"koala","duck","marmot","penguin","bear"
        defArrayColors"gray","yellow","blue","red","brown"
        beginenumerate
        foreach X in 0,...,4
        pgfmathsetmacromynameArrayNames[X]
        pgfmathsetmacromycolorArrayColors[X]
        item textcolormycolormyname
        endenumerate
        enddocument


        enter image description here



        Or with an external file (which I create here for the convenience of others in the MWE, but you may drop the filecontents stuff as long you have a data file).



        documentclass[a4paper,twoside,12pt]article
        usepackagefilecontents
        beginfilecontents*myarrays.tex
        defArrayNames"koala","duck","marmot","penguin","bear"
        defArrayColors"gray","yellow","blue","red","brown"
        endfilecontents*
        usepackagepgffor
        usepackagexcolor
        begindocument
        inputmyarrays.tex
        beginenumerate
        foreach X in ArrayNames
        foreach Y [count=Z starting from 0]in X
        pgfmathsetmacromycolorArrayColors[Z]
        pgfmathsetmacromynameArrayNames[Z]
        item textcolormycolormyname
        endenumerate
        enddocument


        And of course you can install any mapping. Here is an example (in which I assume you already have created myarrays.tex, if not uncomment the corresponding lines).



        documentclass[a4paper,twoside,12pt]article
        % usepackagefilecontents
        % beginfilecontents*myarrays.tex
        % defArrayNames"koala","duck","marmot","penguin","bear"
        % defArrayColors"gray","yellow","blue","red","brown"
        % endfilecontents*
        usepackagepgffor
        usepackagexcolor
        begindocument
        inputmyarrays.tex
        pgfkeys/pgf/declare function=mymap(x)=int(mod(1+x*x,4));
        beginenumerate
        foreach X in ArrayNames
        foreach Y [count=Z starting from 0]in X
        pgfmathsetmacromycolorArrayColors[mymap(Z)]
        pgfmathsetmacromynameArrayNames[Z]
        item textcolormycolormyname
        endenumerate
        enddocument


        enter image description here



        As you can see, this function is chosen such that it distinguishes between birds on the one hand and mammals and beings on the other hand.






        share|improve this answer

























        • thank for your quick reply. I know that pgffor in same file.tex can do it. Can you solution/idea set variable array in control file, not in template file? defArrayNames"koala","duck","marmot","penguin","bear" defArrayColors"gray","yellow","blue","red","brown" Thanks

          – tisaigon
          Feb 14 at 2:25






        • 1





          @tisaigon myarrays.tex needs only to have defArrayNames"koala","duck","marmot","penguin","bear" defArrayColors"gray","yellow","blue","red","brown" in it.

          – marmot
          Feb 14 at 4:52






        • 1





          @tisaigon I added a mapping function (the flexibility of adding this very easily may be an advantage of this approach), which you can adjust to your needs.

          – marmot
          Feb 14 at 6:36






        • 1





          @tisaigon What does documentclass[a4paper,twoside,12pt]article usepackagepgffor usepackagexcolor begindocument inputmyarrays.tex pgfmathsetmacromynameArrayNames[3] myname enddocument give you?

          – marmot
          Feb 14 at 7:12






        • 1





          @tisaigon Could you please ask a new question for that. I am just about to go to bed and others will help you more quickly. If you are lucky, Christian Hupfer sees your question, then you will get an excellent answer.

          – marmot
          Feb 14 at 7:47













        6












        6








        6







        You could use pgffor for that.



        documentclass[a4paper,twoside,12pt]article
        usepackagepgffor
        usepackagexcolor
        begindocument
        defArrayNames"koala","duck","marmot","penguin","bear"
        defArrayColors"gray","yellow","blue","red","brown"
        beginenumerate
        foreach X in 0,...,4
        pgfmathsetmacromynameArrayNames[X]
        pgfmathsetmacromycolorArrayColors[X]
        item textcolormycolormyname
        endenumerate
        enddocument


        enter image description here



        Or with an external file (which I create here for the convenience of others in the MWE, but you may drop the filecontents stuff as long you have a data file).



        documentclass[a4paper,twoside,12pt]article
        usepackagefilecontents
        beginfilecontents*myarrays.tex
        defArrayNames"koala","duck","marmot","penguin","bear"
        defArrayColors"gray","yellow","blue","red","brown"
        endfilecontents*
        usepackagepgffor
        usepackagexcolor
        begindocument
        inputmyarrays.tex
        beginenumerate
        foreach X in ArrayNames
        foreach Y [count=Z starting from 0]in X
        pgfmathsetmacromycolorArrayColors[Z]
        pgfmathsetmacromynameArrayNames[Z]
        item textcolormycolormyname
        endenumerate
        enddocument


        And of course you can install any mapping. Here is an example (in which I assume you already have created myarrays.tex, if not uncomment the corresponding lines).



        documentclass[a4paper,twoside,12pt]article
        % usepackagefilecontents
        % beginfilecontents*myarrays.tex
        % defArrayNames"koala","duck","marmot","penguin","bear"
        % defArrayColors"gray","yellow","blue","red","brown"
        % endfilecontents*
        usepackagepgffor
        usepackagexcolor
        begindocument
        inputmyarrays.tex
        pgfkeys/pgf/declare function=mymap(x)=int(mod(1+x*x,4));
        beginenumerate
        foreach X in ArrayNames
        foreach Y [count=Z starting from 0]in X
        pgfmathsetmacromycolorArrayColors[mymap(Z)]
        pgfmathsetmacromynameArrayNames[Z]
        item textcolormycolormyname
        endenumerate
        enddocument


        enter image description here



        As you can see, this function is chosen such that it distinguishes between birds on the one hand and mammals and beings on the other hand.






        share|improve this answer















        You could use pgffor for that.



        documentclass[a4paper,twoside,12pt]article
        usepackagepgffor
        usepackagexcolor
        begindocument
        defArrayNames"koala","duck","marmot","penguin","bear"
        defArrayColors"gray","yellow","blue","red","brown"
        beginenumerate
        foreach X in 0,...,4
        pgfmathsetmacromynameArrayNames[X]
        pgfmathsetmacromycolorArrayColors[X]
        item textcolormycolormyname
        endenumerate
        enddocument


        enter image description here



        Or with an external file (which I create here for the convenience of others in the MWE, but you may drop the filecontents stuff as long you have a data file).



        documentclass[a4paper,twoside,12pt]article
        usepackagefilecontents
        beginfilecontents*myarrays.tex
        defArrayNames"koala","duck","marmot","penguin","bear"
        defArrayColors"gray","yellow","blue","red","brown"
        endfilecontents*
        usepackagepgffor
        usepackagexcolor
        begindocument
        inputmyarrays.tex
        beginenumerate
        foreach X in ArrayNames
        foreach Y [count=Z starting from 0]in X
        pgfmathsetmacromycolorArrayColors[Z]
        pgfmathsetmacromynameArrayNames[Z]
        item textcolormycolormyname
        endenumerate
        enddocument


        And of course you can install any mapping. Here is an example (in which I assume you already have created myarrays.tex, if not uncomment the corresponding lines).



        documentclass[a4paper,twoside,12pt]article
        % usepackagefilecontents
        % beginfilecontents*myarrays.tex
        % defArrayNames"koala","duck","marmot","penguin","bear"
        % defArrayColors"gray","yellow","blue","red","brown"
        % endfilecontents*
        usepackagepgffor
        usepackagexcolor
        begindocument
        inputmyarrays.tex
        pgfkeys/pgf/declare function=mymap(x)=int(mod(1+x*x,4));
        beginenumerate
        foreach X in ArrayNames
        foreach Y [count=Z starting from 0]in X
        pgfmathsetmacromycolorArrayColors[mymap(Z)]
        pgfmathsetmacromynameArrayNames[Z]
        item textcolormycolormyname
        endenumerate
        enddocument


        enter image description here



        As you can see, this function is chosen such that it distinguishes between birds on the one hand and mammals and beings on the other hand.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Feb 14 at 6:35

























        answered Feb 14 at 2:22









        marmotmarmot

        107k5129243




        107k5129243












        • thank for your quick reply. I know that pgffor in same file.tex can do it. Can you solution/idea set variable array in control file, not in template file? defArrayNames"koala","duck","marmot","penguin","bear" defArrayColors"gray","yellow","blue","red","brown" Thanks

          – tisaigon
          Feb 14 at 2:25






        • 1





          @tisaigon myarrays.tex needs only to have defArrayNames"koala","duck","marmot","penguin","bear" defArrayColors"gray","yellow","blue","red","brown" in it.

          – marmot
          Feb 14 at 4:52






        • 1





          @tisaigon I added a mapping function (the flexibility of adding this very easily may be an advantage of this approach), which you can adjust to your needs.

          – marmot
          Feb 14 at 6:36






        • 1





          @tisaigon What does documentclass[a4paper,twoside,12pt]article usepackagepgffor usepackagexcolor begindocument inputmyarrays.tex pgfmathsetmacromynameArrayNames[3] myname enddocument give you?

          – marmot
          Feb 14 at 7:12






        • 1





          @tisaigon Could you please ask a new question for that. I am just about to go to bed and others will help you more quickly. If you are lucky, Christian Hupfer sees your question, then you will get an excellent answer.

          – marmot
          Feb 14 at 7:47

















        • thank for your quick reply. I know that pgffor in same file.tex can do it. Can you solution/idea set variable array in control file, not in template file? defArrayNames"koala","duck","marmot","penguin","bear" defArrayColors"gray","yellow","blue","red","brown" Thanks

          – tisaigon
          Feb 14 at 2:25






        • 1





          @tisaigon myarrays.tex needs only to have defArrayNames"koala","duck","marmot","penguin","bear" defArrayColors"gray","yellow","blue","red","brown" in it.

          – marmot
          Feb 14 at 4:52






        • 1





          @tisaigon I added a mapping function (the flexibility of adding this very easily may be an advantage of this approach), which you can adjust to your needs.

          – marmot
          Feb 14 at 6:36






        • 1





          @tisaigon What does documentclass[a4paper,twoside,12pt]article usepackagepgffor usepackagexcolor begindocument inputmyarrays.tex pgfmathsetmacromynameArrayNames[3] myname enddocument give you?

          – marmot
          Feb 14 at 7:12






        • 1





          @tisaigon Could you please ask a new question for that. I am just about to go to bed and others will help you more quickly. If you are lucky, Christian Hupfer sees your question, then you will get an excellent answer.

          – marmot
          Feb 14 at 7:47
















        thank for your quick reply. I know that pgffor in same file.tex can do it. Can you solution/idea set variable array in control file, not in template file? defArrayNames"koala","duck","marmot","penguin","bear" defArrayColors"gray","yellow","blue","red","brown" Thanks

        – tisaigon
        Feb 14 at 2:25





        thank for your quick reply. I know that pgffor in same file.tex can do it. Can you solution/idea set variable array in control file, not in template file? defArrayNames"koala","duck","marmot","penguin","bear" defArrayColors"gray","yellow","blue","red","brown" Thanks

        – tisaigon
        Feb 14 at 2:25




        1




        1





        @tisaigon myarrays.tex needs only to have defArrayNames"koala","duck","marmot","penguin","bear" defArrayColors"gray","yellow","blue","red","brown" in it.

        – marmot
        Feb 14 at 4:52





        @tisaigon myarrays.tex needs only to have defArrayNames"koala","duck","marmot","penguin","bear" defArrayColors"gray","yellow","blue","red","brown" in it.

        – marmot
        Feb 14 at 4:52




        1




        1





        @tisaigon I added a mapping function (the flexibility of adding this very easily may be an advantage of this approach), which you can adjust to your needs.

        – marmot
        Feb 14 at 6:36





        @tisaigon I added a mapping function (the flexibility of adding this very easily may be an advantage of this approach), which you can adjust to your needs.

        – marmot
        Feb 14 at 6:36




        1




        1





        @tisaigon What does documentclass[a4paper,twoside,12pt]article usepackagepgffor usepackagexcolor begindocument inputmyarrays.tex pgfmathsetmacromynameArrayNames[3] myname enddocument give you?

        – marmot
        Feb 14 at 7:12





        @tisaigon What does documentclass[a4paper,twoside,12pt]article usepackagepgffor usepackagexcolor begindocument inputmyarrays.tex pgfmathsetmacromynameArrayNames[3] myname enddocument give you?

        – marmot
        Feb 14 at 7:12




        1




        1





        @tisaigon Could you please ask a new question for that. I am just about to go to bed and others will help you more quickly. If you are lucky, Christian Hupfer sees your question, then you will get an excellent answer.

        – marmot
        Feb 14 at 7:47





        @tisaigon Could you please ask a new question for that. I am just about to go to bed and others will help you more quickly. If you are lucky, Christian Hupfer sees your question, then you will get an excellent answer.

        – marmot
        Feb 14 at 7:47











        3














        Trivial with listofitems.



        documentclassarticle
        usepackagelistofitems,xcolor
        newcommandArrayNamesName1,Name2,N3,N4,N5,N6,N7,N8,N9,Name10
        newcommandArrayColorsred,blue,cyan,cyan!50!red,red!50,
        purple,green,yellow,blue!50,magenta
        readlist*arraynameArrayNames
        readlist*arraycolorArrayColors
        begindocument
        beginenumerate
        foreachitemxinarraynameitem textcolorarraycolor[xcnt]x
        endenumerate

        textcolorarraycolor[4]arrayname[9]

        textcolorarraycolor[5]arrayname[8]
        enddocument


        enter image description here






        share|improve this answer



























          3














          Trivial with listofitems.



          documentclassarticle
          usepackagelistofitems,xcolor
          newcommandArrayNamesName1,Name2,N3,N4,N5,N6,N7,N8,N9,Name10
          newcommandArrayColorsred,blue,cyan,cyan!50!red,red!50,
          purple,green,yellow,blue!50,magenta
          readlist*arraynameArrayNames
          readlist*arraycolorArrayColors
          begindocument
          beginenumerate
          foreachitemxinarraynameitem textcolorarraycolor[xcnt]x
          endenumerate

          textcolorarraycolor[4]arrayname[9]

          textcolorarraycolor[5]arrayname[8]
          enddocument


          enter image description here






          share|improve this answer

























            3












            3








            3







            Trivial with listofitems.



            documentclassarticle
            usepackagelistofitems,xcolor
            newcommandArrayNamesName1,Name2,N3,N4,N5,N6,N7,N8,N9,Name10
            newcommandArrayColorsred,blue,cyan,cyan!50!red,red!50,
            purple,green,yellow,blue!50,magenta
            readlist*arraynameArrayNames
            readlist*arraycolorArrayColors
            begindocument
            beginenumerate
            foreachitemxinarraynameitem textcolorarraycolor[xcnt]x
            endenumerate

            textcolorarraycolor[4]arrayname[9]

            textcolorarraycolor[5]arrayname[8]
            enddocument


            enter image description here






            share|improve this answer













            Trivial with listofitems.



            documentclassarticle
            usepackagelistofitems,xcolor
            newcommandArrayNamesName1,Name2,N3,N4,N5,N6,N7,N8,N9,Name10
            newcommandArrayColorsred,blue,cyan,cyan!50!red,red!50,
            purple,green,yellow,blue!50,magenta
            readlist*arraynameArrayNames
            readlist*arraycolorArrayColors
            begindocument
            beginenumerate
            foreachitemxinarraynameitem textcolorarraycolor[xcnt]x
            endenumerate

            textcolorarraycolor[4]arrayname[9]

            textcolorarraycolor[5]arrayname[8]
            enddocument


            enter image description here







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Feb 14 at 2:49









            Steven B. SegletesSteven B. Segletes

            157k9204411




            157k9204411





















                3














                You can have files with the following structure



                colorlist
                red
                green
                blue
                green!40!yellow
                -green!40!yellow
                rgb:-green!40!yellow,3;green!40!yellow,2;red,1
                red>wheel,12



                It would also be possible to have the simpler structure



                red
                green
                blue
                green!40!yellow


                - green!40!yellow
                rgb:-green!40!yellow,3;green!40!yellow,2;red,1
                red>wheel,12



                if preferred. Then in the document you call



                assigncolors<filename><list of names for the colors>


                Here's the code, using filecontents for making the example self-contained; the name for the color list file can be whatever you prefer.



                beginfilecontentsjobname.colors
                colorlist
                red
                green
                blue
                green!40!yellow
                -green!40!yellow
                rgb:-green!40!yellow,3;green!40!yellow,2;red,1
                red>wheel,12

                endfilecontents

                documentclassarticle
                usepackagexcolor
                usepackagexparse

                ExplSyntaxOn
                NewDocumentCommandassigncolorsmm
                % #1 = file name, #2 = list of names
                clist_set:Nn l__tisaigon_colornames_clist #2
                file_input:n #1

                NewDocumentCommandcolorlistm

                int_zero:N l__tisaigon_colornames_int
                tl_map_inline:nn #1

                int_incr:N l__tisaigon_colornames_int
                colorlet

                clist_item:Nn l__tisaigon_colornames_clist l__tisaigon_colornames_int


                ##1



                clist_new:N l__tisaigon_colornames_clist
                int_new:N l__tisaigon_colornames_int
                ExplSyntaxOff

                assigncolorsjobname.colors
                color1,
                color2,
                color3,
                header,
                body,
                footer,
                fancy,


                begindocument

                textcolorcolor1Abc

                textcolorcolor2Abc

                textcolorcolor3Abc

                textcolorheaderAbc

                textcolorbodyAbc

                textcolorfooterAbc

                textcolorfancyAbc

                enddocument


                enter image description here






                share|improve this answer



























                  3














                  You can have files with the following structure



                  colorlist
                  red
                  green
                  blue
                  green!40!yellow
                  -green!40!yellow
                  rgb:-green!40!yellow,3;green!40!yellow,2;red,1
                  red>wheel,12



                  It would also be possible to have the simpler structure



                  red
                  green
                  blue
                  green!40!yellow


                  - green!40!yellow
                  rgb:-green!40!yellow,3;green!40!yellow,2;red,1
                  red>wheel,12



                  if preferred. Then in the document you call



                  assigncolors<filename><list of names for the colors>


                  Here's the code, using filecontents for making the example self-contained; the name for the color list file can be whatever you prefer.



                  beginfilecontentsjobname.colors
                  colorlist
                  red
                  green
                  blue
                  green!40!yellow
                  -green!40!yellow
                  rgb:-green!40!yellow,3;green!40!yellow,2;red,1
                  red>wheel,12

                  endfilecontents

                  documentclassarticle
                  usepackagexcolor
                  usepackagexparse

                  ExplSyntaxOn
                  NewDocumentCommandassigncolorsmm
                  % #1 = file name, #2 = list of names
                  clist_set:Nn l__tisaigon_colornames_clist #2
                  file_input:n #1

                  NewDocumentCommandcolorlistm

                  int_zero:N l__tisaigon_colornames_int
                  tl_map_inline:nn #1

                  int_incr:N l__tisaigon_colornames_int
                  colorlet

                  clist_item:Nn l__tisaigon_colornames_clist l__tisaigon_colornames_int


                  ##1



                  clist_new:N l__tisaigon_colornames_clist
                  int_new:N l__tisaigon_colornames_int
                  ExplSyntaxOff

                  assigncolorsjobname.colors
                  color1,
                  color2,
                  color3,
                  header,
                  body,
                  footer,
                  fancy,


                  begindocument

                  textcolorcolor1Abc

                  textcolorcolor2Abc

                  textcolorcolor3Abc

                  textcolorheaderAbc

                  textcolorbodyAbc

                  textcolorfooterAbc

                  textcolorfancyAbc

                  enddocument


                  enter image description here






                  share|improve this answer

























                    3












                    3








                    3







                    You can have files with the following structure



                    colorlist
                    red
                    green
                    blue
                    green!40!yellow
                    -green!40!yellow
                    rgb:-green!40!yellow,3;green!40!yellow,2;red,1
                    red>wheel,12



                    It would also be possible to have the simpler structure



                    red
                    green
                    blue
                    green!40!yellow


                    - green!40!yellow
                    rgb:-green!40!yellow,3;green!40!yellow,2;red,1
                    red>wheel,12



                    if preferred. Then in the document you call



                    assigncolors<filename><list of names for the colors>


                    Here's the code, using filecontents for making the example self-contained; the name for the color list file can be whatever you prefer.



                    beginfilecontentsjobname.colors
                    colorlist
                    red
                    green
                    blue
                    green!40!yellow
                    -green!40!yellow
                    rgb:-green!40!yellow,3;green!40!yellow,2;red,1
                    red>wheel,12

                    endfilecontents

                    documentclassarticle
                    usepackagexcolor
                    usepackagexparse

                    ExplSyntaxOn
                    NewDocumentCommandassigncolorsmm
                    % #1 = file name, #2 = list of names
                    clist_set:Nn l__tisaigon_colornames_clist #2
                    file_input:n #1

                    NewDocumentCommandcolorlistm

                    int_zero:N l__tisaigon_colornames_int
                    tl_map_inline:nn #1

                    int_incr:N l__tisaigon_colornames_int
                    colorlet

                    clist_item:Nn l__tisaigon_colornames_clist l__tisaigon_colornames_int


                    ##1



                    clist_new:N l__tisaigon_colornames_clist
                    int_new:N l__tisaigon_colornames_int
                    ExplSyntaxOff

                    assigncolorsjobname.colors
                    color1,
                    color2,
                    color3,
                    header,
                    body,
                    footer,
                    fancy,


                    begindocument

                    textcolorcolor1Abc

                    textcolorcolor2Abc

                    textcolorcolor3Abc

                    textcolorheaderAbc

                    textcolorbodyAbc

                    textcolorfooterAbc

                    textcolorfancyAbc

                    enddocument


                    enter image description here






                    share|improve this answer













                    You can have files with the following structure



                    colorlist
                    red
                    green
                    blue
                    green!40!yellow
                    -green!40!yellow
                    rgb:-green!40!yellow,3;green!40!yellow,2;red,1
                    red>wheel,12



                    It would also be possible to have the simpler structure



                    red
                    green
                    blue
                    green!40!yellow


                    - green!40!yellow
                    rgb:-green!40!yellow,3;green!40!yellow,2;red,1
                    red>wheel,12



                    if preferred. Then in the document you call



                    assigncolors<filename><list of names for the colors>


                    Here's the code, using filecontents for making the example self-contained; the name for the color list file can be whatever you prefer.



                    beginfilecontentsjobname.colors
                    colorlist
                    red
                    green
                    blue
                    green!40!yellow
                    -green!40!yellow
                    rgb:-green!40!yellow,3;green!40!yellow,2;red,1
                    red>wheel,12

                    endfilecontents

                    documentclassarticle
                    usepackagexcolor
                    usepackagexparse

                    ExplSyntaxOn
                    NewDocumentCommandassigncolorsmm
                    % #1 = file name, #2 = list of names
                    clist_set:Nn l__tisaigon_colornames_clist #2
                    file_input:n #1

                    NewDocumentCommandcolorlistm

                    int_zero:N l__tisaigon_colornames_int
                    tl_map_inline:nn #1

                    int_incr:N l__tisaigon_colornames_int
                    colorlet

                    clist_item:Nn l__tisaigon_colornames_clist l__tisaigon_colornames_int


                    ##1



                    clist_new:N l__tisaigon_colornames_clist
                    int_new:N l__tisaigon_colornames_int
                    ExplSyntaxOff

                    assigncolorsjobname.colors
                    color1,
                    color2,
                    color3,
                    header,
                    body,
                    footer,
                    fancy,


                    begindocument

                    textcolorcolor1Abc

                    textcolorcolor2Abc

                    textcolorcolor3Abc

                    textcolorheaderAbc

                    textcolorbodyAbc

                    textcolorfooterAbc

                    textcolorfancyAbc

                    enddocument


                    enter image description here







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Feb 14 at 10:51









                    egregegreg

                    725k8819193224




                    725k8819193224





















                        2














                        In a very simplistic way you can place a number of color definitions using (say) colorletcolorX<colour> inside color_array.tex and load them within the document preamble:



                        enter image description here



                        documentclassarticle

                        % Just for this example, create control_array.tex that contains all the colour definitions
                        usepackagefilecontents
                        beginfilecontents*control_array.tex
                        usepackagexcolor
                        colorletcolor1blue
                        colorletcolor2green
                        colorletcolor3red!30!yellow
                        colorletcolor4rgb:black,1;red,2;orange,3
                        colorletcolor5black!50
                        endfilecontents*

                        inputcontrol_array% Input colour definitions

                        begindocument

                        beginenumerate
                        item textcolorcolor1Name1
                        item textcolorcolor2Name2
                        item textcolorcolor3Name3
                        endenumerate

                        textcolorcolor4Name9

                        textcolorcolor5Name8

                        enddocument


                        Note that inputcolor_array is called within the preamble since color_array.tex includes a call to load xcolor which can only be called within the preamble.






                        share|improve this answer



























                          2














                          In a very simplistic way you can place a number of color definitions using (say) colorletcolorX<colour> inside color_array.tex and load them within the document preamble:



                          enter image description here



                          documentclassarticle

                          % Just for this example, create control_array.tex that contains all the colour definitions
                          usepackagefilecontents
                          beginfilecontents*control_array.tex
                          usepackagexcolor
                          colorletcolor1blue
                          colorletcolor2green
                          colorletcolor3red!30!yellow
                          colorletcolor4rgb:black,1;red,2;orange,3
                          colorletcolor5black!50
                          endfilecontents*

                          inputcontrol_array% Input colour definitions

                          begindocument

                          beginenumerate
                          item textcolorcolor1Name1
                          item textcolorcolor2Name2
                          item textcolorcolor3Name3
                          endenumerate

                          textcolorcolor4Name9

                          textcolorcolor5Name8

                          enddocument


                          Note that inputcolor_array is called within the preamble since color_array.tex includes a call to load xcolor which can only be called within the preamble.






                          share|improve this answer

























                            2












                            2








                            2







                            In a very simplistic way you can place a number of color definitions using (say) colorletcolorX<colour> inside color_array.tex and load them within the document preamble:



                            enter image description here



                            documentclassarticle

                            % Just for this example, create control_array.tex that contains all the colour definitions
                            usepackagefilecontents
                            beginfilecontents*control_array.tex
                            usepackagexcolor
                            colorletcolor1blue
                            colorletcolor2green
                            colorletcolor3red!30!yellow
                            colorletcolor4rgb:black,1;red,2;orange,3
                            colorletcolor5black!50
                            endfilecontents*

                            inputcontrol_array% Input colour definitions

                            begindocument

                            beginenumerate
                            item textcolorcolor1Name1
                            item textcolorcolor2Name2
                            item textcolorcolor3Name3
                            endenumerate

                            textcolorcolor4Name9

                            textcolorcolor5Name8

                            enddocument


                            Note that inputcolor_array is called within the preamble since color_array.tex includes a call to load xcolor which can only be called within the preamble.






                            share|improve this answer













                            In a very simplistic way you can place a number of color definitions using (say) colorletcolorX<colour> inside color_array.tex and load them within the document preamble:



                            enter image description here



                            documentclassarticle

                            % Just for this example, create control_array.tex that contains all the colour definitions
                            usepackagefilecontents
                            beginfilecontents*control_array.tex
                            usepackagexcolor
                            colorletcolor1blue
                            colorletcolor2green
                            colorletcolor3red!30!yellow
                            colorletcolor4rgb:black,1;red,2;orange,3
                            colorletcolor5black!50
                            endfilecontents*

                            inputcontrol_array% Input colour definitions

                            begindocument

                            beginenumerate
                            item textcolorcolor1Name1
                            item textcolorcolor2Name2
                            item textcolorcolor3Name3
                            endenumerate

                            textcolorcolor4Name9

                            textcolorcolor5Name8

                            enddocument


                            Note that inputcolor_array is called within the preamble since color_array.tex includes a call to load xcolor which can only be called within the preamble.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Feb 14 at 2:51









                            WernerWerner

                            447k699891693




                            447k699891693



























                                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%2f474792%2fglobal-variable-array%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

                                How to check contact read email or not when send email to Individual?

                                Bahrain

                                Postfix configuration issue with fips on centos 7; mailgun relay