Is there a possibility to generate a list dynamically in Latex? Unicorn Meta Zoo #1: Why...
How to keep bees out of canned beverages?
What do you call an IPA symbol that lacks a name (e.g. ɲ)?
Coin Game with infinite paradox
Is it appropriate to mention a relatable company blog post when you're asked about the company?
What is a 'Key' in computer science?
Will temporary Dex penalties prevent you from getting the benefits of the "Two Weapon Fighting" feat if your Dex score falls below the prerequisite?
Why doesn't the university give past final exams' answers?
Why does Java have support for time zone offsets with seconds precision?
Is there a verb for listening stealthily?
How can I wire a 9-position switch so that each position turns on one more LED than the one before?
What is the ongoing value of the Kanban board to the developers as opposed to management
What were wait-states, and why was it only an issue for PCs?
Will I be more secure with my own router behind my ISP's router?
What is ls Largest Number Formed by only moving two sticks in 508?
My admission is revoked after accepting the admission offer
Are these square matrices always diagonalisable?
Determinant of a matrix with 2 equal rows
Why did Israel vote against lifting the American embargo on Cuba?
What happened to Viserion in Season 7?
Like totally amazing interchangeable sister outfit accessory swapping or whatever
/bin/ls sorts differently than just ls
Writing a T-SQL stored procedure to receive 4 numbers and insert them into a table
Israeli soda type drink
Suing a Police Officer Instead of the Police Department
Is there a possibility to generate a list dynamically in Latex?
Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar ManaraExtracting the structure of a LaTex document, including commentsEnumerate and itemize undefined + captions not workingHow do I generate a check-list?Generate List/Array of RequirementsHow to make itemize/enumerate/description environment robust to missing item elements?How do I generate in LaTeX a list of random questions avoiding repetitions?How to generate unordered list with hyphen?How can I create a better pseudo-enumerated list unconstrained by any environmentAuto generate list-items within table from string with delimitercross-referencing two long lists; general recommendations?Generate an iterable list
As stated, I wonder if there is any possibility to dynamically add items to a list and print it anywhere in the document, regardless of where the definitions are made.
I'm thinking something like this:
documentclass[a4paper,12pt]{article}
defineList{MyListName}
begin{document}
begin{itemize}
printlist{MyListName}
end{itemize}
Lorem ipsum dolor sit amet...
addToList{MyListName}{item First}
addToList{MyListName}{item Second}
end{document}
and this would then result in something like this (in essence, the printlist{MyListName}
merely acts as a macro and is replaced by the content of the list:
Of course, being able to iterate over the list items would be even more elegant, however it might introduce too much complexity.
lists
add a comment |
As stated, I wonder if there is any possibility to dynamically add items to a list and print it anywhere in the document, regardless of where the definitions are made.
I'm thinking something like this:
documentclass[a4paper,12pt]{article}
defineList{MyListName}
begin{document}
begin{itemize}
printlist{MyListName}
end{itemize}
Lorem ipsum dolor sit amet...
addToList{MyListName}{item First}
addToList{MyListName}{item Second}
end{document}
and this would then result in something like this (in essence, the printlist{MyListName}
merely acts as a macro and is replaced by the content of the list:
Of course, being able to iterate over the list items would be even more elegant, however it might introduce too much complexity.
lists
Is it your intent that later defineditem
s are printed earlier in the document, at the instance ofprintlist
? Alatableofcontents
?
– Steven B. Segletes
13 hours ago
One can put pretty much anything into @currentlabel and use label and ref to access it. ( Pgfplots puts the entire legend into a ref.) All you need is a label naming convention.
– John Kormylo
13 hours ago
An answer like this, tex.stackexchange.com/questions/202574/…, may be exactly what you are looking for.
– Steven B. Segletes
13 hours ago
add a comment |
As stated, I wonder if there is any possibility to dynamically add items to a list and print it anywhere in the document, regardless of where the definitions are made.
I'm thinking something like this:
documentclass[a4paper,12pt]{article}
defineList{MyListName}
begin{document}
begin{itemize}
printlist{MyListName}
end{itemize}
Lorem ipsum dolor sit amet...
addToList{MyListName}{item First}
addToList{MyListName}{item Second}
end{document}
and this would then result in something like this (in essence, the printlist{MyListName}
merely acts as a macro and is replaced by the content of the list:
Of course, being able to iterate over the list items would be even more elegant, however it might introduce too much complexity.
lists
As stated, I wonder if there is any possibility to dynamically add items to a list and print it anywhere in the document, regardless of where the definitions are made.
I'm thinking something like this:
documentclass[a4paper,12pt]{article}
defineList{MyListName}
begin{document}
begin{itemize}
printlist{MyListName}
end{itemize}
Lorem ipsum dolor sit amet...
addToList{MyListName}{item First}
addToList{MyListName}{item Second}
end{document}
and this would then result in something like this (in essence, the printlist{MyListName}
merely acts as a macro and is replaced by the content of the list:
Of course, being able to iterate over the list items would be even more elegant, however it might introduce too much complexity.
lists
lists
asked 13 hours ago
chrillofchrillof
261
261
Is it your intent that later defineditem
s are printed earlier in the document, at the instance ofprintlist
? Alatableofcontents
?
– Steven B. Segletes
13 hours ago
One can put pretty much anything into @currentlabel and use label and ref to access it. ( Pgfplots puts the entire legend into a ref.) All you need is a label naming convention.
– John Kormylo
13 hours ago
An answer like this, tex.stackexchange.com/questions/202574/…, may be exactly what you are looking for.
– Steven B. Segletes
13 hours ago
add a comment |
Is it your intent that later defineditem
s are printed earlier in the document, at the instance ofprintlist
? Alatableofcontents
?
– Steven B. Segletes
13 hours ago
One can put pretty much anything into @currentlabel and use label and ref to access it. ( Pgfplots puts the entire legend into a ref.) All you need is a label naming convention.
– John Kormylo
13 hours ago
An answer like this, tex.stackexchange.com/questions/202574/…, may be exactly what you are looking for.
– Steven B. Segletes
13 hours ago
Is it your intent that later defined
item
s are printed earlier in the document, at the instance of printlist
? Ala tableofcontents
?– Steven B. Segletes
13 hours ago
Is it your intent that later defined
item
s are printed earlier in the document, at the instance of printlist
? Ala tableofcontents
?– Steven B. Segletes
13 hours ago
One can put pretty much anything into @currentlabel and use label and ref to access it. ( Pgfplots puts the entire legend into a ref.) All you need is a label naming convention.
– John Kormylo
13 hours ago
One can put pretty much anything into @currentlabel and use label and ref to access it. ( Pgfplots puts the entire legend into a ref.) All you need is a label naming convention.
– John Kormylo
13 hours ago
An answer like this, tex.stackexchange.com/questions/202574/…, may be exactly what you are looking for.
– Steven B. Segletes
13 hours ago
An answer like this, tex.stackexchange.com/questions/202574/…, may be exactly what you are looking for.
– Steven B. Segletes
13 hours ago
add a comment |
3 Answers
3
active
oldest
votes
You can use the .aux
file.
With defineList
we initialize a sequence variable; each addToList
command writes in the .aux
file the corresponding entry as argument to chrillofaddtolist
.
When the .aux
file is read in at begin document, the sequence is populated with the items gathered in the previous run so it will be available as soon as the document starts.
The command chrillofaddtolist
is made a no-op at end document, when the .aux
file is read back in, but we need no action.
Finally, printList
just delivers the sequence.
As a technical workaround, I added a litemize
environment, so no error is raised when the sequence is still empty.
documentclass[a4paper,12pt]{article}
usepackage{xparse}
ExplSyntaxOn
NewDocumentCommand{defineList}{m}
{
seq_new:c { g_chrillof_list_#1_seq }
}
NewDocumentCommand{addToList}{mm}
{
iow_shipout:cn { @auxout } { chrillofaddtolist { #1 } { #2 } }
}
NewDocumentCommand{chrillofaddtolist}{mm}
{
seq_gput_right:cn { g_chrillof_list_#1_seq } { #2 }
}
NewDocumentCommand{printList}{m}
{
seq_use:cn { g_chrillof_list_#1_seq } { }
}
AtEndDocument{cs_set_eq:NN chrillofaddtolist use_none:nn }
ExplSyntaxOff
makeatletter
newenvironment{litemize}
{let@noitemerrrelaxitemize}
{enditemize}
makeatother
defineList{MyListName}
begin{document}
begin{litemize}
printList{MyListName}
end{litemize}
Lorem ipsum dolor sit amet...
addToList{MyListName}{item First}
addToList{MyListName}{item Second}
end{document}
add a comment |
The sagetex
package, documentation here, gives you access to the Python programming language. This is one way to keep track of the list and print using a loop.
documentclass{article}
usepackage{sagetex}
begin{document}
begin{sagesilent}
MyList = ["spring","summer"]
output = r"begin{itemize}"
for i in range(0,len(MyList)):
output += r"item %s"%(MyList[i])
output += r"end{itemize}"
end{sagesilent}
sagestr{output}
Lorem ipsum dolor sit amet...
begin{sagesilent}
MyList.insert(0,"winter")
MyList.append("fall")
output = r"begin{itemize}"
for i in range(0,len(MyList)):
output += r"item %s"%(MyList[i])
output += r"end{itemize}"
end{sagesilent}
sagestr{output}
end{document}
The result is shown below:
The "behind the scenes" work is done in sagesilent
environment. The original list is created to contain "spring" and "summer". A for loop creates a string that will put the list into the itemize environment. To insert it into the document, use sagestr
, the SAGE string environment. If we want to add "winter" to be first in the list and "fall" to be last, the command MyList.insert(0,"winter") puts "winter" in the first position (which in Python is the zeroth position). The command MyList.append("fall") puts "fall" at the end of the list, however long it is. The for loop prints out over the longer list since len(MyList) is the length of the list.
The extra block of code each time is a bit clunky but it is easy to read and modify. You also get the benefit of being able to insert into any part of the list. The sagetex
package relies on the computer algebra system SAGE, which is not part of the LaTeX package. It either needs to be downloaded to your computer or you can open a free Cocalc account and work from the cloud.
add a comment |
Requires two passes. Based on my answer at Extracting the structure of a LaTex document, including comments, but adapting the syntax to meet the OP's needs.
Multiple lists can be simultaneously active. Here, in the MWE, I build "xyz" and "pdq" lists.
documentclass{article}
letsvaddtocontentsaddtocontents
makeatletter
newcommanddefineList[1]{%
expandafterdefcsname add#1lineendcsname##1##2##3{addtocontents {##1}{%
protect csname #1lineendcsname {##2}{##3}}}
expandafterdefcsname write#1endcsname{%
renewcommandaddtocontents[2]{relax}%
setcounter{section}{0}noindent%
expandafterdefcsname #1lineendcsname####1####2{expandaftercsname####1endcsname{####2}}%
@starttoc{#1}%
setcounter{section}{0}%
letaddtocontentssvaddtocontents%
}%
csname add#1lineendcsname{#1}{begin}{itemize}%
AtEndDocument{csname add#1lineendcsname{#1}{end}{itemize}}
}
newcommandaddToList[2]{csname add#1lineendcsname{#1}{item}{#2}}
newcommandprintList[1]{csname write#1endcsname}
makeatother
begin{document}
%tableofcontents% CAN UNCOMMMENT TO SEE THAT toc WORKS FINE
defineList{xyz}
defineList{pdq}
section{Introduction}
addToList{xyz}{First item on my list.}
Text related to why tracking balls is important, blah, blah, blah.
Blah, blah, blah.
addToList{pdq}{First pdq item}
Here is my XYZ list:
printList{xyz}
section{Next Section}
addToList{xyz}{Second item on list}
Text relating the challenges, blah, blah, blah.
More blah, blah, blah.
addToList{pdq}{Next pdq item}
addToList{xyz}{Third item on list.}
Here is my PDQ list:
printList{pdq}
Text relating the existing work on tracking balls, blah, blah, blah.
Blah, blah, blah.
end{document}
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%2f486224%2fis-there-a-possibility-to-generate-a-list-dynamically-in-latex%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
You can use the .aux
file.
With defineList
we initialize a sequence variable; each addToList
command writes in the .aux
file the corresponding entry as argument to chrillofaddtolist
.
When the .aux
file is read in at begin document, the sequence is populated with the items gathered in the previous run so it will be available as soon as the document starts.
The command chrillofaddtolist
is made a no-op at end document, when the .aux
file is read back in, but we need no action.
Finally, printList
just delivers the sequence.
As a technical workaround, I added a litemize
environment, so no error is raised when the sequence is still empty.
documentclass[a4paper,12pt]{article}
usepackage{xparse}
ExplSyntaxOn
NewDocumentCommand{defineList}{m}
{
seq_new:c { g_chrillof_list_#1_seq }
}
NewDocumentCommand{addToList}{mm}
{
iow_shipout:cn { @auxout } { chrillofaddtolist { #1 } { #2 } }
}
NewDocumentCommand{chrillofaddtolist}{mm}
{
seq_gput_right:cn { g_chrillof_list_#1_seq } { #2 }
}
NewDocumentCommand{printList}{m}
{
seq_use:cn { g_chrillof_list_#1_seq } { }
}
AtEndDocument{cs_set_eq:NN chrillofaddtolist use_none:nn }
ExplSyntaxOff
makeatletter
newenvironment{litemize}
{let@noitemerrrelaxitemize}
{enditemize}
makeatother
defineList{MyListName}
begin{document}
begin{litemize}
printList{MyListName}
end{litemize}
Lorem ipsum dolor sit amet...
addToList{MyListName}{item First}
addToList{MyListName}{item Second}
end{document}
add a comment |
You can use the .aux
file.
With defineList
we initialize a sequence variable; each addToList
command writes in the .aux
file the corresponding entry as argument to chrillofaddtolist
.
When the .aux
file is read in at begin document, the sequence is populated with the items gathered in the previous run so it will be available as soon as the document starts.
The command chrillofaddtolist
is made a no-op at end document, when the .aux
file is read back in, but we need no action.
Finally, printList
just delivers the sequence.
As a technical workaround, I added a litemize
environment, so no error is raised when the sequence is still empty.
documentclass[a4paper,12pt]{article}
usepackage{xparse}
ExplSyntaxOn
NewDocumentCommand{defineList}{m}
{
seq_new:c { g_chrillof_list_#1_seq }
}
NewDocumentCommand{addToList}{mm}
{
iow_shipout:cn { @auxout } { chrillofaddtolist { #1 } { #2 } }
}
NewDocumentCommand{chrillofaddtolist}{mm}
{
seq_gput_right:cn { g_chrillof_list_#1_seq } { #2 }
}
NewDocumentCommand{printList}{m}
{
seq_use:cn { g_chrillof_list_#1_seq } { }
}
AtEndDocument{cs_set_eq:NN chrillofaddtolist use_none:nn }
ExplSyntaxOff
makeatletter
newenvironment{litemize}
{let@noitemerrrelaxitemize}
{enditemize}
makeatother
defineList{MyListName}
begin{document}
begin{litemize}
printList{MyListName}
end{litemize}
Lorem ipsum dolor sit amet...
addToList{MyListName}{item First}
addToList{MyListName}{item Second}
end{document}
add a comment |
You can use the .aux
file.
With defineList
we initialize a sequence variable; each addToList
command writes in the .aux
file the corresponding entry as argument to chrillofaddtolist
.
When the .aux
file is read in at begin document, the sequence is populated with the items gathered in the previous run so it will be available as soon as the document starts.
The command chrillofaddtolist
is made a no-op at end document, when the .aux
file is read back in, but we need no action.
Finally, printList
just delivers the sequence.
As a technical workaround, I added a litemize
environment, so no error is raised when the sequence is still empty.
documentclass[a4paper,12pt]{article}
usepackage{xparse}
ExplSyntaxOn
NewDocumentCommand{defineList}{m}
{
seq_new:c { g_chrillof_list_#1_seq }
}
NewDocumentCommand{addToList}{mm}
{
iow_shipout:cn { @auxout } { chrillofaddtolist { #1 } { #2 } }
}
NewDocumentCommand{chrillofaddtolist}{mm}
{
seq_gput_right:cn { g_chrillof_list_#1_seq } { #2 }
}
NewDocumentCommand{printList}{m}
{
seq_use:cn { g_chrillof_list_#1_seq } { }
}
AtEndDocument{cs_set_eq:NN chrillofaddtolist use_none:nn }
ExplSyntaxOff
makeatletter
newenvironment{litemize}
{let@noitemerrrelaxitemize}
{enditemize}
makeatother
defineList{MyListName}
begin{document}
begin{litemize}
printList{MyListName}
end{litemize}
Lorem ipsum dolor sit amet...
addToList{MyListName}{item First}
addToList{MyListName}{item Second}
end{document}
You can use the .aux
file.
With defineList
we initialize a sequence variable; each addToList
command writes in the .aux
file the corresponding entry as argument to chrillofaddtolist
.
When the .aux
file is read in at begin document, the sequence is populated with the items gathered in the previous run so it will be available as soon as the document starts.
The command chrillofaddtolist
is made a no-op at end document, when the .aux
file is read back in, but we need no action.
Finally, printList
just delivers the sequence.
As a technical workaround, I added a litemize
environment, so no error is raised when the sequence is still empty.
documentclass[a4paper,12pt]{article}
usepackage{xparse}
ExplSyntaxOn
NewDocumentCommand{defineList}{m}
{
seq_new:c { g_chrillof_list_#1_seq }
}
NewDocumentCommand{addToList}{mm}
{
iow_shipout:cn { @auxout } { chrillofaddtolist { #1 } { #2 } }
}
NewDocumentCommand{chrillofaddtolist}{mm}
{
seq_gput_right:cn { g_chrillof_list_#1_seq } { #2 }
}
NewDocumentCommand{printList}{m}
{
seq_use:cn { g_chrillof_list_#1_seq } { }
}
AtEndDocument{cs_set_eq:NN chrillofaddtolist use_none:nn }
ExplSyntaxOff
makeatletter
newenvironment{litemize}
{let@noitemerrrelaxitemize}
{enditemize}
makeatother
defineList{MyListName}
begin{document}
begin{litemize}
printList{MyListName}
end{litemize}
Lorem ipsum dolor sit amet...
addToList{MyListName}{item First}
addToList{MyListName}{item Second}
end{document}
answered 12 hours ago
egregegreg
736k8919353261
736k8919353261
add a comment |
add a comment |
The sagetex
package, documentation here, gives you access to the Python programming language. This is one way to keep track of the list and print using a loop.
documentclass{article}
usepackage{sagetex}
begin{document}
begin{sagesilent}
MyList = ["spring","summer"]
output = r"begin{itemize}"
for i in range(0,len(MyList)):
output += r"item %s"%(MyList[i])
output += r"end{itemize}"
end{sagesilent}
sagestr{output}
Lorem ipsum dolor sit amet...
begin{sagesilent}
MyList.insert(0,"winter")
MyList.append("fall")
output = r"begin{itemize}"
for i in range(0,len(MyList)):
output += r"item %s"%(MyList[i])
output += r"end{itemize}"
end{sagesilent}
sagestr{output}
end{document}
The result is shown below:
The "behind the scenes" work is done in sagesilent
environment. The original list is created to contain "spring" and "summer". A for loop creates a string that will put the list into the itemize environment. To insert it into the document, use sagestr
, the SAGE string environment. If we want to add "winter" to be first in the list and "fall" to be last, the command MyList.insert(0,"winter") puts "winter" in the first position (which in Python is the zeroth position). The command MyList.append("fall") puts "fall" at the end of the list, however long it is. The for loop prints out over the longer list since len(MyList) is the length of the list.
The extra block of code each time is a bit clunky but it is easy to read and modify. You also get the benefit of being able to insert into any part of the list. The sagetex
package relies on the computer algebra system SAGE, which is not part of the LaTeX package. It either needs to be downloaded to your computer or you can open a free Cocalc account and work from the cloud.
add a comment |
The sagetex
package, documentation here, gives you access to the Python programming language. This is one way to keep track of the list and print using a loop.
documentclass{article}
usepackage{sagetex}
begin{document}
begin{sagesilent}
MyList = ["spring","summer"]
output = r"begin{itemize}"
for i in range(0,len(MyList)):
output += r"item %s"%(MyList[i])
output += r"end{itemize}"
end{sagesilent}
sagestr{output}
Lorem ipsum dolor sit amet...
begin{sagesilent}
MyList.insert(0,"winter")
MyList.append("fall")
output = r"begin{itemize}"
for i in range(0,len(MyList)):
output += r"item %s"%(MyList[i])
output += r"end{itemize}"
end{sagesilent}
sagestr{output}
end{document}
The result is shown below:
The "behind the scenes" work is done in sagesilent
environment. The original list is created to contain "spring" and "summer". A for loop creates a string that will put the list into the itemize environment. To insert it into the document, use sagestr
, the SAGE string environment. If we want to add "winter" to be first in the list and "fall" to be last, the command MyList.insert(0,"winter") puts "winter" in the first position (which in Python is the zeroth position). The command MyList.append("fall") puts "fall" at the end of the list, however long it is. The for loop prints out over the longer list since len(MyList) is the length of the list.
The extra block of code each time is a bit clunky but it is easy to read and modify. You also get the benefit of being able to insert into any part of the list. The sagetex
package relies on the computer algebra system SAGE, which is not part of the LaTeX package. It either needs to be downloaded to your computer or you can open a free Cocalc account and work from the cloud.
add a comment |
The sagetex
package, documentation here, gives you access to the Python programming language. This is one way to keep track of the list and print using a loop.
documentclass{article}
usepackage{sagetex}
begin{document}
begin{sagesilent}
MyList = ["spring","summer"]
output = r"begin{itemize}"
for i in range(0,len(MyList)):
output += r"item %s"%(MyList[i])
output += r"end{itemize}"
end{sagesilent}
sagestr{output}
Lorem ipsum dolor sit amet...
begin{sagesilent}
MyList.insert(0,"winter")
MyList.append("fall")
output = r"begin{itemize}"
for i in range(0,len(MyList)):
output += r"item %s"%(MyList[i])
output += r"end{itemize}"
end{sagesilent}
sagestr{output}
end{document}
The result is shown below:
The "behind the scenes" work is done in sagesilent
environment. The original list is created to contain "spring" and "summer". A for loop creates a string that will put the list into the itemize environment. To insert it into the document, use sagestr
, the SAGE string environment. If we want to add "winter" to be first in the list and "fall" to be last, the command MyList.insert(0,"winter") puts "winter" in the first position (which in Python is the zeroth position). The command MyList.append("fall") puts "fall" at the end of the list, however long it is. The for loop prints out over the longer list since len(MyList) is the length of the list.
The extra block of code each time is a bit clunky but it is easy to read and modify. You also get the benefit of being able to insert into any part of the list. The sagetex
package relies on the computer algebra system SAGE, which is not part of the LaTeX package. It either needs to be downloaded to your computer or you can open a free Cocalc account and work from the cloud.
The sagetex
package, documentation here, gives you access to the Python programming language. This is one way to keep track of the list and print using a loop.
documentclass{article}
usepackage{sagetex}
begin{document}
begin{sagesilent}
MyList = ["spring","summer"]
output = r"begin{itemize}"
for i in range(0,len(MyList)):
output += r"item %s"%(MyList[i])
output += r"end{itemize}"
end{sagesilent}
sagestr{output}
Lorem ipsum dolor sit amet...
begin{sagesilent}
MyList.insert(0,"winter")
MyList.append("fall")
output = r"begin{itemize}"
for i in range(0,len(MyList)):
output += r"item %s"%(MyList[i])
output += r"end{itemize}"
end{sagesilent}
sagestr{output}
end{document}
The result is shown below:
The "behind the scenes" work is done in sagesilent
environment. The original list is created to contain "spring" and "summer". A for loop creates a string that will put the list into the itemize environment. To insert it into the document, use sagestr
, the SAGE string environment. If we want to add "winter" to be first in the list and "fall" to be last, the command MyList.insert(0,"winter") puts "winter" in the first position (which in Python is the zeroth position). The command MyList.append("fall") puts "fall" at the end of the list, however long it is. The for loop prints out over the longer list since len(MyList) is the length of the list.
The extra block of code each time is a bit clunky but it is easy to read and modify. You also get the benefit of being able to insert into any part of the list. The sagetex
package relies on the computer algebra system SAGE, which is not part of the LaTeX package. It either needs to be downloaded to your computer or you can open a free Cocalc account and work from the cloud.
answered 11 hours ago
DJPDJP
8,00921732
8,00921732
add a comment |
add a comment |
Requires two passes. Based on my answer at Extracting the structure of a LaTex document, including comments, but adapting the syntax to meet the OP's needs.
Multiple lists can be simultaneously active. Here, in the MWE, I build "xyz" and "pdq" lists.
documentclass{article}
letsvaddtocontentsaddtocontents
makeatletter
newcommanddefineList[1]{%
expandafterdefcsname add#1lineendcsname##1##2##3{addtocontents {##1}{%
protect csname #1lineendcsname {##2}{##3}}}
expandafterdefcsname write#1endcsname{%
renewcommandaddtocontents[2]{relax}%
setcounter{section}{0}noindent%
expandafterdefcsname #1lineendcsname####1####2{expandaftercsname####1endcsname{####2}}%
@starttoc{#1}%
setcounter{section}{0}%
letaddtocontentssvaddtocontents%
}%
csname add#1lineendcsname{#1}{begin}{itemize}%
AtEndDocument{csname add#1lineendcsname{#1}{end}{itemize}}
}
newcommandaddToList[2]{csname add#1lineendcsname{#1}{item}{#2}}
newcommandprintList[1]{csname write#1endcsname}
makeatother
begin{document}
%tableofcontents% CAN UNCOMMMENT TO SEE THAT toc WORKS FINE
defineList{xyz}
defineList{pdq}
section{Introduction}
addToList{xyz}{First item on my list.}
Text related to why tracking balls is important, blah, blah, blah.
Blah, blah, blah.
addToList{pdq}{First pdq item}
Here is my XYZ list:
printList{xyz}
section{Next Section}
addToList{xyz}{Second item on list}
Text relating the challenges, blah, blah, blah.
More blah, blah, blah.
addToList{pdq}{Next pdq item}
addToList{xyz}{Third item on list.}
Here is my PDQ list:
printList{pdq}
Text relating the existing work on tracking balls, blah, blah, blah.
Blah, blah, blah.
end{document}
add a comment |
Requires two passes. Based on my answer at Extracting the structure of a LaTex document, including comments, but adapting the syntax to meet the OP's needs.
Multiple lists can be simultaneously active. Here, in the MWE, I build "xyz" and "pdq" lists.
documentclass{article}
letsvaddtocontentsaddtocontents
makeatletter
newcommanddefineList[1]{%
expandafterdefcsname add#1lineendcsname##1##2##3{addtocontents {##1}{%
protect csname #1lineendcsname {##2}{##3}}}
expandafterdefcsname write#1endcsname{%
renewcommandaddtocontents[2]{relax}%
setcounter{section}{0}noindent%
expandafterdefcsname #1lineendcsname####1####2{expandaftercsname####1endcsname{####2}}%
@starttoc{#1}%
setcounter{section}{0}%
letaddtocontentssvaddtocontents%
}%
csname add#1lineendcsname{#1}{begin}{itemize}%
AtEndDocument{csname add#1lineendcsname{#1}{end}{itemize}}
}
newcommandaddToList[2]{csname add#1lineendcsname{#1}{item}{#2}}
newcommandprintList[1]{csname write#1endcsname}
makeatother
begin{document}
%tableofcontents% CAN UNCOMMMENT TO SEE THAT toc WORKS FINE
defineList{xyz}
defineList{pdq}
section{Introduction}
addToList{xyz}{First item on my list.}
Text related to why tracking balls is important, blah, blah, blah.
Blah, blah, blah.
addToList{pdq}{First pdq item}
Here is my XYZ list:
printList{xyz}
section{Next Section}
addToList{xyz}{Second item on list}
Text relating the challenges, blah, blah, blah.
More blah, blah, blah.
addToList{pdq}{Next pdq item}
addToList{xyz}{Third item on list.}
Here is my PDQ list:
printList{pdq}
Text relating the existing work on tracking balls, blah, blah, blah.
Blah, blah, blah.
end{document}
add a comment |
Requires two passes. Based on my answer at Extracting the structure of a LaTex document, including comments, but adapting the syntax to meet the OP's needs.
Multiple lists can be simultaneously active. Here, in the MWE, I build "xyz" and "pdq" lists.
documentclass{article}
letsvaddtocontentsaddtocontents
makeatletter
newcommanddefineList[1]{%
expandafterdefcsname add#1lineendcsname##1##2##3{addtocontents {##1}{%
protect csname #1lineendcsname {##2}{##3}}}
expandafterdefcsname write#1endcsname{%
renewcommandaddtocontents[2]{relax}%
setcounter{section}{0}noindent%
expandafterdefcsname #1lineendcsname####1####2{expandaftercsname####1endcsname{####2}}%
@starttoc{#1}%
setcounter{section}{0}%
letaddtocontentssvaddtocontents%
}%
csname add#1lineendcsname{#1}{begin}{itemize}%
AtEndDocument{csname add#1lineendcsname{#1}{end}{itemize}}
}
newcommandaddToList[2]{csname add#1lineendcsname{#1}{item}{#2}}
newcommandprintList[1]{csname write#1endcsname}
makeatother
begin{document}
%tableofcontents% CAN UNCOMMMENT TO SEE THAT toc WORKS FINE
defineList{xyz}
defineList{pdq}
section{Introduction}
addToList{xyz}{First item on my list.}
Text related to why tracking balls is important, blah, blah, blah.
Blah, blah, blah.
addToList{pdq}{First pdq item}
Here is my XYZ list:
printList{xyz}
section{Next Section}
addToList{xyz}{Second item on list}
Text relating the challenges, blah, blah, blah.
More blah, blah, blah.
addToList{pdq}{Next pdq item}
addToList{xyz}{Third item on list.}
Here is my PDQ list:
printList{pdq}
Text relating the existing work on tracking balls, blah, blah, blah.
Blah, blah, blah.
end{document}
Requires two passes. Based on my answer at Extracting the structure of a LaTex document, including comments, but adapting the syntax to meet the OP's needs.
Multiple lists can be simultaneously active. Here, in the MWE, I build "xyz" and "pdq" lists.
documentclass{article}
letsvaddtocontentsaddtocontents
makeatletter
newcommanddefineList[1]{%
expandafterdefcsname add#1lineendcsname##1##2##3{addtocontents {##1}{%
protect csname #1lineendcsname {##2}{##3}}}
expandafterdefcsname write#1endcsname{%
renewcommandaddtocontents[2]{relax}%
setcounter{section}{0}noindent%
expandafterdefcsname #1lineendcsname####1####2{expandaftercsname####1endcsname{####2}}%
@starttoc{#1}%
setcounter{section}{0}%
letaddtocontentssvaddtocontents%
}%
csname add#1lineendcsname{#1}{begin}{itemize}%
AtEndDocument{csname add#1lineendcsname{#1}{end}{itemize}}
}
newcommandaddToList[2]{csname add#1lineendcsname{#1}{item}{#2}}
newcommandprintList[1]{csname write#1endcsname}
makeatother
begin{document}
%tableofcontents% CAN UNCOMMMENT TO SEE THAT toc WORKS FINE
defineList{xyz}
defineList{pdq}
section{Introduction}
addToList{xyz}{First item on my list.}
Text related to why tracking balls is important, blah, blah, blah.
Blah, blah, blah.
addToList{pdq}{First pdq item}
Here is my XYZ list:
printList{xyz}
section{Next Section}
addToList{xyz}{Second item on list}
Text relating the challenges, blah, blah, blah.
More blah, blah, blah.
addToList{pdq}{Next pdq item}
addToList{xyz}{Third item on list.}
Here is my PDQ list:
printList{pdq}
Text relating the existing work on tracking balls, blah, blah, blah.
Blah, blah, blah.
end{document}
edited 11 hours ago
answered 11 hours ago
Steven B. SegletesSteven B. Segletes
163k9207419
163k9207419
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%2f486224%2fis-there-a-possibility-to-generate-a-list-dynamically-in-latex%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
Is it your intent that later defined
item
s are printed earlier in the document, at the instance ofprintlist
? Alatableofcontents
?– Steven B. Segletes
13 hours ago
One can put pretty much anything into @currentlabel and use label and ref to access it. ( Pgfplots puts the entire legend into a ref.) All you need is a label naming convention.
– John Kormylo
13 hours ago
An answer like this, tex.stackexchange.com/questions/202574/…, may be exactly what you are looking for.
– Steven B. Segletes
13 hours ago