Global variable Array
Clash Royale CLAN TAG#URR8PPP
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
add a comment |
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
Constant arrays are easy, variable arrays use things likecsname nametheindexendcsname
.
– John Kormylo
Feb 14 at 4:51
add a comment |
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
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
color external-files
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 likecsname nametheindexendcsname
.
– John Kormylo
Feb 14 at 4:51
add a comment |
Constant arrays are easy, variable arrays use things likecsname 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
add a comment |
4 Answers
4
active
oldest
votes
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
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
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.
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
@tisaigonmyarrays.tex
needs only to havedefArrayNames"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 doesdocumentclass[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
|
show 11 more comments
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
add a comment |
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
add a comment |
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:
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.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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
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.
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
@tisaigonmyarrays.tex
needs only to havedefArrayNames"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 doesdocumentclass[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
|
show 11 more comments
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
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
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.
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
@tisaigonmyarrays.tex
needs only to havedefArrayNames"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 doesdocumentclass[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
|
show 11 more comments
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
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
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.
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
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
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.
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
@tisaigonmyarrays.tex
needs only to havedefArrayNames"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 doesdocumentclass[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
|
show 11 more comments
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
@tisaigonmyarrays.tex
needs only to havedefArrayNames"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 doesdocumentclass[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
|
show 11 more comments
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
add a comment |
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
add a comment |
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
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
answered Feb 14 at 2:49
Steven B. SegletesSteven B. Segletes
157k9204411
157k9204411
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Feb 14 at 10:51
egregegreg
725k8819193224
725k8819193224
add a comment |
add a comment |
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:
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.
add a comment |
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:
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.
add a comment |
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:
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.
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:
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.
answered Feb 14 at 2:51
WernerWerner
447k699891693
447k699891693
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Constant arrays are easy, variable arrays use things like
csname nametheindexendcsname
.– John Kormylo
Feb 14 at 4:51