Global variable Array












3















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}
usepackage{xcolor}
begin{document}
%Call Name1, Nam10...Color 1, Color2...Color10
begin{enumerate}
item textcolor{color1}{Name1}
item textcolor{color2}{Name2}
item textcolor{color3}{Name3}
end{enumerate}
textcolor{color4}{Name9} \
textcolor{color5}{Name8}
end{document}


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










share|improve this question





























    3















    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}
    usepackage{xcolor}
    begin{document}
    %Call Name1, Nam10...Color 1, Color2...Color10
    begin{enumerate}
    item textcolor{color1}{Name1}
    item textcolor{color2}{Name2}
    item textcolor{color3}{Name3}
    end{enumerate}
    textcolor{color4}{Name9} \
    textcolor{color5}{Name8}
    end{document}


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










    share|improve this question



























      3












      3








      3








      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}
      usepackage{xcolor}
      begin{document}
      %Call Name1, Nam10...Color 1, Color2...Color10
      begin{enumerate}
      item textcolor{color1}{Name1}
      item textcolor{color2}{Name2}
      item textcolor{color3}{Name3}
      end{enumerate}
      textcolor{color4}{Name9} \
      textcolor{color5}{Name8}
      end{document}


      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}
      usepackage{xcolor}
      begin{document}
      %Call Name1, Nam10...Color 1, Color2...Color10
      begin{enumerate}
      item textcolor{color1}{Name1}
      item textcolor{color2}{Name2}
      item textcolor{color3}{Name3}
      end{enumerate}
      textcolor{color4}{Name9} \
      textcolor{color5}{Name8}
      end{document}


      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 38 mins ago









      Werner

      444k689791680




      444k689791680










      asked 1 hour ago









      tisaigontisaigon

      1217




      1217






















          3 Answers
          3






          active

          oldest

          votes


















          2














          You could use pgffor for that.



          documentclass[a4paper,twoside,12pt]{article}
          usepackage{pgffor}
          usepackage{xcolor}
          begin{document}
          defArrayNames{{"koala","duck","marmot","penguin","bear"}}
          defArrayColors{{"gray","yellow","blue","red","brown"}}
          begin{enumerate}
          foreach X in {0,...,4}
          {pgfmathsetmacro{myname}{ArrayNames[X]}
          pgfmathsetmacro{mycolor}{ArrayColors[X]}
          item textcolor{mycolor}{myname}}
          end{enumerate}
          end{document}


          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}
          usepackage{filecontents}
          begin{filecontents*}{myarrays.tex}
          defArrayNames{{"koala","duck","marmot","penguin","bear"}}
          defArrayColors{{"gray","yellow","blue","red","brown"}}
          end{filecontents*}
          usepackage{pgffor}
          usepackage{xcolor}
          begin{document}
          input{myarrays.tex}
          begin{enumerate}
          foreach X in ArrayNames
          {foreach Y [count=Z starting from 0]in X
          {pgfmathsetmacro{mycolor}{ArrayColors[Z]}
          pgfmathsetmacro{myname}{ArrayNames[Z]}
          item textcolor{mycolor}{myname}}}
          end{enumerate}
          end{document}





          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
            1 hour ago











          • and some situation, please not use "For each", example: textcolor{color4}{Name9} \ textcolor{color5}{Name8}. thanks

            – tisaigon
            1 hour ago













          • @tisaigon I do not understand your last requests. Could you please try to be more specific? Note, however, that I added a proposal that loads an external file.

            – marmot
            57 mins ago



















          1














          Trivial with listofitems.



          documentclass{article}
          usepackage{listofitems,xcolor}
          newcommandArrayNames{Name1,Name2,N3,N4,N5,N6,N7,N8,N9,Name10}
          newcommandArrayColors{red,blue,cyan,cyan!50!red,red!50,
          purple,green,yellow,blue!50,magenta}
          readlist*arrayname{ArrayNames}
          readlist*arraycolor{ArrayColors}
          begin{document}
          begin{enumerate}
          foreachitemxinarrayname{item textcolor{arraycolor[xcnt]}{x}}
          end{enumerate}

          textcolor{arraycolor[4]}{arrayname[9]}

          textcolor{arraycolor[5]}{arrayname[8]}
          end{document}


          enter image description here






          share|improve this answer































            0














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



            enter image description here



            documentclass{article}

            % Just for this example, create control_array.tex that contains all the colour definitions
            usepackage{filecontents}
            begin{filecontents*}{control_array.tex}
            usepackage{xcolor}
            colorlet{color1}{blue}
            colorlet{color2}{green}
            colorlet{color3}{red!30!yellow}
            colorlet{color4}{rgb:black,1;red,2;orange,3}
            colorlet{color5}{black!50}
            end{filecontents*}

            input{control_array}% Input colour definitions

            begin{document}

            begin{enumerate}
            item textcolor{color1}{Name1}
            item textcolor{color2}{Name2}
            item textcolor{color3}{Name3}
            end{enumerate}

            textcolor{color4}{Name9}

            textcolor{color5}{Name8}

            end{document}


            Note that input{color_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

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              2














              You could use pgffor for that.



              documentclass[a4paper,twoside,12pt]{article}
              usepackage{pgffor}
              usepackage{xcolor}
              begin{document}
              defArrayNames{{"koala","duck","marmot","penguin","bear"}}
              defArrayColors{{"gray","yellow","blue","red","brown"}}
              begin{enumerate}
              foreach X in {0,...,4}
              {pgfmathsetmacro{myname}{ArrayNames[X]}
              pgfmathsetmacro{mycolor}{ArrayColors[X]}
              item textcolor{mycolor}{myname}}
              end{enumerate}
              end{document}


              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}
              usepackage{filecontents}
              begin{filecontents*}{myarrays.tex}
              defArrayNames{{"koala","duck","marmot","penguin","bear"}}
              defArrayColors{{"gray","yellow","blue","red","brown"}}
              end{filecontents*}
              usepackage{pgffor}
              usepackage{xcolor}
              begin{document}
              input{myarrays.tex}
              begin{enumerate}
              foreach X in ArrayNames
              {foreach Y [count=Z starting from 0]in X
              {pgfmathsetmacro{mycolor}{ArrayColors[Z]}
              pgfmathsetmacro{myname}{ArrayNames[Z]}
              item textcolor{mycolor}{myname}}}
              end{enumerate}
              end{document}





              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
                1 hour ago











              • and some situation, please not use "For each", example: textcolor{color4}{Name9} \ textcolor{color5}{Name8}. thanks

                – tisaigon
                1 hour ago













              • @tisaigon I do not understand your last requests. Could you please try to be more specific? Note, however, that I added a proposal that loads an external file.

                – marmot
                57 mins ago
















              2














              You could use pgffor for that.



              documentclass[a4paper,twoside,12pt]{article}
              usepackage{pgffor}
              usepackage{xcolor}
              begin{document}
              defArrayNames{{"koala","duck","marmot","penguin","bear"}}
              defArrayColors{{"gray","yellow","blue","red","brown"}}
              begin{enumerate}
              foreach X in {0,...,4}
              {pgfmathsetmacro{myname}{ArrayNames[X]}
              pgfmathsetmacro{mycolor}{ArrayColors[X]}
              item textcolor{mycolor}{myname}}
              end{enumerate}
              end{document}


              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}
              usepackage{filecontents}
              begin{filecontents*}{myarrays.tex}
              defArrayNames{{"koala","duck","marmot","penguin","bear"}}
              defArrayColors{{"gray","yellow","blue","red","brown"}}
              end{filecontents*}
              usepackage{pgffor}
              usepackage{xcolor}
              begin{document}
              input{myarrays.tex}
              begin{enumerate}
              foreach X in ArrayNames
              {foreach Y [count=Z starting from 0]in X
              {pgfmathsetmacro{mycolor}{ArrayColors[Z]}
              pgfmathsetmacro{myname}{ArrayNames[Z]}
              item textcolor{mycolor}{myname}}}
              end{enumerate}
              end{document}





              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
                1 hour ago











              • and some situation, please not use "For each", example: textcolor{color4}{Name9} \ textcolor{color5}{Name8}. thanks

                – tisaigon
                1 hour ago













              • @tisaigon I do not understand your last requests. Could you please try to be more specific? Note, however, that I added a proposal that loads an external file.

                – marmot
                57 mins ago














              2












              2








              2







              You could use pgffor for that.



              documentclass[a4paper,twoside,12pt]{article}
              usepackage{pgffor}
              usepackage{xcolor}
              begin{document}
              defArrayNames{{"koala","duck","marmot","penguin","bear"}}
              defArrayColors{{"gray","yellow","blue","red","brown"}}
              begin{enumerate}
              foreach X in {0,...,4}
              {pgfmathsetmacro{myname}{ArrayNames[X]}
              pgfmathsetmacro{mycolor}{ArrayColors[X]}
              item textcolor{mycolor}{myname}}
              end{enumerate}
              end{document}


              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}
              usepackage{filecontents}
              begin{filecontents*}{myarrays.tex}
              defArrayNames{{"koala","duck","marmot","penguin","bear"}}
              defArrayColors{{"gray","yellow","blue","red","brown"}}
              end{filecontents*}
              usepackage{pgffor}
              usepackage{xcolor}
              begin{document}
              input{myarrays.tex}
              begin{enumerate}
              foreach X in ArrayNames
              {foreach Y [count=Z starting from 0]in X
              {pgfmathsetmacro{mycolor}{ArrayColors[Z]}
              pgfmathsetmacro{myname}{ArrayNames[Z]}
              item textcolor{mycolor}{myname}}}
              end{enumerate}
              end{document}





              share|improve this answer















              You could use pgffor for that.



              documentclass[a4paper,twoside,12pt]{article}
              usepackage{pgffor}
              usepackage{xcolor}
              begin{document}
              defArrayNames{{"koala","duck","marmot","penguin","bear"}}
              defArrayColors{{"gray","yellow","blue","red","brown"}}
              begin{enumerate}
              foreach X in {0,...,4}
              {pgfmathsetmacro{myname}{ArrayNames[X]}
              pgfmathsetmacro{mycolor}{ArrayColors[X]}
              item textcolor{mycolor}{myname}}
              end{enumerate}
              end{document}


              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}
              usepackage{filecontents}
              begin{filecontents*}{myarrays.tex}
              defArrayNames{{"koala","duck","marmot","penguin","bear"}}
              defArrayColors{{"gray","yellow","blue","red","brown"}}
              end{filecontents*}
              usepackage{pgffor}
              usepackage{xcolor}
              begin{document}
              input{myarrays.tex}
              begin{enumerate}
              foreach X in ArrayNames
              {foreach Y [count=Z starting from 0]in X
              {pgfmathsetmacro{mycolor}{ArrayColors[Z]}
              pgfmathsetmacro{myname}{ArrayNames[Z]}
              item textcolor{mycolor}{myname}}}
              end{enumerate}
              end{document}






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited 58 mins ago

























              answered 1 hour ago









              marmotmarmot

              99.7k4115220




              99.7k4115220













              • 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
                1 hour ago











              • and some situation, please not use "For each", example: textcolor{color4}{Name9} \ textcolor{color5}{Name8}. thanks

                – tisaigon
                1 hour ago













              • @tisaigon I do not understand your last requests. Could you please try to be more specific? Note, however, that I added a proposal that loads an external file.

                – marmot
                57 mins ago



















              • 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
                1 hour ago











              • and some situation, please not use "For each", example: textcolor{color4}{Name9} \ textcolor{color5}{Name8}. thanks

                – tisaigon
                1 hour ago













              • @tisaigon I do not understand your last requests. Could you please try to be more specific? Note, however, that I added a proposal that loads an external file.

                – marmot
                57 mins ago

















              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
              1 hour ago





              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
              1 hour ago













              and some situation, please not use "For each", example: textcolor{color4}{Name9} \ textcolor{color5}{Name8}. thanks

              – tisaigon
              1 hour ago







              and some situation, please not use "For each", example: textcolor{color4}{Name9} \ textcolor{color5}{Name8}. thanks

              – tisaigon
              1 hour ago















              @tisaigon I do not understand your last requests. Could you please try to be more specific? Note, however, that I added a proposal that loads an external file.

              – marmot
              57 mins ago





              @tisaigon I do not understand your last requests. Could you please try to be more specific? Note, however, that I added a proposal that loads an external file.

              – marmot
              57 mins ago











              1














              Trivial with listofitems.



              documentclass{article}
              usepackage{listofitems,xcolor}
              newcommandArrayNames{Name1,Name2,N3,N4,N5,N6,N7,N8,N9,Name10}
              newcommandArrayColors{red,blue,cyan,cyan!50!red,red!50,
              purple,green,yellow,blue!50,magenta}
              readlist*arrayname{ArrayNames}
              readlist*arraycolor{ArrayColors}
              begin{document}
              begin{enumerate}
              foreachitemxinarrayname{item textcolor{arraycolor[xcnt]}{x}}
              end{enumerate}

              textcolor{arraycolor[4]}{arrayname[9]}

              textcolor{arraycolor[5]}{arrayname[8]}
              end{document}


              enter image description here






              share|improve this answer




























                1














                Trivial with listofitems.



                documentclass{article}
                usepackage{listofitems,xcolor}
                newcommandArrayNames{Name1,Name2,N3,N4,N5,N6,N7,N8,N9,Name10}
                newcommandArrayColors{red,blue,cyan,cyan!50!red,red!50,
                purple,green,yellow,blue!50,magenta}
                readlist*arrayname{ArrayNames}
                readlist*arraycolor{ArrayColors}
                begin{document}
                begin{enumerate}
                foreachitemxinarrayname{item textcolor{arraycolor[xcnt]}{x}}
                end{enumerate}

                textcolor{arraycolor[4]}{arrayname[9]}

                textcolor{arraycolor[5]}{arrayname[8]}
                end{document}


                enter image description here






                share|improve this answer


























                  1












                  1








                  1







                  Trivial with listofitems.



                  documentclass{article}
                  usepackage{listofitems,xcolor}
                  newcommandArrayNames{Name1,Name2,N3,N4,N5,N6,N7,N8,N9,Name10}
                  newcommandArrayColors{red,blue,cyan,cyan!50!red,red!50,
                  purple,green,yellow,blue!50,magenta}
                  readlist*arrayname{ArrayNames}
                  readlist*arraycolor{ArrayColors}
                  begin{document}
                  begin{enumerate}
                  foreachitemxinarrayname{item textcolor{arraycolor[xcnt]}{x}}
                  end{enumerate}

                  textcolor{arraycolor[4]}{arrayname[9]}

                  textcolor{arraycolor[5]}{arrayname[8]}
                  end{document}


                  enter image description here






                  share|improve this answer













                  Trivial with listofitems.



                  documentclass{article}
                  usepackage{listofitems,xcolor}
                  newcommandArrayNames{Name1,Name2,N3,N4,N5,N6,N7,N8,N9,Name10}
                  newcommandArrayColors{red,blue,cyan,cyan!50!red,red!50,
                  purple,green,yellow,blue!50,magenta}
                  readlist*arrayname{ArrayNames}
                  readlist*arraycolor{ArrayColors}
                  begin{document}
                  begin{enumerate}
                  foreachitemxinarrayname{item textcolor{arraycolor[xcnt]}{x}}
                  end{enumerate}

                  textcolor{arraycolor[4]}{arrayname[9]}

                  textcolor{arraycolor[5]}{arrayname[8]}
                  end{document}


                  enter image description here







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 41 mins ago









                  Steven B. SegletesSteven B. Segletes

                  155k9199407




                  155k9199407























                      0














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



                      enter image description here



                      documentclass{article}

                      % Just for this example, create control_array.tex that contains all the colour definitions
                      usepackage{filecontents}
                      begin{filecontents*}{control_array.tex}
                      usepackage{xcolor}
                      colorlet{color1}{blue}
                      colorlet{color2}{green}
                      colorlet{color3}{red!30!yellow}
                      colorlet{color4}{rgb:black,1;red,2;orange,3}
                      colorlet{color5}{black!50}
                      end{filecontents*}

                      input{control_array}% Input colour definitions

                      begin{document}

                      begin{enumerate}
                      item textcolor{color1}{Name1}
                      item textcolor{color2}{Name2}
                      item textcolor{color3}{Name3}
                      end{enumerate}

                      textcolor{color4}{Name9}

                      textcolor{color5}{Name8}

                      end{document}


                      Note that input{color_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




























                        0














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



                        enter image description here



                        documentclass{article}

                        % Just for this example, create control_array.tex that contains all the colour definitions
                        usepackage{filecontents}
                        begin{filecontents*}{control_array.tex}
                        usepackage{xcolor}
                        colorlet{color1}{blue}
                        colorlet{color2}{green}
                        colorlet{color3}{red!30!yellow}
                        colorlet{color4}{rgb:black,1;red,2;orange,3}
                        colorlet{color5}{black!50}
                        end{filecontents*}

                        input{control_array}% Input colour definitions

                        begin{document}

                        begin{enumerate}
                        item textcolor{color1}{Name1}
                        item textcolor{color2}{Name2}
                        item textcolor{color3}{Name3}
                        end{enumerate}

                        textcolor{color4}{Name9}

                        textcolor{color5}{Name8}

                        end{document}


                        Note that input{color_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


























                          0












                          0








                          0







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



                          enter image description here



                          documentclass{article}

                          % Just for this example, create control_array.tex that contains all the colour definitions
                          usepackage{filecontents}
                          begin{filecontents*}{control_array.tex}
                          usepackage{xcolor}
                          colorlet{color1}{blue}
                          colorlet{color2}{green}
                          colorlet{color3}{red!30!yellow}
                          colorlet{color4}{rgb:black,1;red,2;orange,3}
                          colorlet{color5}{black!50}
                          end{filecontents*}

                          input{control_array}% Input colour definitions

                          begin{document}

                          begin{enumerate}
                          item textcolor{color1}{Name1}
                          item textcolor{color2}{Name2}
                          item textcolor{color3}{Name3}
                          end{enumerate}

                          textcolor{color4}{Name9}

                          textcolor{color5}{Name8}

                          end{document}


                          Note that input{color_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) colorlet{colorX}{<colour>} inside color_array.tex and load them within the document preamble:



                          enter image description here



                          documentclass{article}

                          % Just for this example, create control_array.tex that contains all the colour definitions
                          usepackage{filecontents}
                          begin{filecontents*}{control_array.tex}
                          usepackage{xcolor}
                          colorlet{color1}{blue}
                          colorlet{color2}{green}
                          colorlet{color3}{red!30!yellow}
                          colorlet{color4}{rgb:black,1;red,2;orange,3}
                          colorlet{color5}{black!50}
                          end{filecontents*}

                          input{control_array}% Input colour definitions

                          begin{document}

                          begin{enumerate}
                          item textcolor{color1}{Name1}
                          item textcolor{color2}{Name2}
                          item textcolor{color3}{Name3}
                          end{enumerate}

                          textcolor{color4}{Name9}

                          textcolor{color5}{Name8}

                          end{document}


                          Note that input{color_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 39 mins ago









                          WernerWerner

                          444k689791680




                          444k689791680






























                              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

                              Loup dans la culture

                              How to solve the problem of ntp “Unable to contact time server” from KDE?

                              ASUS Zenbook UX433/UX333 — Configure Touchpad-embedded numpad on Linux