Is there a possibility to generate a list dynamically in Latex?Extracting 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

How do I check if a string is entirely made of the same substring?

Phrase for the opposite of "foolproof"

Size of electromagnet needed to replicate Earth's magnetic field

Solving polynominals equations (relationship of roots)

How come there are so many candidates for the 2020 Democratic party presidential nomination?

"You've called the wrong number" or "You called the wrong number"

Rivers without rain

Pre-plastic human skin alternative

Multiple options vs single option UI

Re-entry to Germany after vacation using blue card

Contradiction proof for inequality of P and NP?

Is it idiomatic to construct against `this`

Can SQL Server create collisions in system generated constraint names?

Was Dennis Ritchie being too modest in this quote about C and Pascal?

How could Tony Stark make this in Endgame?

Can an Area of Effect spell cast outside a Prismatic Wall extend inside it?

Partitioning the Reals into two Locally Uncountable, Dense Sets

Alignment of various blocks in tikz

Why did C use the -> operator instead of reusing the . operator?

Do I have an "anti-research" personality?

a sore throat vs a strep throat vs strep throat

Why must Chinese maps be obfuscated?

A Paper Record is What I Hamper

What are the characteristics of a typeless programming language?



Is there a possibility to generate a list dynamically in Latex?


Extracting 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













5















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
defineListMyListName
begindocument
beginitemize
printlistMyListName
enditemize
Lorem ipsum dolor sit amet...
addToListMyListNameitem First
addToListMyListNameitem Second
enddocument


