Looping over charts and names simultaneouslyIncrements in foreach loop with two variables, TikZLooping and...
Multi tool use
Why did Jon Snow admit his fault in S08E06?
How does the Earth's center produce heat?
Can we show a sum of symmetrical cosine values is zero by using roots of unity?
How would a developer who mostly fixed bugs for years at a company call out their contributions in their CV?
The disk image is 497GB smaller than the target device
Are there any German nonsense poems (Jabberwocky)?
How was Daenerys able to legitimise Gendry?
Creating second map without labels using QGIS?
Why would a rational buyer offer to buy with no conditions precedent?
Why does the hash of infinity have the digits of π?
Final exams: What is the most common protocol for scheduling?
Is "vegetable base" a common term in English?
Is superuser the same as root?
Cardio work for Muay Thai fighters
How to determine if a hyphen (-) exists inside a column
Is my plasma cannon concept viable?
Sorting with IComparable design
Why does splatting create a tuple on the rhs but a list on the lhs?
What could a self-sustaining lunar colony slowly lose that would ultimately prove fatal?
Navigating a quick return to previous employer
Heat lost in ideal capacitor charging
Burned out due to current job, Can I take a week of vacation between jobs?
First Program Tic-Tac-Toe
Variable declaraton with extra in C
Looping over charts and names simultaneously
Increments in foreach loop with two variables, TikZLooping and linking with TikZlooping in tabularCreate a document looping through imagesLooping over elements to change font in math modeLooping Through a Nested ListTikZ scaling graphic and adjust node position and keep font sizeLooping over stringsLooping over macro arguments with spaces and building partial commandsAlternating/looping section dividerstikzset does not work in foreach loop
I want to use a common index to loop over two separate comma-separated lists at once, one which is a list of abbreviations and one a list of names. I want to use the abbreviations to import charts as pdfs, and the names to label them.
This is what I have so far:
documentclass[12pt]{article}
usepackage{tikz}
usepackage{graphicx}
defnamelist{"New York", "Illinois","Texas"}
defabrevlist{NY,IL,TX}
begin{document}
foreach x in abrevlist {%
newpage
section*{x} % <-- I want to use the state name here
begin{figure}[h!]
includegraphics[width=.5textwidth]{../charts/summary/x _compare.pdf}
caption{x} % <-- I want to use the state name here
end{figure}
}
end{document}
This imports the figures as I want, but does nothing with the state names. I would like to replace the section and captions with, for example, "New York" in place of "NYC".
Obviously, one could create an index i
and loop over that to index the abbreviation or name as necessary. But I can't make that work. Any suggestions? Thanks!
tikz-pgf macros graphics loops
New contributor
add a comment |
I want to use a common index to loop over two separate comma-separated lists at once, one which is a list of abbreviations and one a list of names. I want to use the abbreviations to import charts as pdfs, and the names to label them.
This is what I have so far:
documentclass[12pt]{article}
usepackage{tikz}
usepackage{graphicx}
defnamelist{"New York", "Illinois","Texas"}
defabrevlist{NY,IL,TX}
begin{document}
foreach x in abrevlist {%
newpage
section*{x} % <-- I want to use the state name here
begin{figure}[h!]
includegraphics[width=.5textwidth]{../charts/summary/x _compare.pdf}
caption{x} % <-- I want to use the state name here
end{figure}
}
end{document}
This imports the figures as I want, but does nothing with the state names. I would like to replace the section and captions with, for example, "New York" in place of "NYC".
Obviously, one could create an index i
and loop over that to index the abbreviation or name as necessary. But I can't make that work. Any suggestions? Thanks!
tikz-pgf macros graphics loops
New contributor
I don't think so. Here there is a reference both to text (in the caption) and a filename (in the includegraphics). The other question has only one. I can do either one, but not both.
– squipbar
8 hours ago
add a comment |
I want to use a common index to loop over two separate comma-separated lists at once, one which is a list of abbreviations and one a list of names. I want to use the abbreviations to import charts as pdfs, and the names to label them.
This is what I have so far:
documentclass[12pt]{article}
usepackage{tikz}
usepackage{graphicx}
defnamelist{"New York", "Illinois","Texas"}
defabrevlist{NY,IL,TX}
begin{document}
foreach x in abrevlist {%
newpage
section*{x} % <-- I want to use the state name here
begin{figure}[h!]
includegraphics[width=.5textwidth]{../charts/summary/x _compare.pdf}
caption{x} % <-- I want to use the state name here
end{figure}
}
end{document}
This imports the figures as I want, but does nothing with the state names. I would like to replace the section and captions with, for example, "New York" in place of "NYC".
Obviously, one could create an index i
and loop over that to index the abbreviation or name as necessary. But I can't make that work. Any suggestions? Thanks!
tikz-pgf macros graphics loops
New contributor
I want to use a common index to loop over two separate comma-separated lists at once, one which is a list of abbreviations and one a list of names. I want to use the abbreviations to import charts as pdfs, and the names to label them.
This is what I have so far:
documentclass[12pt]{article}
usepackage{tikz}
usepackage{graphicx}
defnamelist{"New York", "Illinois","Texas"}
defabrevlist{NY,IL,TX}
begin{document}
foreach x in abrevlist {%
newpage
section*{x} % <-- I want to use the state name here
begin{figure}[h!]
includegraphics[width=.5textwidth]{../charts/summary/x _compare.pdf}
caption{x} % <-- I want to use the state name here
end{figure}
}
end{document}
This imports the figures as I want, but does nothing with the state names. I would like to replace the section and captions with, for example, "New York" in place of "NYC".
Obviously, one could create an index i
and loop over that to index the abbreviation or name as necessary. But I can't make that work. Any suggestions? Thanks!
tikz-pgf macros graphics loops
tikz-pgf macros graphics loops
New contributor
New contributor
New contributor
asked 8 hours ago
squipbarsquipbar
1232
1232
New contributor
New contributor
I don't think so. Here there is a reference both to text (in the caption) and a filename (in the includegraphics). The other question has only one. I can do either one, but not both.
– squipbar
8 hours ago
add a comment |
I don't think so. Here there is a reference both to text (in the caption) and a filename (in the includegraphics). The other question has only one. I can do either one, but not both.
– squipbar
8 hours ago
I don't think so. Here there is a reference both to text (in the caption) and a filename (in the includegraphics). The other question has only one. I can do either one, but not both.
– squipbar
8 hours ago
I don't think so. Here there is a reference both to text (in the caption) and a filename (in the includegraphics). The other question has only one. I can do either one, but not both.
– squipbar
8 hours ago
add a comment |
2 Answers
2
active
oldest
votes
documentclass[12pt]{article}
usepackage{tikz}
defnamelist{"New York", "Illinois","Texas"}
defabrevlist{NY,IL,TX}
begin{document}
foreach X [count=Y starting from 0] in abrevlist {%
newpagepgfmathsetmacro{mystate}{{namelist}[Y]}
section*{mystate} % <-- I want to use the state name here
begin{figure}[h!]
%includegraphics[width=.5textwidth]{../charts/summary/X _compare.pdf}
caption{X} % <-- I want to use the state name here
end{figure}
}
end{document}
Nice, but you removed the line that references the filename for the figure. Can you edit to retain that? Will your X still work ok there?
– squipbar
8 hours ago
@squipbar Good catch. I removed it because I do not have your graphics files.Now it should work if you uncomment it. (There are reasons whyX
might be better thanx
, even though here it does not matter.)
– marmot
8 hours ago
This still gives me an error. I get:! Package PGF Math Error: Unknown function
New' (in '{New York,Illinois,Texas}[0]').`
– squipbar
7 hours ago
@squipbar Do you run the precise code from above or a version in which you removed the"
fromnamelist
? The error message suggests that you are using something likedefnamelist{{New York},{Illinois},{Texas}}
ordefnamelist{New York,Illinois,Texas}
. Also the number of{
is important inpgfmathsetmacro{mystate}{{namelist}[Y]}
, i.e.pgfmathsetmacro{mystate}{namelist[Y]}
won't work.
– marmot
7 hours ago
add a comment |
Here's my proposal.
documentclass{article}
usepackage{xparse}
ExplSyntaxOn
NewDocumentCommand{maketwoprongedlist}{m m}
{
prop_new:c { g_squipbar_list_#1_plist }
seq_new:c { g_squipbar_list_#1_seq }
clist_map_inline:nn { #2 }
{
__squipbar_list_entry:nnn {#1} ##1
}
}
cs_new_protected:Nn __squipbar_list_entry:nnn
{
seq_gput_right:cn { g_squipbar_list_#1_seq } { #2 }
prop_gput:cnn { g_squipbar_list_#1_plist } { short@#2 } { #2 }
prop_gput:cnn { g_squipbar_list_#1_plist } { long@#2 } { #3 }
}
NewDocumentCommand{usetwoprongedlist}{m +m}
{
cs_set_protected:Nn __squipbar_list_entry:nn { #2 }
seq_map_inline:cn { g_squipbar_list_#1_seq }
{
__squipbar_list_entry:nn
{ prop_item:cn { g_squipbar_list_#1_plist } { short@##1 } }
{ prop_item:cn { g_squipbar_list_#1_plist } { long@##1 } }
}
}
ExplSyntaxOff
maketwoprongedlist{states}{
{NY}{New York},
{IL}{Illinois},
{TX}{Texas}
}
begin{document}
usetwoprongedlist{states}{%
newpage
section*{#2} % <-- I want to use the state name here
begin{figure}[h!]
centering
%includegraphics[width=.5textwidth]{../charts/summary/x _compare.pdf}
texttt{../charts/summary/#1-compare.pdf}
caption{#2} % <-- I want to use the state name here
end{figure}
}
end{document}
Since I don't have your pictures, I emulated them by just printing the file name.
How does this work?
First of all, I define a list giving it a name. The items are comma separated and should consist of {<abbreviation>}{<full name>}
. The first part is also used for indexing and so it should consist of characters only (but this might be overcome, in case of need).
Each part is then stored as an item in a property list, indexed as short@<abbreviation>
and long@<abbreviation>
. Also a sequence is maintained containing the abbreviations, for later usage; the order will be that of input.
The usetwoprongedlist
command has two arguments: the first is the list to be processed; the second argument is a template, just like the main argument to foreach
; the difference is that #1
and #2
are used to denote the short and long versions of the current item.
A scratch function is defined and then the sequence indexing the list's items is mapped, calling the scratch function with arguments
prop_item:cn {<list name>} { short@<current item> }
and
prop_item:cn {<list name>} { long@<current item> }
respectively. Et voilà.
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
});
}
});
squipbar is a new contributor. Be nice, and check out our Code of Conduct.
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%2f492002%2flooping-over-charts-and-names-simultaneously%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
documentclass[12pt]{article}
usepackage{tikz}
defnamelist{"New York", "Illinois","Texas"}
defabrevlist{NY,IL,TX}
begin{document}
foreach X [count=Y starting from 0] in abrevlist {%
newpagepgfmathsetmacro{mystate}{{namelist}[Y]}
section*{mystate} % <-- I want to use the state name here
begin{figure}[h!]
%includegraphics[width=.5textwidth]{../charts/summary/X _compare.pdf}
caption{X} % <-- I want to use the state name here
end{figure}
}
end{document}
Nice, but you removed the line that references the filename for the figure. Can you edit to retain that? Will your X still work ok there?
– squipbar
8 hours ago
@squipbar Good catch. I removed it because I do not have your graphics files.Now it should work if you uncomment it. (There are reasons whyX
might be better thanx
, even though here it does not matter.)
– marmot
8 hours ago
This still gives me an error. I get:! Package PGF Math Error: Unknown function
New' (in '{New York,Illinois,Texas}[0]').`
– squipbar
7 hours ago
@squipbar Do you run the precise code from above or a version in which you removed the"
fromnamelist
? The error message suggests that you are using something likedefnamelist{{New York},{Illinois},{Texas}}
ordefnamelist{New York,Illinois,Texas}
. Also the number of{
is important inpgfmathsetmacro{mystate}{{namelist}[Y]}
, i.e.pgfmathsetmacro{mystate}{namelist[Y]}
won't work.
– marmot
7 hours ago
add a comment |
documentclass[12pt]{article}
usepackage{tikz}
defnamelist{"New York", "Illinois","Texas"}
defabrevlist{NY,IL,TX}
begin{document}
foreach X [count=Y starting from 0] in abrevlist {%
newpagepgfmathsetmacro{mystate}{{namelist}[Y]}
section*{mystate} % <-- I want to use the state name here
begin{figure}[h!]
%includegraphics[width=.5textwidth]{../charts/summary/X _compare.pdf}
caption{X} % <-- I want to use the state name here
end{figure}
}
end{document}
Nice, but you removed the line that references the filename for the figure. Can you edit to retain that? Will your X still work ok there?
– squipbar
8 hours ago
@squipbar Good catch. I removed it because I do not have your graphics files.Now it should work if you uncomment it. (There are reasons whyX
might be better thanx
, even though here it does not matter.)
– marmot
8 hours ago
This still gives me an error. I get:! Package PGF Math Error: Unknown function
New' (in '{New York,Illinois,Texas}[0]').`
– squipbar
7 hours ago
@squipbar Do you run the precise code from above or a version in which you removed the"
fromnamelist
? The error message suggests that you are using something likedefnamelist{{New York},{Illinois},{Texas}}
ordefnamelist{New York,Illinois,Texas}
. Also the number of{
is important inpgfmathsetmacro{mystate}{{namelist}[Y]}
, i.e.pgfmathsetmacro{mystate}{namelist[Y]}
won't work.
– marmot
7 hours ago
add a comment |
documentclass[12pt]{article}
usepackage{tikz}
defnamelist{"New York", "Illinois","Texas"}
defabrevlist{NY,IL,TX}
begin{document}
foreach X [count=Y starting from 0] in abrevlist {%
newpagepgfmathsetmacro{mystate}{{namelist}[Y]}
section*{mystate} % <-- I want to use the state name here
begin{figure}[h!]
%includegraphics[width=.5textwidth]{../charts/summary/X _compare.pdf}
caption{X} % <-- I want to use the state name here
end{figure}
}
end{document}
documentclass[12pt]{article}
usepackage{tikz}
defnamelist{"New York", "Illinois","Texas"}
defabrevlist{NY,IL,TX}
begin{document}
foreach X [count=Y starting from 0] in abrevlist {%
newpagepgfmathsetmacro{mystate}{{namelist}[Y]}
section*{mystate} % <-- I want to use the state name here
begin{figure}[h!]
%includegraphics[width=.5textwidth]{../charts/summary/X _compare.pdf}
caption{X} % <-- I want to use the state name here
end{figure}
}
end{document}
edited 8 hours ago
answered 8 hours ago
marmotmarmot
129k6163310
129k6163310
Nice, but you removed the line that references the filename for the figure. Can you edit to retain that? Will your X still work ok there?
– squipbar
8 hours ago
@squipbar Good catch. I removed it because I do not have your graphics files.Now it should work if you uncomment it. (There are reasons whyX
might be better thanx
, even though here it does not matter.)
– marmot
8 hours ago
This still gives me an error. I get:! Package PGF Math Error: Unknown function
New' (in '{New York,Illinois,Texas}[0]').`
– squipbar
7 hours ago
@squipbar Do you run the precise code from above or a version in which you removed the"
fromnamelist
? The error message suggests that you are using something likedefnamelist{{New York},{Illinois},{Texas}}
ordefnamelist{New York,Illinois,Texas}
. Also the number of{
is important inpgfmathsetmacro{mystate}{{namelist}[Y]}
, i.e.pgfmathsetmacro{mystate}{namelist[Y]}
won't work.
– marmot
7 hours ago
add a comment |
Nice, but you removed the line that references the filename for the figure. Can you edit to retain that? Will your X still work ok there?
– squipbar
8 hours ago
@squipbar Good catch. I removed it because I do not have your graphics files.Now it should work if you uncomment it. (There are reasons whyX
might be better thanx
, even though here it does not matter.)
– marmot
8 hours ago
This still gives me an error. I get:! Package PGF Math Error: Unknown function
New' (in '{New York,Illinois,Texas}[0]').`
– squipbar
7 hours ago
@squipbar Do you run the precise code from above or a version in which you removed the"
fromnamelist
? The error message suggests that you are using something likedefnamelist{{New York},{Illinois},{Texas}}
ordefnamelist{New York,Illinois,Texas}
. Also the number of{
is important inpgfmathsetmacro{mystate}{{namelist}[Y]}
, i.e.pgfmathsetmacro{mystate}{namelist[Y]}
won't work.
– marmot
7 hours ago
Nice, but you removed the line that references the filename for the figure. Can you edit to retain that? Will your X still work ok there?
– squipbar
8 hours ago
Nice, but you removed the line that references the filename for the figure. Can you edit to retain that? Will your X still work ok there?
– squipbar
8 hours ago
@squipbar Good catch. I removed it because I do not have your graphics files.Now it should work if you uncomment it. (There are reasons why
X
might be better than x
, even though here it does not matter.)– marmot
8 hours ago
@squipbar Good catch. I removed it because I do not have your graphics files.Now it should work if you uncomment it. (There are reasons why
X
might be better than x
, even though here it does not matter.)– marmot
8 hours ago
This still gives me an error. I get:
! Package PGF Math Error: Unknown function
New' (in '{New York,Illinois,Texas}[0]').`– squipbar
7 hours ago
This still gives me an error. I get:
! Package PGF Math Error: Unknown function
New' (in '{New York,Illinois,Texas}[0]').`– squipbar
7 hours ago
@squipbar Do you run the precise code from above or a version in which you removed the
"
from namelist
? The error message suggests that you are using something like defnamelist{{New York},{Illinois},{Texas}}
or defnamelist{New York,Illinois,Texas}
. Also the number of {
is important in pgfmathsetmacro{mystate}{{namelist}[Y]}
, i.e. pgfmathsetmacro{mystate}{namelist[Y]}
won't work.– marmot
7 hours ago
@squipbar Do you run the precise code from above or a version in which you removed the
"
from namelist
? The error message suggests that you are using something like defnamelist{{New York},{Illinois},{Texas}}
or defnamelist{New York,Illinois,Texas}
. Also the number of {
is important in pgfmathsetmacro{mystate}{{namelist}[Y]}
, i.e. pgfmathsetmacro{mystate}{namelist[Y]}
won't work.– marmot
7 hours ago
add a comment |
Here's my proposal.
documentclass{article}
usepackage{xparse}
ExplSyntaxOn
NewDocumentCommand{maketwoprongedlist}{m m}
{
prop_new:c { g_squipbar_list_#1_plist }
seq_new:c { g_squipbar_list_#1_seq }
clist_map_inline:nn { #2 }
{
__squipbar_list_entry:nnn {#1} ##1
}
}
cs_new_protected:Nn __squipbar_list_entry:nnn
{
seq_gput_right:cn { g_squipbar_list_#1_seq } { #2 }
prop_gput:cnn { g_squipbar_list_#1_plist } { short@#2 } { #2 }
prop_gput:cnn { g_squipbar_list_#1_plist } { long@#2 } { #3 }
}
NewDocumentCommand{usetwoprongedlist}{m +m}
{
cs_set_protected:Nn __squipbar_list_entry:nn { #2 }
seq_map_inline:cn { g_squipbar_list_#1_seq }
{
__squipbar_list_entry:nn
{ prop_item:cn { g_squipbar_list_#1_plist } { short@##1 } }
{ prop_item:cn { g_squipbar_list_#1_plist } { long@##1 } }
}
}
ExplSyntaxOff
maketwoprongedlist{states}{
{NY}{New York},
{IL}{Illinois},
{TX}{Texas}
}
begin{document}
usetwoprongedlist{states}{%
newpage
section*{#2} % <-- I want to use the state name here
begin{figure}[h!]
centering
%includegraphics[width=.5textwidth]{../charts/summary/x _compare.pdf}
texttt{../charts/summary/#1-compare.pdf}
caption{#2} % <-- I want to use the state name here
end{figure}
}
end{document}
Since I don't have your pictures, I emulated them by just printing the file name.
How does this work?
First of all, I define a list giving it a name. The items are comma separated and should consist of {<abbreviation>}{<full name>}
. The first part is also used for indexing and so it should consist of characters only (but this might be overcome, in case of need).
Each part is then stored as an item in a property list, indexed as short@<abbreviation>
and long@<abbreviation>
. Also a sequence is maintained containing the abbreviations, for later usage; the order will be that of input.
The usetwoprongedlist
command has two arguments: the first is the list to be processed; the second argument is a template, just like the main argument to foreach
; the difference is that #1
and #2
are used to denote the short and long versions of the current item.
A scratch function is defined and then the sequence indexing the list's items is mapped, calling the scratch function with arguments
prop_item:cn {<list name>} { short@<current item> }
and
prop_item:cn {<list name>} { long@<current item> }
respectively. Et voilà.
add a comment |
Here's my proposal.
documentclass{article}
usepackage{xparse}
ExplSyntaxOn
NewDocumentCommand{maketwoprongedlist}{m m}
{
prop_new:c { g_squipbar_list_#1_plist }
seq_new:c { g_squipbar_list_#1_seq }
clist_map_inline:nn { #2 }
{
__squipbar_list_entry:nnn {#1} ##1
}
}
cs_new_protected:Nn __squipbar_list_entry:nnn
{
seq_gput_right:cn { g_squipbar_list_#1_seq } { #2 }
prop_gput:cnn { g_squipbar_list_#1_plist } { short@#2 } { #2 }
prop_gput:cnn { g_squipbar_list_#1_plist } { long@#2 } { #3 }
}
NewDocumentCommand{usetwoprongedlist}{m +m}
{
cs_set_protected:Nn __squipbar_list_entry:nn { #2 }
seq_map_inline:cn { g_squipbar_list_#1_seq }
{
__squipbar_list_entry:nn
{ prop_item:cn { g_squipbar_list_#1_plist } { short@##1 } }
{ prop_item:cn { g_squipbar_list_#1_plist } { long@##1 } }
}
}
ExplSyntaxOff
maketwoprongedlist{states}{
{NY}{New York},
{IL}{Illinois},
{TX}{Texas}
}
begin{document}
usetwoprongedlist{states}{%
newpage
section*{#2} % <-- I want to use the state name here
begin{figure}[h!]
centering
%includegraphics[width=.5textwidth]{../charts/summary/x _compare.pdf}
texttt{../charts/summary/#1-compare.pdf}
caption{#2} % <-- I want to use the state name here
end{figure}
}
end{document}
Since I don't have your pictures, I emulated them by just printing the file name.
How does this work?
First of all, I define a list giving it a name. The items are comma separated and should consist of {<abbreviation>}{<full name>}
. The first part is also used for indexing and so it should consist of characters only (but this might be overcome, in case of need).
Each part is then stored as an item in a property list, indexed as short@<abbreviation>
and long@<abbreviation>
. Also a sequence is maintained containing the abbreviations, for later usage; the order will be that of input.
The usetwoprongedlist
command has two arguments: the first is the list to be processed; the second argument is a template, just like the main argument to foreach
; the difference is that #1
and #2
are used to denote the short and long versions of the current item.
A scratch function is defined and then the sequence indexing the list's items is mapped, calling the scratch function with arguments
prop_item:cn {<list name>} { short@<current item> }
and
prop_item:cn {<list name>} { long@<current item> }
respectively. Et voilà.
add a comment |
Here's my proposal.
documentclass{article}
usepackage{xparse}
ExplSyntaxOn
NewDocumentCommand{maketwoprongedlist}{m m}
{
prop_new:c { g_squipbar_list_#1_plist }
seq_new:c { g_squipbar_list_#1_seq }
clist_map_inline:nn { #2 }
{
__squipbar_list_entry:nnn {#1} ##1
}
}
cs_new_protected:Nn __squipbar_list_entry:nnn
{
seq_gput_right:cn { g_squipbar_list_#1_seq } { #2 }
prop_gput:cnn { g_squipbar_list_#1_plist } { short@#2 } { #2 }
prop_gput:cnn { g_squipbar_list_#1_plist } { long@#2 } { #3 }
}
NewDocumentCommand{usetwoprongedlist}{m +m}
{
cs_set_protected:Nn __squipbar_list_entry:nn { #2 }
seq_map_inline:cn { g_squipbar_list_#1_seq }
{
__squipbar_list_entry:nn
{ prop_item:cn { g_squipbar_list_#1_plist } { short@##1 } }
{ prop_item:cn { g_squipbar_list_#1_plist } { long@##1 } }
}
}
ExplSyntaxOff
maketwoprongedlist{states}{
{NY}{New York},
{IL}{Illinois},
{TX}{Texas}
}
begin{document}
usetwoprongedlist{states}{%
newpage
section*{#2} % <-- I want to use the state name here
begin{figure}[h!]
centering
%includegraphics[width=.5textwidth]{../charts/summary/x _compare.pdf}
texttt{../charts/summary/#1-compare.pdf}
caption{#2} % <-- I want to use the state name here
end{figure}
}
end{document}
Since I don't have your pictures, I emulated them by just printing the file name.
How does this work?
First of all, I define a list giving it a name. The items are comma separated and should consist of {<abbreviation>}{<full name>}
. The first part is also used for indexing and so it should consist of characters only (but this might be overcome, in case of need).
Each part is then stored as an item in a property list, indexed as short@<abbreviation>
and long@<abbreviation>
. Also a sequence is maintained containing the abbreviations, for later usage; the order will be that of input.
The usetwoprongedlist
command has two arguments: the first is the list to be processed; the second argument is a template, just like the main argument to foreach
; the difference is that #1
and #2
are used to denote the short and long versions of the current item.
A scratch function is defined and then the sequence indexing the list's items is mapped, calling the scratch function with arguments
prop_item:cn {<list name>} { short@<current item> }
and
prop_item:cn {<list name>} { long@<current item> }
respectively. Et voilà.
Here's my proposal.
documentclass{article}
usepackage{xparse}
ExplSyntaxOn
NewDocumentCommand{maketwoprongedlist}{m m}
{
prop_new:c { g_squipbar_list_#1_plist }
seq_new:c { g_squipbar_list_#1_seq }
clist_map_inline:nn { #2 }
{
__squipbar_list_entry:nnn {#1} ##1
}
}
cs_new_protected:Nn __squipbar_list_entry:nnn
{
seq_gput_right:cn { g_squipbar_list_#1_seq } { #2 }
prop_gput:cnn { g_squipbar_list_#1_plist } { short@#2 } { #2 }
prop_gput:cnn { g_squipbar_list_#1_plist } { long@#2 } { #3 }
}
NewDocumentCommand{usetwoprongedlist}{m +m}
{
cs_set_protected:Nn __squipbar_list_entry:nn { #2 }
seq_map_inline:cn { g_squipbar_list_#1_seq }
{
__squipbar_list_entry:nn
{ prop_item:cn { g_squipbar_list_#1_plist } { short@##1 } }
{ prop_item:cn { g_squipbar_list_#1_plist } { long@##1 } }
}
}
ExplSyntaxOff
maketwoprongedlist{states}{
{NY}{New York},
{IL}{Illinois},
{TX}{Texas}
}
begin{document}
usetwoprongedlist{states}{%
newpage
section*{#2} % <-- I want to use the state name here
begin{figure}[h!]
centering
%includegraphics[width=.5textwidth]{../charts/summary/x _compare.pdf}
texttt{../charts/summary/#1-compare.pdf}
caption{#2} % <-- I want to use the state name here
end{figure}
}
end{document}
Since I don't have your pictures, I emulated them by just printing the file name.
How does this work?
First of all, I define a list giving it a name. The items are comma separated and should consist of {<abbreviation>}{<full name>}
. The first part is also used for indexing and so it should consist of characters only (but this might be overcome, in case of need).
Each part is then stored as an item in a property list, indexed as short@<abbreviation>
and long@<abbreviation>
. Also a sequence is maintained containing the abbreviations, for later usage; the order will be that of input.
The usetwoprongedlist
command has two arguments: the first is the list to be processed; the second argument is a template, just like the main argument to foreach
; the difference is that #1
and #2
are used to denote the short and long versions of the current item.
A scratch function is defined and then the sequence indexing the list's items is mapped, calling the scratch function with arguments
prop_item:cn {<list name>} { short@<current item> }
and
prop_item:cn {<list name>} { long@<current item> }
respectively. Et voilà.
answered 7 hours ago
egregegreg
743k8919453277
743k8919453277
add a comment |
add a comment |
squipbar is a new contributor. Be nice, and check out our Code of Conduct.
squipbar is a new contributor. Be nice, and check out our Code of Conduct.
squipbar is a new contributor. Be nice, and check out our Code of Conduct.
squipbar is a new contributor. Be nice, and check out our Code of Conduct.
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%2f492002%2flooping-over-charts-and-names-simultaneously%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
qx2 C lTEKSTkWVDZ,P ICEVWOABWdE8 Z,j
I don't think so. Here there is a reference both to text (in the caption) and a filename (in the includegraphics). The other question has only one. I can do either one, but not both.
– squipbar
8 hours ago