and this would then result in something like this (in essence, the printlistMyListName merely acts as a macro and is replaced by the content of the list:



Bullet list preceding the "Lorem ipsum" paragraph.



Of course, being able to iterate over the list items would be even more elegant, however it might introduce too much complexity.










share|improve this question






















  • Is it your intent that later defined items are printed earlier in the document, at the instance of printlist? Ala tableofcontents?

    – Steven B. Segletes
    Apr 23 at 15:07












  • 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
    Apr 23 at 15:21











  • An answer like this, tex.stackexchange.com/questions/202574/…, may be exactly what you are looking for.

    – Steven B. Segletes
    Apr 23 at 15:24
















5















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
defineListMyListName
begindocument
beginitemize
printlistMyListName
enditemize
Lorem ipsum dolor sit amet...
addToListMyListNameitem First
addToListMyListNameitem Second
enddocument


and this would then result in something like this (in essence, the printlistMyListName merely acts as a macro and is replaced by the content of the list:



Bullet list preceding the "Lorem ipsum" paragraph.



Of course, being able to iterate over the list items would be even more elegant, however it might introduce too much complexity.










share|improve this question






















  • Is it your intent that later defined items are printed earlier in the document, at the instance of printlist? Ala tableofcontents?

    – Steven B. Segletes
    Apr 23 at 15:07












  • 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
    Apr 23 at 15:21











  • An answer like this, tex.stackexchange.com/questions/202574/…, may be exactly what you are looking for.

    – Steven B. Segletes
    Apr 23 at 15:24














5












5








5


1






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
defineListMyListName
begindocument
beginitemize
printlistMyListName
enditemize
Lorem ipsum dolor sit amet...
addToListMyListNameitem First
addToListMyListNameitem Second
enddocument


and this would then result in something like this (in essence, the printlistMyListName merely acts as a macro and is replaced by the content of the list:



Bullet list preceding the "Lorem ipsum" paragraph.



Of course, being able to iterate over the list items would be even more elegant, however it might introduce too much complexity.










share|improve this question














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
defineListMyListName
begindocument
beginitemize
printlistMyListName
enditemize
Lorem ipsum dolor sit amet...
addToListMyListNameitem First
addToListMyListNameitem Second
enddocument


and this would then result in something like this (in essence, the printlistMyListName merely acts as a macro and is replaced by the content of the list:



Bullet list preceding the "Lorem ipsum" paragraph.



Of course, being able to iterate over the list items would be even more elegant, however it might introduce too much complexity.







lists






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Apr 23 at 15:04









chrillofchrillof

261




261












  • Is it your intent that later defined items are printed earlier in the document, at the instance of printlist? Ala tableofcontents?

    – Steven B. Segletes
    Apr 23 at 15:07












  • 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
    Apr 23 at 15:21











  • An answer like this, tex.stackexchange.com/questions/202574/…, may be exactly what you are looking for.

    – Steven B. Segletes
    Apr 23 at 15:24


















  • Is it your intent that later defined items are printed earlier in the document, at the instance of printlist? Ala tableofcontents?

    – Steven B. Segletes
    Apr 23 at 15:07












  • 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
    Apr 23 at 15:21











  • An answer like this, tex.stackexchange.com/questions/202574/…, may be exactly what you are looking for.

    – Steven B. Segletes
    Apr 23 at 15:24

















Is it your intent that later defined items are printed earlier in the document, at the instance of printlist? Ala tableofcontents?

– Steven B. Segletes
Apr 23 at 15:07






Is it your intent that later defined items are printed earlier in the document, at the instance of printlist? Ala tableofcontents?

– Steven B. Segletes
Apr 23 at 15:07














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
Apr 23 at 15:21





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
Apr 23 at 15:21













An answer like this, tex.stackexchange.com/questions/202574/…, may be exactly what you are looking for.

– Steven B. Segletes
Apr 23 at 15:24






An answer like this, tex.stackexchange.com/questions/202574/…, may be exactly what you are looking for.

– Steven B. Segletes
Apr 23 at 15:24











3 Answers
3






active

oldest

votes


















5














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
usepackagexparse

ExplSyntaxOn
NewDocumentCommanddefineListm

seq_new:c g_chrillof_list_#1_seq

NewDocumentCommandaddToListmm

iow_shipout:cn @auxout chrillofaddtolist #1 #2

NewDocumentCommandchrillofaddtolistmm

seq_gput_right:cn g_chrillof_list_#1_seq #2

NewDocumentCommandprintListm

seq_use:cn g_chrillof_list_#1_seq

AtEndDocumentcs_set_eq:NN chrillofaddtolist use_none:nn
ExplSyntaxOff

makeatletter
newenvironmentlitemize
let@noitemerrrelaxitemize
enditemize
makeatother

defineListMyListName

begindocument

beginlitemize
printListMyListName
endlitemize

Lorem ipsum dolor sit amet...

addToListMyListNameitem First
addToListMyListNameitem Second

enddocument


enter image description here






share|improve this answer






























    3














    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.



    documentclassarticle
    usepackagesagetex
    begindocument
    beginsagesilent
    MyList = ["spring","summer"]
    output = r"beginitemize"
    for i in range(0,len(MyList)):
    output += r"item %s"%(MyList[i])
    output += r"enditemize"
    endsagesilent

    sagestroutput

    Lorem ipsum dolor sit amet...

    beginsagesilent
    MyList.insert(0,"winter")
    MyList.append("fall")
    output = r"beginitemize"
    for i in range(0,len(MyList)):
    output += r"item %s"%(MyList[i])
    output += r"enditemize"
    endsagesilent

    sagestroutput
    enddocument


    The result is shown below:
    enter image description here



    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.






    share|improve this answer






























      2














      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.



      documentclassarticle
      letsvaddtocontentsaddtocontents
      makeatletter
      newcommanddefineList[1]%
      expandafterdefcsname add#1lineendcsname##1##2##3addtocontents ##1%
      protect csname #1lineendcsname ##2##3
      expandafterdefcsname write#1endcsname%
      renewcommandaddtocontents[2]relax%
      setcountersection0noindent%
      expandafterdefcsname #1lineendcsname####1####2expandaftercsname####1endcsname####2%
      @starttoc#1%
      setcountersection0%
      letaddtocontentssvaddtocontents%
      %
      csname add#1lineendcsname#1beginitemize%
      AtEndDocumentcsname add#1lineendcsname#1enditemize

      newcommandaddToList[2]csname add#1lineendcsname#1item#2
      newcommandprintList[1]csname write#1endcsname
      makeatother
      begindocument
      %tableofcontents% CAN UNCOMMMENT TO SEE THAT toc WORKS FINE
      defineListxyz
      defineListpdq

      sectionIntroduction

      addToListxyzFirst item on my list.
      Text related to why tracking balls is important, blah, blah, blah.
      Blah, blah, blah.
      addToListpdqFirst pdq item

      Here is my XYZ list:
      printListxyz

      sectionNext Section

      addToListxyzSecond item on list
      Text relating the challenges, blah, blah, blah.
      More blah, blah, blah.
      addToListpdqNext pdq item

      addToListxyzThird item on list.
      Here is my PDQ list:
      printListpdq

      Text relating the existing work on tracking balls, blah, blah, blah.
      Blah, blah, blah.

      enddocument


      enter image description here






      share|improve this answer

























        Your Answer








        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "85"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );













        draft saved

        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%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









        5














        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
        usepackagexparse

        ExplSyntaxOn
        NewDocumentCommanddefineListm

        seq_new:c g_chrillof_list_#1_seq

        NewDocumentCommandaddToListmm

        iow_shipout:cn @auxout chrillofaddtolist #1 #2

        NewDocumentCommandchrillofaddtolistmm

        seq_gput_right:cn g_chrillof_list_#1_seq #2

        NewDocumentCommandprintListm

        seq_use:cn g_chrillof_list_#1_seq

        AtEndDocumentcs_set_eq:NN chrillofaddtolist use_none:nn
        ExplSyntaxOff

        makeatletter
        newenvironmentlitemize
        let@noitemerrrelaxitemize
        enditemize
        makeatother

        defineListMyListName

        begindocument

        beginlitemize
        printListMyListName
        endlitemize

        Lorem ipsum dolor sit amet...

        addToListMyListNameitem First
        addToListMyListNameitem Second

        enddocument


        enter image description here






        share|improve this answer



























          5














          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
          usepackagexparse

          ExplSyntaxOn
          NewDocumentCommanddefineListm

          seq_new:c g_chrillof_list_#1_seq

          NewDocumentCommandaddToListmm

          iow_shipout:cn @auxout chrillofaddtolist #1 #2

          NewDocumentCommandchrillofaddtolistmm

          seq_gput_right:cn g_chrillof_list_#1_seq #2

          NewDocumentCommandprintListm

          seq_use:cn g_chrillof_list_#1_seq

          AtEndDocumentcs_set_eq:NN chrillofaddtolist use_none:nn
          ExplSyntaxOff

          makeatletter
          newenvironmentlitemize
          let@noitemerrrelaxitemize
          enditemize
          makeatother

          defineListMyListName

          begindocument

          beginlitemize
          printListMyListName
          endlitemize

          Lorem ipsum dolor sit amet...

          addToListMyListNameitem First
          addToListMyListNameitem Second

          enddocument


          enter image description here






          share|improve this answer

























            5












            5








            5







            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
            usepackagexparse

            ExplSyntaxOn
            NewDocumentCommanddefineListm

            seq_new:c g_chrillof_list_#1_seq

            NewDocumentCommandaddToListmm

            iow_shipout:cn @auxout chrillofaddtolist #1 #2

            NewDocumentCommandchrillofaddtolistmm

            seq_gput_right:cn g_chrillof_list_#1_seq #2

            NewDocumentCommandprintListm

            seq_use:cn g_chrillof_list_#1_seq

            AtEndDocumentcs_set_eq:NN chrillofaddtolist use_none:nn
            ExplSyntaxOff

            makeatletter
            newenvironmentlitemize
            let@noitemerrrelaxitemize
            enditemize
            makeatother

            defineListMyListName

            begindocument

            beginlitemize
            printListMyListName
            endlitemize

            Lorem ipsum dolor sit amet...

            addToListMyListNameitem First
            addToListMyListNameitem Second

            enddocument


            enter image description here






            share|improve this answer













            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
            usepackagexparse

            ExplSyntaxOn
            NewDocumentCommanddefineListm

            seq_new:c g_chrillof_list_#1_seq

            NewDocumentCommandaddToListmm

            iow_shipout:cn @auxout chrillofaddtolist #1 #2

            NewDocumentCommandchrillofaddtolistmm

            seq_gput_right:cn g_chrillof_list_#1_seq #2

            NewDocumentCommandprintListm

            seq_use:cn g_chrillof_list_#1_seq

            AtEndDocumentcs_set_eq:NN chrillofaddtolist use_none:nn
            ExplSyntaxOff

            makeatletter
            newenvironmentlitemize
            let@noitemerrrelaxitemize
            enditemize
            makeatother

            defineListMyListName

            begindocument

            beginlitemize
            printListMyListName
            endlitemize

            Lorem ipsum dolor sit amet...

            addToListMyListNameitem First
            addToListMyListNameitem Second

            enddocument


            enter image description here







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Apr 23 at 15:51









            egregegreg

            737k8919373265




            737k8919373265





















                3














                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.



                documentclassarticle
                usepackagesagetex
                begindocument
                beginsagesilent
                MyList = ["spring","summer"]
                output = r"beginitemize"
                for i in range(0,len(MyList)):
                output += r"item %s"%(MyList[i])
                output += r"enditemize"
                endsagesilent

                sagestroutput

                Lorem ipsum dolor sit amet...

                beginsagesilent
                MyList.insert(0,"winter")
                MyList.append("fall")
                output = r"beginitemize"
                for i in range(0,len(MyList)):
                output += r"item %s"%(MyList[i])
                output += r"enditemize"
                endsagesilent

                sagestroutput
                enddocument


                The result is shown below:
                enter image description here



                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.






                share|improve this answer



























                  3














                  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.



                  documentclassarticle
                  usepackagesagetex
                  begindocument
                  beginsagesilent
                  MyList = ["spring","summer"]
                  output = r"beginitemize"
                  for i in range(0,len(MyList)):
                  output += r"item %s"%(MyList[i])
                  output += r"enditemize"
                  endsagesilent

                  sagestroutput

                  Lorem ipsum dolor sit amet...

                  beginsagesilent
                  MyList.insert(0,"winter")
                  MyList.append("fall")
                  output = r"beginitemize"
                  for i in range(0,len(MyList)):
                  output += r"item %s"%(MyList[i])
                  output += r"enditemize"
                  endsagesilent

                  sagestroutput
                  enddocument


                  The result is shown below:
                  enter image description here



                  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.






                  share|improve this answer

























                    3












                    3








                    3







                    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.



                    documentclassarticle
                    usepackagesagetex
                    begindocument
                    beginsagesilent
                    MyList = ["spring","summer"]
                    output = r"beginitemize"
                    for i in range(0,len(MyList)):
                    output += r"item %s"%(MyList[i])
                    output += r"enditemize"
                    endsagesilent

                    sagestroutput

                    Lorem ipsum dolor sit amet...

                    beginsagesilent
                    MyList.insert(0,"winter")
                    MyList.append("fall")
                    output = r"beginitemize"
                    for i in range(0,len(MyList)):
                    output += r"item %s"%(MyList[i])
                    output += r"enditemize"
                    endsagesilent

                    sagestroutput
                    enddocument


                    The result is shown below:
                    enter image description here



                    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.






                    share|improve this answer













                    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.



                    documentclassarticle
                    usepackagesagetex
                    begindocument
                    beginsagesilent
                    MyList = ["spring","summer"]
                    output = r"beginitemize"
                    for i in range(0,len(MyList)):
                    output += r"item %s"%(MyList[i])
                    output += r"enditemize"
                    endsagesilent

                    sagestroutput

                    Lorem ipsum dolor sit amet...

                    beginsagesilent
                    MyList.insert(0,"winter")
                    MyList.append("fall")
                    output = r"beginitemize"
                    for i in range(0,len(MyList)):
                    output += r"item %s"%(MyList[i])
                    output += r"enditemize"
                    endsagesilent

                    sagestroutput
                    enddocument


                    The result is shown below:
                    enter image description here



                    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.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Apr 23 at 16:56









                    DJPDJP

                    8,00921732




                    8,00921732





















                        2














                        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.



                        documentclassarticle
                        letsvaddtocontentsaddtocontents
                        makeatletter
                        newcommanddefineList[1]%
                        expandafterdefcsname add#1lineendcsname##1##2##3addtocontents ##1%
                        protect csname #1lineendcsname ##2##3
                        expandafterdefcsname write#1endcsname%
                        renewcommandaddtocontents[2]relax%
                        setcountersection0noindent%
                        expandafterdefcsname #1lineendcsname####1####2expandaftercsname####1endcsname####2%
                        @starttoc#1%
                        setcountersection0%
                        letaddtocontentssvaddtocontents%
                        %
                        csname add#1lineendcsname#1beginitemize%
                        AtEndDocumentcsname add#1lineendcsname#1enditemize

                        newcommandaddToList[2]csname add#1lineendcsname#1item#2
                        newcommandprintList[1]csname write#1endcsname
                        makeatother
                        begindocument
                        %tableofcontents% CAN UNCOMMMENT TO SEE THAT toc WORKS FINE
                        defineListxyz
                        defineListpdq

                        sectionIntroduction

                        addToListxyzFirst item on my list.
                        Text related to why tracking balls is important, blah, blah, blah.
                        Blah, blah, blah.
                        addToListpdqFirst pdq item

                        Here is my XYZ list:
                        printListxyz

                        sectionNext Section

                        addToListxyzSecond item on list
                        Text relating the challenges, blah, blah, blah.
                        More blah, blah, blah.
                        addToListpdqNext pdq item

                        addToListxyzThird item on list.
                        Here is my PDQ list:
                        printListpdq

                        Text relating the existing work on tracking balls, blah, blah, blah.
                        Blah, blah, blah.

                        enddocument


                        enter image description here






                        share|improve this answer





























                          2














                          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.



                          documentclassarticle
                          letsvaddtocontentsaddtocontents
                          makeatletter
                          newcommanddefineList[1]%
                          expandafterdefcsname add#1lineendcsname##1##2##3addtocontents ##1%
                          protect csname #1lineendcsname ##2##3
                          expandafterdefcsname write#1endcsname%
                          renewcommandaddtocontents[2]relax%
                          setcountersection0noindent%
                          expandafterdefcsname #1lineendcsname####1####2expandaftercsname####1endcsname####2%
                          @starttoc#1%
                          setcountersection0%
                          letaddtocontentssvaddtocontents%
                          %
                          csname add#1lineendcsname#1beginitemize%
                          AtEndDocumentcsname add#1lineendcsname#1enditemize

                          newcommandaddToList[2]csname add#1lineendcsname#1item#2
                          newcommandprintList[1]csname write#1endcsname
                          makeatother
                          begindocument
                          %tableofcontents% CAN UNCOMMMENT TO SEE THAT toc WORKS FINE
                          defineListxyz
                          defineListpdq

                          sectionIntroduction

                          addToListxyzFirst item on my list.
                          Text related to why tracking balls is important, blah, blah, blah.
                          Blah, blah, blah.
                          addToListpdqFirst pdq item

                          Here is my XYZ list:
                          printListxyz

                          sectionNext Section

                          addToListxyzSecond item on list
                          Text relating the challenges, blah, blah, blah.
                          More blah, blah, blah.
                          addToListpdqNext pdq item

                          addToListxyzThird item on list.
                          Here is my PDQ list:
                          printListpdq

                          Text relating the existing work on tracking balls, blah, blah, blah.
                          Blah, blah, blah.

                          enddocument


                          enter image description here






                          share|improve this answer



























                            2












                            2








                            2







                            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.



                            documentclassarticle
                            letsvaddtocontentsaddtocontents
                            makeatletter
                            newcommanddefineList[1]%
                            expandafterdefcsname add#1lineendcsname##1##2##3addtocontents ##1%
                            protect csname #1lineendcsname ##2##3
                            expandafterdefcsname write#1endcsname%
                            renewcommandaddtocontents[2]relax%
                            setcountersection0noindent%
                            expandafterdefcsname #1lineendcsname####1####2expandaftercsname####1endcsname####2%
                            @starttoc#1%
                            setcountersection0%
                            letaddtocontentssvaddtocontents%
                            %
                            csname add#1lineendcsname#1beginitemize%
                            AtEndDocumentcsname add#1lineendcsname#1enditemize

                            newcommandaddToList[2]csname add#1lineendcsname#1item#2
                            newcommandprintList[1]csname write#1endcsname
                            makeatother
                            begindocument
                            %tableofcontents% CAN UNCOMMMENT TO SEE THAT toc WORKS FINE
                            defineListxyz
                            defineListpdq

                            sectionIntroduction

                            addToListxyzFirst item on my list.
                            Text related to why tracking balls is important, blah, blah, blah.
                            Blah, blah, blah.
                            addToListpdqFirst pdq item

                            Here is my XYZ list:
                            printListxyz

                            sectionNext Section

                            addToListxyzSecond item on list
                            Text relating the challenges, blah, blah, blah.
                            More blah, blah, blah.
                            addToListpdqNext pdq item

                            addToListxyzThird item on list.
                            Here is my PDQ list:
                            printListpdq

                            Text relating the existing work on tracking balls, blah, blah, blah.
                            Blah, blah, blah.

                            enddocument


                            enter image description here






                            share|improve this answer















                            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.



                            documentclassarticle
                            letsvaddtocontentsaddtocontents
                            makeatletter
                            newcommanddefineList[1]%
                            expandafterdefcsname add#1lineendcsname##1##2##3addtocontents ##1%
                            protect csname #1lineendcsname ##2##3
                            expandafterdefcsname write#1endcsname%
                            renewcommandaddtocontents[2]relax%
                            setcountersection0noindent%
                            expandafterdefcsname #1lineendcsname####1####2expandaftercsname####1endcsname####2%
                            @starttoc#1%
                            setcountersection0%
                            letaddtocontentssvaddtocontents%
                            %
                            csname add#1lineendcsname#1beginitemize%
                            AtEndDocumentcsname add#1lineendcsname#1enditemize

                            newcommandaddToList[2]csname add#1lineendcsname#1item#2
                            newcommandprintList[1]csname write#1endcsname
                            makeatother
                            begindocument
                            %tableofcontents% CAN UNCOMMMENT TO SEE THAT toc WORKS FINE
                            defineListxyz
                            defineListpdq

                            sectionIntroduction

                            addToListxyzFirst item on my list.
                            Text related to why tracking balls is important, blah, blah, blah.
                            Blah, blah, blah.
                            addToListpdqFirst pdq item

                            Here is my XYZ list:
                            printListxyz

                            sectionNext Section

                            addToListxyzSecond item on list
                            Text relating the challenges, blah, blah, blah.
                            More blah, blah, blah.
                            addToListpdqNext pdq item

                            addToListxyzThird item on list.
                            Here is my PDQ list:
                            printListpdq

                            Text relating the existing work on tracking balls, blah, blah, blah.
                            Blah, blah, blah.

                            enddocument


                            enter image description here







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Apr 23 at 17:25

























                            answered Apr 23 at 16:53









                            Steven B. SegletesSteven B. Segletes

                            163k9208421




                            163k9208421



























                                draft saved

                                draft discarded
















































                                Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f486224%2fis-there-a-possibility-to-generate-a-list-dynamically-in-latex%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                                Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

                                Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?