modular macro list structure to iterate it












1















Based on the Wipet's answer, and with the same learning spirit, about the iterate loop "for", it's interesting to find out how the proposed "for loop" could be more modular. I want to pass, as an argument, the iterable list purposed in the above example.



documentclass[a4paper]{article}
usepackage{pst-solides3d}

%%% FOR LOOP %%%
makeatletter
longdeffor#1in#2#3{expandafterdefcsname b:string#1endcsname{#3}%
@forinA#1#2;}
longdef@forinA#1#2;{ifx#2else
def#1{#2}csname b:string#1endcsname expandafter@forinAexpandafter#1fi}
%%%%%%%%%%%%%%%%%%
makeatother

%% Variables%%
pgfmathparse{1.2}edeflinkLength{pgfmathresult}
pgfmathparse{0.2}edefjointRadio{pgfmathresult}
pgfmathparse{0.6}edefjointLength{pgfmathresult}

newcommand{iterating}{
%%% point's structure %%%
fori in {%
0 0 0;% N°0
0 0 0;% N°1
0 0 linkLength;% N°2
0 0 jointLength;% N°3
0 {jointLength*0.5} {linkLength + jointRadio};% N°4
}
{%
ipar
%... call to several macros
}%
}
begin{document}

iterating

end{document}


The code behavior is correct for my purpose.



0 0 0
0 0 0
0 0 1.2
0 0 0.6
0 0.6*0.5 1.2+ 0.2


This list, is an implicit list, with several variables and arithmetic operation in each component. So the main idea is passing the list as a macro, something like newcommand{list}{0 0 0;0 0 0;0 0 linkLength;0 0 jointLength;0 {jointLength*0.5} {linkLength + jointRadio}} and call it as fori in list. I don't understand which modifications be needed in for declaration to reach this behavior.
(i realize that this behavior could be reached using foreach statement but i need to understand how could be done)



Any ideas, will be well received.










share|improve this question



























    1















    Based on the Wipet's answer, and with the same learning spirit, about the iterate loop "for", it's interesting to find out how the proposed "for loop" could be more modular. I want to pass, as an argument, the iterable list purposed in the above example.



    documentclass[a4paper]{article}
    usepackage{pst-solides3d}

    %%% FOR LOOP %%%
    makeatletter
    longdeffor#1in#2#3{expandafterdefcsname b:string#1endcsname{#3}%
    @forinA#1#2;}
    longdef@forinA#1#2;{ifx#2else
    def#1{#2}csname b:string#1endcsname expandafter@forinAexpandafter#1fi}
    %%%%%%%%%%%%%%%%%%
    makeatother

    %% Variables%%
    pgfmathparse{1.2}edeflinkLength{pgfmathresult}
    pgfmathparse{0.2}edefjointRadio{pgfmathresult}
    pgfmathparse{0.6}edefjointLength{pgfmathresult}

    newcommand{iterating}{
    %%% point's structure %%%
    fori in {%
    0 0 0;% N°0
    0 0 0;% N°1
    0 0 linkLength;% N°2
    0 0 jointLength;% N°3
    0 {jointLength*0.5} {linkLength + jointRadio};% N°4
    }
    {%
    ipar
    %... call to several macros
    }%
    }
    begin{document}

    iterating

    end{document}


    The code behavior is correct for my purpose.



    0 0 0
    0 0 0
    0 0 1.2
    0 0 0.6
    0 0.6*0.5 1.2+ 0.2


    This list, is an implicit list, with several variables and arithmetic operation in each component. So the main idea is passing the list as a macro, something like newcommand{list}{0 0 0;0 0 0;0 0 linkLength;0 0 jointLength;0 {jointLength*0.5} {linkLength + jointRadio}} and call it as fori in list. I don't understand which modifications be needed in for declaration to reach this behavior.
    (i realize that this behavior could be reached using foreach statement but i need to understand how could be done)



    Any ideas, will be well received.










    share|improve this question

























      1












      1








      1


      0






      Based on the Wipet's answer, and with the same learning spirit, about the iterate loop "for", it's interesting to find out how the proposed "for loop" could be more modular. I want to pass, as an argument, the iterable list purposed in the above example.



      documentclass[a4paper]{article}
      usepackage{pst-solides3d}

      %%% FOR LOOP %%%
      makeatletter
      longdeffor#1in#2#3{expandafterdefcsname b:string#1endcsname{#3}%
      @forinA#1#2;}
      longdef@forinA#1#2;{ifx#2else
      def#1{#2}csname b:string#1endcsname expandafter@forinAexpandafter#1fi}
      %%%%%%%%%%%%%%%%%%
      makeatother

      %% Variables%%
      pgfmathparse{1.2}edeflinkLength{pgfmathresult}
      pgfmathparse{0.2}edefjointRadio{pgfmathresult}
      pgfmathparse{0.6}edefjointLength{pgfmathresult}

      newcommand{iterating}{
      %%% point's structure %%%
      fori in {%
      0 0 0;% N°0
      0 0 0;% N°1
      0 0 linkLength;% N°2
      0 0 jointLength;% N°3
      0 {jointLength*0.5} {linkLength + jointRadio};% N°4
      }
      {%
      ipar
      %... call to several macros
      }%
      }
      begin{document}

      iterating

      end{document}


      The code behavior is correct for my purpose.



      0 0 0
      0 0 0
      0 0 1.2
      0 0 0.6
      0 0.6*0.5 1.2+ 0.2


      This list, is an implicit list, with several variables and arithmetic operation in each component. So the main idea is passing the list as a macro, something like newcommand{list}{0 0 0;0 0 0;0 0 linkLength;0 0 jointLength;0 {jointLength*0.5} {linkLength + jointRadio}} and call it as fori in list. I don't understand which modifications be needed in for declaration to reach this behavior.
      (i realize that this behavior could be reached using foreach statement but i need to understand how could be done)



      Any ideas, will be well received.










      share|improve this question














      Based on the Wipet's answer, and with the same learning spirit, about the iterate loop "for", it's interesting to find out how the proposed "for loop" could be more modular. I want to pass, as an argument, the iterable list purposed in the above example.



      documentclass[a4paper]{article}
      usepackage{pst-solides3d}

      %%% FOR LOOP %%%
      makeatletter
      longdeffor#1in#2#3{expandafterdefcsname b:string#1endcsname{#3}%
      @forinA#1#2;}
      longdef@forinA#1#2;{ifx#2else
      def#1{#2}csname b:string#1endcsname expandafter@forinAexpandafter#1fi}
      %%%%%%%%%%%%%%%%%%
      makeatother

      %% Variables%%
      pgfmathparse{1.2}edeflinkLength{pgfmathresult}
      pgfmathparse{0.2}edefjointRadio{pgfmathresult}
      pgfmathparse{0.6}edefjointLength{pgfmathresult}

      newcommand{iterating}{
      %%% point's structure %%%
      fori in {%
      0 0 0;% N°0
      0 0 0;% N°1
      0 0 linkLength;% N°2
      0 0 jointLength;% N°3
      0 {jointLength*0.5} {linkLength + jointRadio};% N°4
      }
      {%
      ipar
      %... call to several macros
      }%
      }
      begin{document}

      iterating

      end{document}


      The code behavior is correct for my purpose.



      0 0 0
      0 0 0
      0 0 1.2
      0 0 0.6
      0 0.6*0.5 1.2+ 0.2


      This list, is an implicit list, with several variables and arithmetic operation in each component. So the main idea is passing the list as a macro, something like newcommand{list}{0 0 0;0 0 0;0 0 linkLength;0 0 jointLength;0 {jointLength*0.5} {linkLength + jointRadio}} and call it as fori in list. I don't understand which modifications be needed in for declaration to reach this behavior.
      (i realize that this behavior could be reached using foreach statement but i need to understand how could be done)



      Any ideas, will be well received.







      macros lists pst-solides3d literate-programming






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 28 at 1:42









      Rene ValenzuelaRene Valenzuela

      185




      185






















          3 Answers
          3






          active

          oldest

          votes


















          1














          (The macro list is already defined and in use for the list-environment in LaTeX 2e.

          Therefore in the example below, the macro MyList is defined and used instead.)



          You can, e.g., easily turn the matter into a matter of expanding the macro that holds the list and afterwards exchanging arguments.



          With the example below, expandafter is used for expanding the macro MyList (whose expansion yields the list that is to be iterated) chronologically before via PassFirstToSecond moving that list (nested in braces) within the arrangement that is formed by the token-stream behind the fori in-construct.



          documentclass[a4paper]{article}
          usepackage{pst-solides3d}

          %%% FOR LOOP %%%
          makeatletter
          longdeffor#1in#2#3{expandafterdefcsname b:string#1endcsname{#3}%
          @forinA#1#2;}
          longdef@forinA#1#2;{ifx#2else
          def#1{#2}csname b:string#1endcsname expandafter@forinAexpandafter#1fi}
          %%%%%%%%%%%%%%%%%%
          makeatother

          %% Variables%%
          pgfmathparse{1.2}edeflinkLength{pgfmathresult}
          pgfmathparse{0.2}edefjointRadio{pgfmathresult}
          pgfmathparse{0.6}edefjointLength{pgfmathresult}

          newcommand{iterating}{%%%%%%%%%%%%%
          %%% point's structure %%%
          fori in {%
          0 0 0;% N°0
          0 0 0;% N°1
          0 0 linkLength;% N°2
          0 0 jointLength;% N°3
          0 {jointLength*0.5} {linkLength + jointRadio};% N°4
          }
          {%
          ipar
          %... call to several macros
          }%
          }


          newcommandPassFirstToSecond[2]{#2{#1}}

          newcommandMyList{%
          0 0 0;% N°0
          0 0 0;% N°1
          0 0 linkLength;% N°2
          0 0 jointLength;% N°3
          0 {jointLength*0.5} {linkLength + jointRadio};% N°4
          }%



          begin{document}

          noindentverb|iterating| yields:

          iterating

          bigskip

          noindentverb|expandafterPassFirstToSecondexpandafter{MyList}{fori in }{ipar}| yields:

          expandafterPassFirstToSecondexpandafter{MyList}{fori in }{ipar}%

          bigskip

          noindent You can also do another kind of verb|expandafter|-orgy:

          bigskip

          noindentverb|expandafterforexpandafteriexpandafter iexpandafter nexpandafter{MyList}{ipar}| yields:

          expandafterforexpandafteriexpandafter iexpandafter nexpandafter{MyList}{ipar}%

          end{document}


          enter image description here





          You can also use a macro like romannumeralExpandtimes for specifying the level of expansion that is needed with the argument which holds the list—romannumeralExpandtimes is explained in How can I know the number of expandafters when appending to a csname macro?:



          documentclass[a4paper]{article}
          usepackage{pst-solides3d}

          %%% FOR LOOP %%%
          makeatletter
          %
          newcommandexchange[2]{#2#1}%
          % A check is needed for finding out if an argument is catcode-11-"d" while there are only
          % the possibilities that the argument is either a single catcode-11-"d"
          % or a single catcode-12-"m":
          definnerdfork#1d#2#3dd{#2}%
          defdfork#1{innerdfork#1{@firstoftwo}d{@secondoftwo}dd}%
          % By means of romannumeral create as many catcode-12-characters m as expansion-steps are to take place.
          % Then by means of recursion for each of these m double the amount of `expandafter`-tokens and
          % add one `expandafter`-token within innerExp's first argument.
          defExpandtimes#1{0expandafterinnerExpexpandafter{expandafter}romannumeralnumbernumber#1 000d}
          definnerExp#1#2{dfork{#2}{#1 }{innerExp{#1#1expandafter}}}


          longdeffor#1in #2-level-expansion of #3#4{%
          expandafterdefcsname b:string#1endcsname{#4}%
          expandafterexchangeexpandafter{romannumeralExpandtimes{#2}#3;}{@forinA#1}%
          }
          longdef@forinA#1#2;{ifx#2else
          def#1{#2}csname b:string#1endcsname expandafter@forinAexpandafter#1fi}
          %%%%%%%%%%%%%%%%%%
          makeatother

          %% Variables%%
          pgfmathparse{1.2}edeflinkLength{pgfmathresult}
          pgfmathparse{0.2}edefjointRadio{pgfmathresult}
          pgfmathparse{0.6}edefjointLength{pgfmathresult}

          newcommandMyList{%
          0 0 0;%
          0 0 0;%
          0 0 linkLength;%
          0 0 jointLength;%
          0 {jointLength*0.5} {linkLength + jointRadio};%
          }%

          newcommandMyOuterListContainer{MyInnerListContainer}
          newcommandMyInnerListContainer{MyList}


          begin{document}

          begingroup
          topsep=0ex partopsep=0ex
          begin{verbatim}
          fori in 0-level-expansion of {%
          0 0 0;%
          0 0 0;%
          0 0 linkLength;%
          0 0 jointLength;%
          0 {jointLength*0.5} {linkLength + jointRadio};%
          }{ipar}%
          end{verbatim}%
          smallskip
          endgroup

          noindent yields:

          fori in 0-level-expansion of {%
          0 0 0;%
          0 0 0;%
          0 0 linkLength;%
          0 0 jointLength;%
          0 {jointLength*0.5} {linkLength + jointRadio};%
          }{ipar}%

          bigskip

          noindentverb|fori in 1-level-expansion of {MyList}{ipar}| yields:

          fori in 1-level-expansion of {MyList}{ipar}

          bigskip

          noindentverb|fori in 3-level-expansion of {MyOuterListContainer}{ipar}| yields:

          fori in 3-level-expansion of {MyOuterListContainer}{ipar}

          end{document}


          enter image description here






          share|improve this answer


























          • Thanks @UlrichDiez, that's nearing enough to the approach that i was seeking. Probably the next step (something more elegant but not necessary at all) will be the integration with the for-macro.

            – Rene Valenzuela
            Feb 28 at 22:41











          • @ReneValenzuela I added another example which exhibits one way of adding an argument to the for-macro where you can specify the level of expansion needed with the list-holding argument.

            – Ulrich Diez
            Mar 1 at 2:54





















          0














          documentclass[a4paper]{article}
          usepackage[T1]{fontenc}
          usepackage{pst-solides3d}
          %% Variables%%
          pgfmathparse{1.2}edeflinkLength{pgfmathresult}
          pgfmathparse{0.2}edefjointRadio{pgfmathresult}
          pgfmathparse{0.6}edefjointLength{pgfmathresult}
          newcommanditlist{
          0 0 0;% N°0
          0 0 0;% N°1
          0 0 linkLength;% N°2
          0 0 jointLength;% N°3
          0 {jointLength*0.5} {linkLength + jointRadio};% N°4
          }
          usepackage{listofitems}
          begin{document}
          setsepchar{;/ }
          ignoreemptyitems
          readlist*mylist{itlist}
          Iterate by row:
          foreachitemxinmylist{par%
          fbox{x}
          }

          Third item on 5th row (the actual tokens):\
          detokenizeexpandafterexpandafterexpandafter{mylist[5,3]}\
          which expands to mylist[5,3]

          1st, 3rd items on 3rd row, in a box is fbox{mylist[3,2],mylist[3,3]}

          Now to iterate on each item:
          foreachitemxinmylist{par%
          foreachitemyinmylist[xcnt]{%
          fbox{y}
          }}
          end{document}


          enter image description here






          share|improve this answer

































            0














            Here's some code I'm developing for leisure. Save the following code as extforeach-code.tex



            % extforeach-code.tex

            ExplSyntaxOn
            providecommandfpeval{fp_eval:n}

            NewDocumentCommand{nforeach}{ m +m }
            {
            tl_clear:N l__manual_nforeach_type_tl
            keys_set:nn { manual/nforeach }
            {
            type=integers,start = 1, step = 1, end = 0,
            }
            keys_set:nn { manual/nforeach } { #1 }
            __manual_nforeach_exec:n { #2 }
            }

            int_new:N g__manual_foreach_map_int
            int_new:N g__manual_fp_map_int
            tl_new:N l__manual_nforeach_type_tl

            keys_define:nn { manual/nforeach }
            {
            type .choice:,
            type .value_required:n = true,
            type/integers .code:n = tl_set:Nn l__manual_nforeach_type_tl { integers },
            type/fp .code:n = tl_set:Nn l__manual_nforeach_type_tl { fp },
            type/alph .code:n = tl_set:Nn l__manual_nforeach_type_tl { alph },
            type/Alph .code:n = tl_set:Nn l__manual_nforeach_type_tl { Alph },
            start .tl_set:N = l__manual_nforeach_start_tl,
            step .tl_set:N = l__manual_nforeach_step_tl,
            end .tl_set:N = l__manual_nforeach_end_tl,
            }

            cs_new_protected:Nn __manual_nforeach_exec:n
            {
            int_gincr:N g__manual_foreach_map_int
            str_case:Vn l__manual_nforeach_type_tl
            {
            {integers}{__manual_nforeach_exec_integers:n { #1 }}
            {fp} {__manual_nforeach_exec_fp:n { #1 }}
            {alph} {__manual_nforeach_exec_alph:Nn int_to_alph:n { #1 }}
            {Alph} {__manual_nforeach_exec_alph:Nn int_to_Alph:n { #1 }}
            }
            int_gdecr:N g__manual_foreach_map_int
            }
            cs_generate_variant:Nn str_case:nn { V }

            cs_new_protected:Nn __manual_nforeach_exec_integers:n
            {
            int_step_inline:nnnn
            { l__manual_nforeach_start_tl }
            { l__manual_nforeach_step_tl }
            { l__manual_nforeach_end_tl }
            { #1 }
            }
            cs_new_protected:Nn __manual_nforeach_exec_alph:Nn
            {
            cs_set:cn { __manual_nforeach_alph_ int_use:N g__manual_foreach_map_int :n } { #2 }
            cs_generate_variant:cn
            { __manual_nforeach_alph_ int_use:N g__manual_foreach_map_int :n }
            { f }
            int_step_inline:nnnn
            { int_from_alph:f { l__manual_nforeach_start_tl } }
            { l__manual_nforeach_step_tl }
            { int_from_alph:f { l__manual_nforeach_end_tl } }
            {
            use:c { __manual_nforeach_alph_ int_use:N g__manual_foreach_map_int :f }
            { #1 { ##1 } }
            }
            }
            cs_generate_variant:Nn cs_generate_variant:Nn { c }
            cs_generate_variant:Nn int_from_alph:n { f }

            cs_new_protected:Nn __manual_nforeach_exec_fp:n
            {
            fp_step_inline:nnnn
            { l__manual_nforeach_start_tl }
            { l__manual_nforeach_step_tl }
            { l__manual_nforeach_end_tl }
            { #1 }
            }

            NewDocumentCommand{lforeach}{ s O{} m +m }
            {
            IfBooleanTF{#1}
            {
            manual_lforeach:non { #2 } { #3 } { #4 }
            }
            {
            manual_lforeach:nnn { #2 } { #3 } { #4 }
            }
            }

            cs_new_protected:Nn manual_lforeach:nnn
            {
            keys_set:nn { manual/lforeach } { single }
            keys_set:nn { manual/lforeach } { #1 }
            clist_set:Nn l__manual_lforeach_list_clist { #2 }
            int_gincr:N g__manual_foreach_map_int
            __manual_lforeach_define:n { #3 }
            clist_map_inline:Nn l__manual_lforeach_list_clist
            {
            use:c { __manual_lforeach_ int_use:N g__manual_foreach_map_int _action:w } ##1 q_stop
            }
            int_gdecr:N g__manual_foreach_map_int
            }
            cs_generate_variant:Nn manual_lforeach:nnn { no }

            cs_new_protected:Nn __manual_lforeach_define:n
            {
            exp_last_unbraced:NcV
            cs_set:Npn
            { __manual_lforeach_ int_use:N g__manual_foreach_map_int _action:w }
            l__manual_lforeach_format_tl
            q_stop
            {#1}
            }

            keys_define:nn { manual/lforeach }
            {
            format .tl_set:N = l__manual_lforeach_format_tl,
            single .code:n = tl_set:Nn l__manual_lforeach_format_tl { ##1 },
            double .code:n = tl_set:Nn l__manual_lforeach_format_tl { ##1/##2 },
            triple .code:n = tl_set:Nn l__manual_lforeach_format_tl { ##1/##2/##3 },
            }
            ExplSyntaxOff


            Now your document can be



            documentclass{article}
            usepackage{xparse,xfp}

            input{extforeach-code.tex}

            newcommandlinkLength{1.2}
            newcommandjointRadio{0.2}
            newcommandjointLength{0.6}

            newcounter{lines}

            begin{document}

            lforeach[format=#1 #2 #3]{
            0 0 0, % N°0
            0 0 0, % N°1
            0 0 linkLength, % N°2
            0 0 jointLength, % N°3
            0 {jointLength*0.5} {linkLength + jointRadio}, % N°4
            }
            {%
            stepcounter{lines}Line thelines is fpeval{#1}~fpeval{#2}~fpeval{#3}par
            }

            end{document}


            With the help of xfp we can even evaluate expressions.



            The format key sets up a template for each item in the comma separated list given as first mandatory argument, here #1 #2 #3 means the item will consist of things like



            <subitem><space><subitem><space><subitem>


            The second mandatory argument is code that uses the arguments set up in the template. There are abbreviations single (default if nothing is specified), double and triple that stand for



            format=#1
            format=#1/#2
            format=#1/#2/#3


            respectively.



            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%2f477066%2fmodular-macro-list-structure-to-iterate-it%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









              1














              (The macro list is already defined and in use for the list-environment in LaTeX 2e.

              Therefore in the example below, the macro MyList is defined and used instead.)



              You can, e.g., easily turn the matter into a matter of expanding the macro that holds the list and afterwards exchanging arguments.



              With the example below, expandafter is used for expanding the macro MyList (whose expansion yields the list that is to be iterated) chronologically before via PassFirstToSecond moving that list (nested in braces) within the arrangement that is formed by the token-stream behind the fori in-construct.



              documentclass[a4paper]{article}
              usepackage{pst-solides3d}

              %%% FOR LOOP %%%
              makeatletter
              longdeffor#1in#2#3{expandafterdefcsname b:string#1endcsname{#3}%
              @forinA#1#2;}
              longdef@forinA#1#2;{ifx#2else
              def#1{#2}csname b:string#1endcsname expandafter@forinAexpandafter#1fi}
              %%%%%%%%%%%%%%%%%%
              makeatother

              %% Variables%%
              pgfmathparse{1.2}edeflinkLength{pgfmathresult}
              pgfmathparse{0.2}edefjointRadio{pgfmathresult}
              pgfmathparse{0.6}edefjointLength{pgfmathresult}

              newcommand{iterating}{%%%%%%%%%%%%%
              %%% point's structure %%%
              fori in {%
              0 0 0;% N°0
              0 0 0;% N°1
              0 0 linkLength;% N°2
              0 0 jointLength;% N°3
              0 {jointLength*0.5} {linkLength + jointRadio};% N°4
              }
              {%
              ipar
              %... call to several macros
              }%
              }


              newcommandPassFirstToSecond[2]{#2{#1}}

              newcommandMyList{%
              0 0 0;% N°0
              0 0 0;% N°1
              0 0 linkLength;% N°2
              0 0 jointLength;% N°3
              0 {jointLength*0.5} {linkLength + jointRadio};% N°4
              }%



              begin{document}

              noindentverb|iterating| yields:

              iterating

              bigskip

              noindentverb|expandafterPassFirstToSecondexpandafter{MyList}{fori in }{ipar}| yields:

              expandafterPassFirstToSecondexpandafter{MyList}{fori in }{ipar}%

              bigskip

              noindent You can also do another kind of verb|expandafter|-orgy:

              bigskip

              noindentverb|expandafterforexpandafteriexpandafter iexpandafter nexpandafter{MyList}{ipar}| yields:

              expandafterforexpandafteriexpandafter iexpandafter nexpandafter{MyList}{ipar}%

              end{document}


              enter image description here





              You can also use a macro like romannumeralExpandtimes for specifying the level of expansion that is needed with the argument which holds the list—romannumeralExpandtimes is explained in How can I know the number of expandafters when appending to a csname macro?:



              documentclass[a4paper]{article}
              usepackage{pst-solides3d}

              %%% FOR LOOP %%%
              makeatletter
              %
              newcommandexchange[2]{#2#1}%
              % A check is needed for finding out if an argument is catcode-11-"d" while there are only
              % the possibilities that the argument is either a single catcode-11-"d"
              % or a single catcode-12-"m":
              definnerdfork#1d#2#3dd{#2}%
              defdfork#1{innerdfork#1{@firstoftwo}d{@secondoftwo}dd}%
              % By means of romannumeral create as many catcode-12-characters m as expansion-steps are to take place.
              % Then by means of recursion for each of these m double the amount of `expandafter`-tokens and
              % add one `expandafter`-token within innerExp's first argument.
              defExpandtimes#1{0expandafterinnerExpexpandafter{expandafter}romannumeralnumbernumber#1 000d}
              definnerExp#1#2{dfork{#2}{#1 }{innerExp{#1#1expandafter}}}


              longdeffor#1in #2-level-expansion of #3#4{%
              expandafterdefcsname b:string#1endcsname{#4}%
              expandafterexchangeexpandafter{romannumeralExpandtimes{#2}#3;}{@forinA#1}%
              }
              longdef@forinA#1#2;{ifx#2else
              def#1{#2}csname b:string#1endcsname expandafter@forinAexpandafter#1fi}
              %%%%%%%%%%%%%%%%%%
              makeatother

              %% Variables%%
              pgfmathparse{1.2}edeflinkLength{pgfmathresult}
              pgfmathparse{0.2}edefjointRadio{pgfmathresult}
              pgfmathparse{0.6}edefjointLength{pgfmathresult}

              newcommandMyList{%
              0 0 0;%
              0 0 0;%
              0 0 linkLength;%
              0 0 jointLength;%
              0 {jointLength*0.5} {linkLength + jointRadio};%
              }%

              newcommandMyOuterListContainer{MyInnerListContainer}
              newcommandMyInnerListContainer{MyList}


              begin{document}

              begingroup
              topsep=0ex partopsep=0ex
              begin{verbatim}
              fori in 0-level-expansion of {%
              0 0 0;%
              0 0 0;%
              0 0 linkLength;%
              0 0 jointLength;%
              0 {jointLength*0.5} {linkLength + jointRadio};%
              }{ipar}%
              end{verbatim}%
              smallskip
              endgroup

              noindent yields:

              fori in 0-level-expansion of {%
              0 0 0;%
              0 0 0;%
              0 0 linkLength;%
              0 0 jointLength;%
              0 {jointLength*0.5} {linkLength + jointRadio};%
              }{ipar}%

              bigskip

              noindentverb|fori in 1-level-expansion of {MyList}{ipar}| yields:

              fori in 1-level-expansion of {MyList}{ipar}

              bigskip

              noindentverb|fori in 3-level-expansion of {MyOuterListContainer}{ipar}| yields:

              fori in 3-level-expansion of {MyOuterListContainer}{ipar}

              end{document}


              enter image description here






              share|improve this answer


























              • Thanks @UlrichDiez, that's nearing enough to the approach that i was seeking. Probably the next step (something more elegant but not necessary at all) will be the integration with the for-macro.

                – Rene Valenzuela
                Feb 28 at 22:41











              • @ReneValenzuela I added another example which exhibits one way of adding an argument to the for-macro where you can specify the level of expansion needed with the list-holding argument.

                – Ulrich Diez
                Mar 1 at 2:54


















              1














              (The macro list is already defined and in use for the list-environment in LaTeX 2e.

              Therefore in the example below, the macro MyList is defined and used instead.)



              You can, e.g., easily turn the matter into a matter of expanding the macro that holds the list and afterwards exchanging arguments.



              With the example below, expandafter is used for expanding the macro MyList (whose expansion yields the list that is to be iterated) chronologically before via PassFirstToSecond moving that list (nested in braces) within the arrangement that is formed by the token-stream behind the fori in-construct.



              documentclass[a4paper]{article}
              usepackage{pst-solides3d}

              %%% FOR LOOP %%%
              makeatletter
              longdeffor#1in#2#3{expandafterdefcsname b:string#1endcsname{#3}%
              @forinA#1#2;}
              longdef@forinA#1#2;{ifx#2else
              def#1{#2}csname b:string#1endcsname expandafter@forinAexpandafter#1fi}
              %%%%%%%%%%%%%%%%%%
              makeatother

              %% Variables%%
              pgfmathparse{1.2}edeflinkLength{pgfmathresult}
              pgfmathparse{0.2}edefjointRadio{pgfmathresult}
              pgfmathparse{0.6}edefjointLength{pgfmathresult}

              newcommand{iterating}{%%%%%%%%%%%%%
              %%% point's structure %%%
              fori in {%
              0 0 0;% N°0
              0 0 0;% N°1
              0 0 linkLength;% N°2
              0 0 jointLength;% N°3
              0 {jointLength*0.5} {linkLength + jointRadio};% N°4
              }
              {%
              ipar
              %... call to several macros
              }%
              }


              newcommandPassFirstToSecond[2]{#2{#1}}

              newcommandMyList{%
              0 0 0;% N°0
              0 0 0;% N°1
              0 0 linkLength;% N°2
              0 0 jointLength;% N°3
              0 {jointLength*0.5} {linkLength + jointRadio};% N°4
              }%



              begin{document}

              noindentverb|iterating| yields:

              iterating

              bigskip

              noindentverb|expandafterPassFirstToSecondexpandafter{MyList}{fori in }{ipar}| yields:

              expandafterPassFirstToSecondexpandafter{MyList}{fori in }{ipar}%

              bigskip

              noindent You can also do another kind of verb|expandafter|-orgy:

              bigskip

              noindentverb|expandafterforexpandafteriexpandafter iexpandafter nexpandafter{MyList}{ipar}| yields:

              expandafterforexpandafteriexpandafter iexpandafter nexpandafter{MyList}{ipar}%

              end{document}


              enter image description here





              You can also use a macro like romannumeralExpandtimes for specifying the level of expansion that is needed with the argument which holds the list—romannumeralExpandtimes is explained in How can I know the number of expandafters when appending to a csname macro?:



              documentclass[a4paper]{article}
              usepackage{pst-solides3d}

              %%% FOR LOOP %%%
              makeatletter
              %
              newcommandexchange[2]{#2#1}%
              % A check is needed for finding out if an argument is catcode-11-"d" while there are only
              % the possibilities that the argument is either a single catcode-11-"d"
              % or a single catcode-12-"m":
              definnerdfork#1d#2#3dd{#2}%
              defdfork#1{innerdfork#1{@firstoftwo}d{@secondoftwo}dd}%
              % By means of romannumeral create as many catcode-12-characters m as expansion-steps are to take place.
              % Then by means of recursion for each of these m double the amount of `expandafter`-tokens and
              % add one `expandafter`-token within innerExp's first argument.
              defExpandtimes#1{0expandafterinnerExpexpandafter{expandafter}romannumeralnumbernumber#1 000d}
              definnerExp#1#2{dfork{#2}{#1 }{innerExp{#1#1expandafter}}}


              longdeffor#1in #2-level-expansion of #3#4{%
              expandafterdefcsname b:string#1endcsname{#4}%
              expandafterexchangeexpandafter{romannumeralExpandtimes{#2}#3;}{@forinA#1}%
              }
              longdef@forinA#1#2;{ifx#2else
              def#1{#2}csname b:string#1endcsname expandafter@forinAexpandafter#1fi}
              %%%%%%%%%%%%%%%%%%
              makeatother

              %% Variables%%
              pgfmathparse{1.2}edeflinkLength{pgfmathresult}
              pgfmathparse{0.2}edefjointRadio{pgfmathresult}
              pgfmathparse{0.6}edefjointLength{pgfmathresult}

              newcommandMyList{%
              0 0 0;%
              0 0 0;%
              0 0 linkLength;%
              0 0 jointLength;%
              0 {jointLength*0.5} {linkLength + jointRadio};%
              }%

              newcommandMyOuterListContainer{MyInnerListContainer}
              newcommandMyInnerListContainer{MyList}


              begin{document}

              begingroup
              topsep=0ex partopsep=0ex
              begin{verbatim}
              fori in 0-level-expansion of {%
              0 0 0;%
              0 0 0;%
              0 0 linkLength;%
              0 0 jointLength;%
              0 {jointLength*0.5} {linkLength + jointRadio};%
              }{ipar}%
              end{verbatim}%
              smallskip
              endgroup

              noindent yields:

              fori in 0-level-expansion of {%
              0 0 0;%
              0 0 0;%
              0 0 linkLength;%
              0 0 jointLength;%
              0 {jointLength*0.5} {linkLength + jointRadio};%
              }{ipar}%

              bigskip

              noindentverb|fori in 1-level-expansion of {MyList}{ipar}| yields:

              fori in 1-level-expansion of {MyList}{ipar}

              bigskip

              noindentverb|fori in 3-level-expansion of {MyOuterListContainer}{ipar}| yields:

              fori in 3-level-expansion of {MyOuterListContainer}{ipar}

              end{document}


              enter image description here






              share|improve this answer


























              • Thanks @UlrichDiez, that's nearing enough to the approach that i was seeking. Probably the next step (something more elegant but not necessary at all) will be the integration with the for-macro.

                – Rene Valenzuela
                Feb 28 at 22:41











              • @ReneValenzuela I added another example which exhibits one way of adding an argument to the for-macro where you can specify the level of expansion needed with the list-holding argument.

                – Ulrich Diez
                Mar 1 at 2:54
















              1












              1








              1







              (The macro list is already defined and in use for the list-environment in LaTeX 2e.

              Therefore in the example below, the macro MyList is defined and used instead.)



              You can, e.g., easily turn the matter into a matter of expanding the macro that holds the list and afterwards exchanging arguments.



              With the example below, expandafter is used for expanding the macro MyList (whose expansion yields the list that is to be iterated) chronologically before via PassFirstToSecond moving that list (nested in braces) within the arrangement that is formed by the token-stream behind the fori in-construct.



              documentclass[a4paper]{article}
              usepackage{pst-solides3d}

              %%% FOR LOOP %%%
              makeatletter
              longdeffor#1in#2#3{expandafterdefcsname b:string#1endcsname{#3}%
              @forinA#1#2;}
              longdef@forinA#1#2;{ifx#2else
              def#1{#2}csname b:string#1endcsname expandafter@forinAexpandafter#1fi}
              %%%%%%%%%%%%%%%%%%
              makeatother

              %% Variables%%
              pgfmathparse{1.2}edeflinkLength{pgfmathresult}
              pgfmathparse{0.2}edefjointRadio{pgfmathresult}
              pgfmathparse{0.6}edefjointLength{pgfmathresult}

              newcommand{iterating}{%%%%%%%%%%%%%
              %%% point's structure %%%
              fori in {%
              0 0 0;% N°0
              0 0 0;% N°1
              0 0 linkLength;% N°2
              0 0 jointLength;% N°3
              0 {jointLength*0.5} {linkLength + jointRadio};% N°4
              }
              {%
              ipar
              %... call to several macros
              }%
              }


              newcommandPassFirstToSecond[2]{#2{#1}}

              newcommandMyList{%
              0 0 0;% N°0
              0 0 0;% N°1
              0 0 linkLength;% N°2
              0 0 jointLength;% N°3
              0 {jointLength*0.5} {linkLength + jointRadio};% N°4
              }%



              begin{document}

              noindentverb|iterating| yields:

              iterating

              bigskip

              noindentverb|expandafterPassFirstToSecondexpandafter{MyList}{fori in }{ipar}| yields:

              expandafterPassFirstToSecondexpandafter{MyList}{fori in }{ipar}%

              bigskip

              noindent You can also do another kind of verb|expandafter|-orgy:

              bigskip

              noindentverb|expandafterforexpandafteriexpandafter iexpandafter nexpandafter{MyList}{ipar}| yields:

              expandafterforexpandafteriexpandafter iexpandafter nexpandafter{MyList}{ipar}%

              end{document}


              enter image description here





              You can also use a macro like romannumeralExpandtimes for specifying the level of expansion that is needed with the argument which holds the list—romannumeralExpandtimes is explained in How can I know the number of expandafters when appending to a csname macro?:



              documentclass[a4paper]{article}
              usepackage{pst-solides3d}

              %%% FOR LOOP %%%
              makeatletter
              %
              newcommandexchange[2]{#2#1}%
              % A check is needed for finding out if an argument is catcode-11-"d" while there are only
              % the possibilities that the argument is either a single catcode-11-"d"
              % or a single catcode-12-"m":
              definnerdfork#1d#2#3dd{#2}%
              defdfork#1{innerdfork#1{@firstoftwo}d{@secondoftwo}dd}%
              % By means of romannumeral create as many catcode-12-characters m as expansion-steps are to take place.
              % Then by means of recursion for each of these m double the amount of `expandafter`-tokens and
              % add one `expandafter`-token within innerExp's first argument.
              defExpandtimes#1{0expandafterinnerExpexpandafter{expandafter}romannumeralnumbernumber#1 000d}
              definnerExp#1#2{dfork{#2}{#1 }{innerExp{#1#1expandafter}}}


              longdeffor#1in #2-level-expansion of #3#4{%
              expandafterdefcsname b:string#1endcsname{#4}%
              expandafterexchangeexpandafter{romannumeralExpandtimes{#2}#3;}{@forinA#1}%
              }
              longdef@forinA#1#2;{ifx#2else
              def#1{#2}csname b:string#1endcsname expandafter@forinAexpandafter#1fi}
              %%%%%%%%%%%%%%%%%%
              makeatother

              %% Variables%%
              pgfmathparse{1.2}edeflinkLength{pgfmathresult}
              pgfmathparse{0.2}edefjointRadio{pgfmathresult}
              pgfmathparse{0.6}edefjointLength{pgfmathresult}

              newcommandMyList{%
              0 0 0;%
              0 0 0;%
              0 0 linkLength;%
              0 0 jointLength;%
              0 {jointLength*0.5} {linkLength + jointRadio};%
              }%

              newcommandMyOuterListContainer{MyInnerListContainer}
              newcommandMyInnerListContainer{MyList}


              begin{document}

              begingroup
              topsep=0ex partopsep=0ex
              begin{verbatim}
              fori in 0-level-expansion of {%
              0 0 0;%
              0 0 0;%
              0 0 linkLength;%
              0 0 jointLength;%
              0 {jointLength*0.5} {linkLength + jointRadio};%
              }{ipar}%
              end{verbatim}%
              smallskip
              endgroup

              noindent yields:

              fori in 0-level-expansion of {%
              0 0 0;%
              0 0 0;%
              0 0 linkLength;%
              0 0 jointLength;%
              0 {jointLength*0.5} {linkLength + jointRadio};%
              }{ipar}%

              bigskip

              noindentverb|fori in 1-level-expansion of {MyList}{ipar}| yields:

              fori in 1-level-expansion of {MyList}{ipar}

              bigskip

              noindentverb|fori in 3-level-expansion of {MyOuterListContainer}{ipar}| yields:

              fori in 3-level-expansion of {MyOuterListContainer}{ipar}

              end{document}


              enter image description here






              share|improve this answer















              (The macro list is already defined and in use for the list-environment in LaTeX 2e.

              Therefore in the example below, the macro MyList is defined and used instead.)



              You can, e.g., easily turn the matter into a matter of expanding the macro that holds the list and afterwards exchanging arguments.



              With the example below, expandafter is used for expanding the macro MyList (whose expansion yields the list that is to be iterated) chronologically before via PassFirstToSecond moving that list (nested in braces) within the arrangement that is formed by the token-stream behind the fori in-construct.



              documentclass[a4paper]{article}
              usepackage{pst-solides3d}

              %%% FOR LOOP %%%
              makeatletter
              longdeffor#1in#2#3{expandafterdefcsname b:string#1endcsname{#3}%
              @forinA#1#2;}
              longdef@forinA#1#2;{ifx#2else
              def#1{#2}csname b:string#1endcsname expandafter@forinAexpandafter#1fi}
              %%%%%%%%%%%%%%%%%%
              makeatother

              %% Variables%%
              pgfmathparse{1.2}edeflinkLength{pgfmathresult}
              pgfmathparse{0.2}edefjointRadio{pgfmathresult}
              pgfmathparse{0.6}edefjointLength{pgfmathresult}

              newcommand{iterating}{%%%%%%%%%%%%%
              %%% point's structure %%%
              fori in {%
              0 0 0;% N°0
              0 0 0;% N°1
              0 0 linkLength;% N°2
              0 0 jointLength;% N°3
              0 {jointLength*0.5} {linkLength + jointRadio};% N°4
              }
              {%
              ipar
              %... call to several macros
              }%
              }


              newcommandPassFirstToSecond[2]{#2{#1}}

              newcommandMyList{%
              0 0 0;% N°0
              0 0 0;% N°1
              0 0 linkLength;% N°2
              0 0 jointLength;% N°3
              0 {jointLength*0.5} {linkLength + jointRadio};% N°4
              }%



              begin{document}

              noindentverb|iterating| yields:

              iterating

              bigskip

              noindentverb|expandafterPassFirstToSecondexpandafter{MyList}{fori in }{ipar}| yields:

              expandafterPassFirstToSecondexpandafter{MyList}{fori in }{ipar}%

              bigskip

              noindent You can also do another kind of verb|expandafter|-orgy:

              bigskip

              noindentverb|expandafterforexpandafteriexpandafter iexpandafter nexpandafter{MyList}{ipar}| yields:

              expandafterforexpandafteriexpandafter iexpandafter nexpandafter{MyList}{ipar}%

              end{document}


              enter image description here





              You can also use a macro like romannumeralExpandtimes for specifying the level of expansion that is needed with the argument which holds the list—romannumeralExpandtimes is explained in How can I know the number of expandafters when appending to a csname macro?:



              documentclass[a4paper]{article}
              usepackage{pst-solides3d}

              %%% FOR LOOP %%%
              makeatletter
              %
              newcommandexchange[2]{#2#1}%
              % A check is needed for finding out if an argument is catcode-11-"d" while there are only
              % the possibilities that the argument is either a single catcode-11-"d"
              % or a single catcode-12-"m":
              definnerdfork#1d#2#3dd{#2}%
              defdfork#1{innerdfork#1{@firstoftwo}d{@secondoftwo}dd}%
              % By means of romannumeral create as many catcode-12-characters m as expansion-steps are to take place.
              % Then by means of recursion for each of these m double the amount of `expandafter`-tokens and
              % add one `expandafter`-token within innerExp's first argument.
              defExpandtimes#1{0expandafterinnerExpexpandafter{expandafter}romannumeralnumbernumber#1 000d}
              definnerExp#1#2{dfork{#2}{#1 }{innerExp{#1#1expandafter}}}


              longdeffor#1in #2-level-expansion of #3#4{%
              expandafterdefcsname b:string#1endcsname{#4}%
              expandafterexchangeexpandafter{romannumeralExpandtimes{#2}#3;}{@forinA#1}%
              }
              longdef@forinA#1#2;{ifx#2else
              def#1{#2}csname b:string#1endcsname expandafter@forinAexpandafter#1fi}
              %%%%%%%%%%%%%%%%%%
              makeatother

              %% Variables%%
              pgfmathparse{1.2}edeflinkLength{pgfmathresult}
              pgfmathparse{0.2}edefjointRadio{pgfmathresult}
              pgfmathparse{0.6}edefjointLength{pgfmathresult}

              newcommandMyList{%
              0 0 0;%
              0 0 0;%
              0 0 linkLength;%
              0 0 jointLength;%
              0 {jointLength*0.5} {linkLength + jointRadio};%
              }%

              newcommandMyOuterListContainer{MyInnerListContainer}
              newcommandMyInnerListContainer{MyList}


              begin{document}

              begingroup
              topsep=0ex partopsep=0ex
              begin{verbatim}
              fori in 0-level-expansion of {%
              0 0 0;%
              0 0 0;%
              0 0 linkLength;%
              0 0 jointLength;%
              0 {jointLength*0.5} {linkLength + jointRadio};%
              }{ipar}%
              end{verbatim}%
              smallskip
              endgroup

              noindent yields:

              fori in 0-level-expansion of {%
              0 0 0;%
              0 0 0;%
              0 0 linkLength;%
              0 0 jointLength;%
              0 {jointLength*0.5} {linkLength + jointRadio};%
              }{ipar}%

              bigskip

              noindentverb|fori in 1-level-expansion of {MyList}{ipar}| yields:

              fori in 1-level-expansion of {MyList}{ipar}

              bigskip

              noindentverb|fori in 3-level-expansion of {MyOuterListContainer}{ipar}| yields:

              fori in 3-level-expansion of {MyOuterListContainer}{ipar}

              end{document}


              enter image description here







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Mar 1 at 2:52

























              answered Feb 28 at 12:52









              Ulrich DiezUlrich Diez

              5,275619




              5,275619













              • Thanks @UlrichDiez, that's nearing enough to the approach that i was seeking. Probably the next step (something more elegant but not necessary at all) will be the integration with the for-macro.

                – Rene Valenzuela
                Feb 28 at 22:41











              • @ReneValenzuela I added another example which exhibits one way of adding an argument to the for-macro where you can specify the level of expansion needed with the list-holding argument.

                – Ulrich Diez
                Mar 1 at 2:54





















              • Thanks @UlrichDiez, that's nearing enough to the approach that i was seeking. Probably the next step (something more elegant but not necessary at all) will be the integration with the for-macro.

                – Rene Valenzuela
                Feb 28 at 22:41











              • @ReneValenzuela I added another example which exhibits one way of adding an argument to the for-macro where you can specify the level of expansion needed with the list-holding argument.

                – Ulrich Diez
                Mar 1 at 2:54



















              Thanks @UlrichDiez, that's nearing enough to the approach that i was seeking. Probably the next step (something more elegant but not necessary at all) will be the integration with the for-macro.

              – Rene Valenzuela
              Feb 28 at 22:41





              Thanks @UlrichDiez, that's nearing enough to the approach that i was seeking. Probably the next step (something more elegant but not necessary at all) will be the integration with the for-macro.

              – Rene Valenzuela
              Feb 28 at 22:41













              @ReneValenzuela I added another example which exhibits one way of adding an argument to the for-macro where you can specify the level of expansion needed with the list-holding argument.

              – Ulrich Diez
              Mar 1 at 2:54







              @ReneValenzuela I added another example which exhibits one way of adding an argument to the for-macro where you can specify the level of expansion needed with the list-holding argument.

              – Ulrich Diez
              Mar 1 at 2:54













              0














              documentclass[a4paper]{article}
              usepackage[T1]{fontenc}
              usepackage{pst-solides3d}
              %% Variables%%
              pgfmathparse{1.2}edeflinkLength{pgfmathresult}
              pgfmathparse{0.2}edefjointRadio{pgfmathresult}
              pgfmathparse{0.6}edefjointLength{pgfmathresult}
              newcommanditlist{
              0 0 0;% N°0
              0 0 0;% N°1
              0 0 linkLength;% N°2
              0 0 jointLength;% N°3
              0 {jointLength*0.5} {linkLength + jointRadio};% N°4
              }
              usepackage{listofitems}
              begin{document}
              setsepchar{;/ }
              ignoreemptyitems
              readlist*mylist{itlist}
              Iterate by row:
              foreachitemxinmylist{par%
              fbox{x}
              }

              Third item on 5th row (the actual tokens):\
              detokenizeexpandafterexpandafterexpandafter{mylist[5,3]}\
              which expands to mylist[5,3]

              1st, 3rd items on 3rd row, in a box is fbox{mylist[3,2],mylist[3,3]}

              Now to iterate on each item:
              foreachitemxinmylist{par%
              foreachitemyinmylist[xcnt]{%
              fbox{y}
              }}
              end{document}


              enter image description here






              share|improve this answer






























                0














                documentclass[a4paper]{article}
                usepackage[T1]{fontenc}
                usepackage{pst-solides3d}
                %% Variables%%
                pgfmathparse{1.2}edeflinkLength{pgfmathresult}
                pgfmathparse{0.2}edefjointRadio{pgfmathresult}
                pgfmathparse{0.6}edefjointLength{pgfmathresult}
                newcommanditlist{
                0 0 0;% N°0
                0 0 0;% N°1
                0 0 linkLength;% N°2
                0 0 jointLength;% N°3
                0 {jointLength*0.5} {linkLength + jointRadio};% N°4
                }
                usepackage{listofitems}
                begin{document}
                setsepchar{;/ }
                ignoreemptyitems
                readlist*mylist{itlist}
                Iterate by row:
                foreachitemxinmylist{par%
                fbox{x}
                }

                Third item on 5th row (the actual tokens):\
                detokenizeexpandafterexpandafterexpandafter{mylist[5,3]}\
                which expands to mylist[5,3]

                1st, 3rd items on 3rd row, in a box is fbox{mylist[3,2],mylist[3,3]}

                Now to iterate on each item:
                foreachitemxinmylist{par%
                foreachitemyinmylist[xcnt]{%
                fbox{y}
                }}
                end{document}


                enter image description here






                share|improve this answer




























                  0












                  0








                  0







                  documentclass[a4paper]{article}
                  usepackage[T1]{fontenc}
                  usepackage{pst-solides3d}
                  %% Variables%%
                  pgfmathparse{1.2}edeflinkLength{pgfmathresult}
                  pgfmathparse{0.2}edefjointRadio{pgfmathresult}
                  pgfmathparse{0.6}edefjointLength{pgfmathresult}
                  newcommanditlist{
                  0 0 0;% N°0
                  0 0 0;% N°1
                  0 0 linkLength;% N°2
                  0 0 jointLength;% N°3
                  0 {jointLength*0.5} {linkLength + jointRadio};% N°4
                  }
                  usepackage{listofitems}
                  begin{document}
                  setsepchar{;/ }
                  ignoreemptyitems
                  readlist*mylist{itlist}
                  Iterate by row:
                  foreachitemxinmylist{par%
                  fbox{x}
                  }

                  Third item on 5th row (the actual tokens):\
                  detokenizeexpandafterexpandafterexpandafter{mylist[5,3]}\
                  which expands to mylist[5,3]

                  1st, 3rd items on 3rd row, in a box is fbox{mylist[3,2],mylist[3,3]}

                  Now to iterate on each item:
                  foreachitemxinmylist{par%
                  foreachitemyinmylist[xcnt]{%
                  fbox{y}
                  }}
                  end{document}


                  enter image description here






                  share|improve this answer















                  documentclass[a4paper]{article}
                  usepackage[T1]{fontenc}
                  usepackage{pst-solides3d}
                  %% Variables%%
                  pgfmathparse{1.2}edeflinkLength{pgfmathresult}
                  pgfmathparse{0.2}edefjointRadio{pgfmathresult}
                  pgfmathparse{0.6}edefjointLength{pgfmathresult}
                  newcommanditlist{
                  0 0 0;% N°0
                  0 0 0;% N°1
                  0 0 linkLength;% N°2
                  0 0 jointLength;% N°3
                  0 {jointLength*0.5} {linkLength + jointRadio};% N°4
                  }
                  usepackage{listofitems}
                  begin{document}
                  setsepchar{;/ }
                  ignoreemptyitems
                  readlist*mylist{itlist}
                  Iterate by row:
                  foreachitemxinmylist{par%
                  fbox{x}
                  }

                  Third item on 5th row (the actual tokens):\
                  detokenizeexpandafterexpandafterexpandafter{mylist[5,3]}\
                  which expands to mylist[5,3]

                  1st, 3rd items on 3rd row, in a box is fbox{mylist[3,2],mylist[3,3]}

                  Now to iterate on each item:
                  foreachitemxinmylist{par%
                  foreachitemyinmylist[xcnt]{%
                  fbox{y}
                  }}
                  end{document}


                  enter image description here







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Feb 28 at 13:30

























                  answered Feb 28 at 12:58









                  Steven B. SegletesSteven B. Segletes

                  157k9203411




                  157k9203411























                      0














                      Here's some code I'm developing for leisure. Save the following code as extforeach-code.tex



                      % extforeach-code.tex

                      ExplSyntaxOn
                      providecommandfpeval{fp_eval:n}

                      NewDocumentCommand{nforeach}{ m +m }
                      {
                      tl_clear:N l__manual_nforeach_type_tl
                      keys_set:nn { manual/nforeach }
                      {
                      type=integers,start = 1, step = 1, end = 0,
                      }
                      keys_set:nn { manual/nforeach } { #1 }
                      __manual_nforeach_exec:n { #2 }
                      }

                      int_new:N g__manual_foreach_map_int
                      int_new:N g__manual_fp_map_int
                      tl_new:N l__manual_nforeach_type_tl

                      keys_define:nn { manual/nforeach }
                      {
                      type .choice:,
                      type .value_required:n = true,
                      type/integers .code:n = tl_set:Nn l__manual_nforeach_type_tl { integers },
                      type/fp .code:n = tl_set:Nn l__manual_nforeach_type_tl { fp },
                      type/alph .code:n = tl_set:Nn l__manual_nforeach_type_tl { alph },
                      type/Alph .code:n = tl_set:Nn l__manual_nforeach_type_tl { Alph },
                      start .tl_set:N = l__manual_nforeach_start_tl,
                      step .tl_set:N = l__manual_nforeach_step_tl,
                      end .tl_set:N = l__manual_nforeach_end_tl,
                      }

                      cs_new_protected:Nn __manual_nforeach_exec:n
                      {
                      int_gincr:N g__manual_foreach_map_int
                      str_case:Vn l__manual_nforeach_type_tl
                      {
                      {integers}{__manual_nforeach_exec_integers:n { #1 }}
                      {fp} {__manual_nforeach_exec_fp:n { #1 }}
                      {alph} {__manual_nforeach_exec_alph:Nn int_to_alph:n { #1 }}
                      {Alph} {__manual_nforeach_exec_alph:Nn int_to_Alph:n { #1 }}
                      }
                      int_gdecr:N g__manual_foreach_map_int
                      }
                      cs_generate_variant:Nn str_case:nn { V }

                      cs_new_protected:Nn __manual_nforeach_exec_integers:n
                      {
                      int_step_inline:nnnn
                      { l__manual_nforeach_start_tl }
                      { l__manual_nforeach_step_tl }
                      { l__manual_nforeach_end_tl }
                      { #1 }
                      }
                      cs_new_protected:Nn __manual_nforeach_exec_alph:Nn
                      {
                      cs_set:cn { __manual_nforeach_alph_ int_use:N g__manual_foreach_map_int :n } { #2 }
                      cs_generate_variant:cn
                      { __manual_nforeach_alph_ int_use:N g__manual_foreach_map_int :n }
                      { f }
                      int_step_inline:nnnn
                      { int_from_alph:f { l__manual_nforeach_start_tl } }
                      { l__manual_nforeach_step_tl }
                      { int_from_alph:f { l__manual_nforeach_end_tl } }
                      {
                      use:c { __manual_nforeach_alph_ int_use:N g__manual_foreach_map_int :f }
                      { #1 { ##1 } }
                      }
                      }
                      cs_generate_variant:Nn cs_generate_variant:Nn { c }
                      cs_generate_variant:Nn int_from_alph:n { f }

                      cs_new_protected:Nn __manual_nforeach_exec_fp:n
                      {
                      fp_step_inline:nnnn
                      { l__manual_nforeach_start_tl }
                      { l__manual_nforeach_step_tl }
                      { l__manual_nforeach_end_tl }
                      { #1 }
                      }

                      NewDocumentCommand{lforeach}{ s O{} m +m }
                      {
                      IfBooleanTF{#1}
                      {
                      manual_lforeach:non { #2 } { #3 } { #4 }
                      }
                      {
                      manual_lforeach:nnn { #2 } { #3 } { #4 }
                      }
                      }

                      cs_new_protected:Nn manual_lforeach:nnn
                      {
                      keys_set:nn { manual/lforeach } { single }
                      keys_set:nn { manual/lforeach } { #1 }
                      clist_set:Nn l__manual_lforeach_list_clist { #2 }
                      int_gincr:N g__manual_foreach_map_int
                      __manual_lforeach_define:n { #3 }
                      clist_map_inline:Nn l__manual_lforeach_list_clist
                      {
                      use:c { __manual_lforeach_ int_use:N g__manual_foreach_map_int _action:w } ##1 q_stop
                      }
                      int_gdecr:N g__manual_foreach_map_int
                      }
                      cs_generate_variant:Nn manual_lforeach:nnn { no }

                      cs_new_protected:Nn __manual_lforeach_define:n
                      {
                      exp_last_unbraced:NcV
                      cs_set:Npn
                      { __manual_lforeach_ int_use:N g__manual_foreach_map_int _action:w }
                      l__manual_lforeach_format_tl
                      q_stop
                      {#1}
                      }

                      keys_define:nn { manual/lforeach }
                      {
                      format .tl_set:N = l__manual_lforeach_format_tl,
                      single .code:n = tl_set:Nn l__manual_lforeach_format_tl { ##1 },
                      double .code:n = tl_set:Nn l__manual_lforeach_format_tl { ##1/##2 },
                      triple .code:n = tl_set:Nn l__manual_lforeach_format_tl { ##1/##2/##3 },
                      }
                      ExplSyntaxOff


                      Now your document can be



                      documentclass{article}
                      usepackage{xparse,xfp}

                      input{extforeach-code.tex}

                      newcommandlinkLength{1.2}
                      newcommandjointRadio{0.2}
                      newcommandjointLength{0.6}

                      newcounter{lines}

                      begin{document}

                      lforeach[format=#1 #2 #3]{
                      0 0 0, % N°0
                      0 0 0, % N°1
                      0 0 linkLength, % N°2
                      0 0 jointLength, % N°3
                      0 {jointLength*0.5} {linkLength + jointRadio}, % N°4
                      }
                      {%
                      stepcounter{lines}Line thelines is fpeval{#1}~fpeval{#2}~fpeval{#3}par
                      }

                      end{document}


                      With the help of xfp we can even evaluate expressions.



                      The format key sets up a template for each item in the comma separated list given as first mandatory argument, here #1 #2 #3 means the item will consist of things like



                      <subitem><space><subitem><space><subitem>


                      The second mandatory argument is code that uses the arguments set up in the template. There are abbreviations single (default if nothing is specified), double and triple that stand for



                      format=#1
                      format=#1/#2
                      format=#1/#2/#3


                      respectively.



                      enter image description here






                      share|improve this answer




























                        0














                        Here's some code I'm developing for leisure. Save the following code as extforeach-code.tex



                        % extforeach-code.tex

                        ExplSyntaxOn
                        providecommandfpeval{fp_eval:n}

                        NewDocumentCommand{nforeach}{ m +m }
                        {
                        tl_clear:N l__manual_nforeach_type_tl
                        keys_set:nn { manual/nforeach }
                        {
                        type=integers,start = 1, step = 1, end = 0,
                        }
                        keys_set:nn { manual/nforeach } { #1 }
                        __manual_nforeach_exec:n { #2 }
                        }

                        int_new:N g__manual_foreach_map_int
                        int_new:N g__manual_fp_map_int
                        tl_new:N l__manual_nforeach_type_tl

                        keys_define:nn { manual/nforeach }
                        {
                        type .choice:,
                        type .value_required:n = true,
                        type/integers .code:n = tl_set:Nn l__manual_nforeach_type_tl { integers },
                        type/fp .code:n = tl_set:Nn l__manual_nforeach_type_tl { fp },
                        type/alph .code:n = tl_set:Nn l__manual_nforeach_type_tl { alph },
                        type/Alph .code:n = tl_set:Nn l__manual_nforeach_type_tl { Alph },
                        start .tl_set:N = l__manual_nforeach_start_tl,
                        step .tl_set:N = l__manual_nforeach_step_tl,
                        end .tl_set:N = l__manual_nforeach_end_tl,
                        }

                        cs_new_protected:Nn __manual_nforeach_exec:n
                        {
                        int_gincr:N g__manual_foreach_map_int
                        str_case:Vn l__manual_nforeach_type_tl
                        {
                        {integers}{__manual_nforeach_exec_integers:n { #1 }}
                        {fp} {__manual_nforeach_exec_fp:n { #1 }}
                        {alph} {__manual_nforeach_exec_alph:Nn int_to_alph:n { #1 }}
                        {Alph} {__manual_nforeach_exec_alph:Nn int_to_Alph:n { #1 }}
                        }
                        int_gdecr:N g__manual_foreach_map_int
                        }
                        cs_generate_variant:Nn str_case:nn { V }

                        cs_new_protected:Nn __manual_nforeach_exec_integers:n
                        {
                        int_step_inline:nnnn
                        { l__manual_nforeach_start_tl }
                        { l__manual_nforeach_step_tl }
                        { l__manual_nforeach_end_tl }
                        { #1 }
                        }
                        cs_new_protected:Nn __manual_nforeach_exec_alph:Nn
                        {
                        cs_set:cn { __manual_nforeach_alph_ int_use:N g__manual_foreach_map_int :n } { #2 }
                        cs_generate_variant:cn
                        { __manual_nforeach_alph_ int_use:N g__manual_foreach_map_int :n }
                        { f }
                        int_step_inline:nnnn
                        { int_from_alph:f { l__manual_nforeach_start_tl } }
                        { l__manual_nforeach_step_tl }
                        { int_from_alph:f { l__manual_nforeach_end_tl } }
                        {
                        use:c { __manual_nforeach_alph_ int_use:N g__manual_foreach_map_int :f }
                        { #1 { ##1 } }
                        }
                        }
                        cs_generate_variant:Nn cs_generate_variant:Nn { c }
                        cs_generate_variant:Nn int_from_alph:n { f }

                        cs_new_protected:Nn __manual_nforeach_exec_fp:n
                        {
                        fp_step_inline:nnnn
                        { l__manual_nforeach_start_tl }
                        { l__manual_nforeach_step_tl }
                        { l__manual_nforeach_end_tl }
                        { #1 }
                        }

                        NewDocumentCommand{lforeach}{ s O{} m +m }
                        {
                        IfBooleanTF{#1}
                        {
                        manual_lforeach:non { #2 } { #3 } { #4 }
                        }
                        {
                        manual_lforeach:nnn { #2 } { #3 } { #4 }
                        }
                        }

                        cs_new_protected:Nn manual_lforeach:nnn
                        {
                        keys_set:nn { manual/lforeach } { single }
                        keys_set:nn { manual/lforeach } { #1 }
                        clist_set:Nn l__manual_lforeach_list_clist { #2 }
                        int_gincr:N g__manual_foreach_map_int
                        __manual_lforeach_define:n { #3 }
                        clist_map_inline:Nn l__manual_lforeach_list_clist
                        {
                        use:c { __manual_lforeach_ int_use:N g__manual_foreach_map_int _action:w } ##1 q_stop
                        }
                        int_gdecr:N g__manual_foreach_map_int
                        }
                        cs_generate_variant:Nn manual_lforeach:nnn { no }

                        cs_new_protected:Nn __manual_lforeach_define:n
                        {
                        exp_last_unbraced:NcV
                        cs_set:Npn
                        { __manual_lforeach_ int_use:N g__manual_foreach_map_int _action:w }
                        l__manual_lforeach_format_tl
                        q_stop
                        {#1}
                        }

                        keys_define:nn { manual/lforeach }
                        {
                        format .tl_set:N = l__manual_lforeach_format_tl,
                        single .code:n = tl_set:Nn l__manual_lforeach_format_tl { ##1 },
                        double .code:n = tl_set:Nn l__manual_lforeach_format_tl { ##1/##2 },
                        triple .code:n = tl_set:Nn l__manual_lforeach_format_tl { ##1/##2/##3 },
                        }
                        ExplSyntaxOff


                        Now your document can be



                        documentclass{article}
                        usepackage{xparse,xfp}

                        input{extforeach-code.tex}

                        newcommandlinkLength{1.2}
                        newcommandjointRadio{0.2}
                        newcommandjointLength{0.6}

                        newcounter{lines}

                        begin{document}

                        lforeach[format=#1 #2 #3]{
                        0 0 0, % N°0
                        0 0 0, % N°1
                        0 0 linkLength, % N°2
                        0 0 jointLength, % N°3
                        0 {jointLength*0.5} {linkLength + jointRadio}, % N°4
                        }
                        {%
                        stepcounter{lines}Line thelines is fpeval{#1}~fpeval{#2}~fpeval{#3}par
                        }

                        end{document}


                        With the help of xfp we can even evaluate expressions.



                        The format key sets up a template for each item in the comma separated list given as first mandatory argument, here #1 #2 #3 means the item will consist of things like



                        <subitem><space><subitem><space><subitem>


                        The second mandatory argument is code that uses the arguments set up in the template. There are abbreviations single (default if nothing is specified), double and triple that stand for



                        format=#1
                        format=#1/#2
                        format=#1/#2/#3


                        respectively.



                        enter image description here






                        share|improve this answer


























                          0












                          0








                          0







                          Here's some code I'm developing for leisure. Save the following code as extforeach-code.tex



                          % extforeach-code.tex

                          ExplSyntaxOn
                          providecommandfpeval{fp_eval:n}

                          NewDocumentCommand{nforeach}{ m +m }
                          {
                          tl_clear:N l__manual_nforeach_type_tl
                          keys_set:nn { manual/nforeach }
                          {
                          type=integers,start = 1, step = 1, end = 0,
                          }
                          keys_set:nn { manual/nforeach } { #1 }
                          __manual_nforeach_exec:n { #2 }
                          }

                          int_new:N g__manual_foreach_map_int
                          int_new:N g__manual_fp_map_int
                          tl_new:N l__manual_nforeach_type_tl

                          keys_define:nn { manual/nforeach }
                          {
                          type .choice:,
                          type .value_required:n = true,
                          type/integers .code:n = tl_set:Nn l__manual_nforeach_type_tl { integers },
                          type/fp .code:n = tl_set:Nn l__manual_nforeach_type_tl { fp },
                          type/alph .code:n = tl_set:Nn l__manual_nforeach_type_tl { alph },
                          type/Alph .code:n = tl_set:Nn l__manual_nforeach_type_tl { Alph },
                          start .tl_set:N = l__manual_nforeach_start_tl,
                          step .tl_set:N = l__manual_nforeach_step_tl,
                          end .tl_set:N = l__manual_nforeach_end_tl,
                          }

                          cs_new_protected:Nn __manual_nforeach_exec:n
                          {
                          int_gincr:N g__manual_foreach_map_int
                          str_case:Vn l__manual_nforeach_type_tl
                          {
                          {integers}{__manual_nforeach_exec_integers:n { #1 }}
                          {fp} {__manual_nforeach_exec_fp:n { #1 }}
                          {alph} {__manual_nforeach_exec_alph:Nn int_to_alph:n { #1 }}
                          {Alph} {__manual_nforeach_exec_alph:Nn int_to_Alph:n { #1 }}
                          }
                          int_gdecr:N g__manual_foreach_map_int
                          }
                          cs_generate_variant:Nn str_case:nn { V }

                          cs_new_protected:Nn __manual_nforeach_exec_integers:n
                          {
                          int_step_inline:nnnn
                          { l__manual_nforeach_start_tl }
                          { l__manual_nforeach_step_tl }
                          { l__manual_nforeach_end_tl }
                          { #1 }
                          }
                          cs_new_protected:Nn __manual_nforeach_exec_alph:Nn
                          {
                          cs_set:cn { __manual_nforeach_alph_ int_use:N g__manual_foreach_map_int :n } { #2 }
                          cs_generate_variant:cn
                          { __manual_nforeach_alph_ int_use:N g__manual_foreach_map_int :n }
                          { f }
                          int_step_inline:nnnn
                          { int_from_alph:f { l__manual_nforeach_start_tl } }
                          { l__manual_nforeach_step_tl }
                          { int_from_alph:f { l__manual_nforeach_end_tl } }
                          {
                          use:c { __manual_nforeach_alph_ int_use:N g__manual_foreach_map_int :f }
                          { #1 { ##1 } }
                          }
                          }
                          cs_generate_variant:Nn cs_generate_variant:Nn { c }
                          cs_generate_variant:Nn int_from_alph:n { f }

                          cs_new_protected:Nn __manual_nforeach_exec_fp:n
                          {
                          fp_step_inline:nnnn
                          { l__manual_nforeach_start_tl }
                          { l__manual_nforeach_step_tl }
                          { l__manual_nforeach_end_tl }
                          { #1 }
                          }

                          NewDocumentCommand{lforeach}{ s O{} m +m }
                          {
                          IfBooleanTF{#1}
                          {
                          manual_lforeach:non { #2 } { #3 } { #4 }
                          }
                          {
                          manual_lforeach:nnn { #2 } { #3 } { #4 }
                          }
                          }

                          cs_new_protected:Nn manual_lforeach:nnn
                          {
                          keys_set:nn { manual/lforeach } { single }
                          keys_set:nn { manual/lforeach } { #1 }
                          clist_set:Nn l__manual_lforeach_list_clist { #2 }
                          int_gincr:N g__manual_foreach_map_int
                          __manual_lforeach_define:n { #3 }
                          clist_map_inline:Nn l__manual_lforeach_list_clist
                          {
                          use:c { __manual_lforeach_ int_use:N g__manual_foreach_map_int _action:w } ##1 q_stop
                          }
                          int_gdecr:N g__manual_foreach_map_int
                          }
                          cs_generate_variant:Nn manual_lforeach:nnn { no }

                          cs_new_protected:Nn __manual_lforeach_define:n
                          {
                          exp_last_unbraced:NcV
                          cs_set:Npn
                          { __manual_lforeach_ int_use:N g__manual_foreach_map_int _action:w }
                          l__manual_lforeach_format_tl
                          q_stop
                          {#1}
                          }

                          keys_define:nn { manual/lforeach }
                          {
                          format .tl_set:N = l__manual_lforeach_format_tl,
                          single .code:n = tl_set:Nn l__manual_lforeach_format_tl { ##1 },
                          double .code:n = tl_set:Nn l__manual_lforeach_format_tl { ##1/##2 },
                          triple .code:n = tl_set:Nn l__manual_lforeach_format_tl { ##1/##2/##3 },
                          }
                          ExplSyntaxOff


                          Now your document can be



                          documentclass{article}
                          usepackage{xparse,xfp}

                          input{extforeach-code.tex}

                          newcommandlinkLength{1.2}
                          newcommandjointRadio{0.2}
                          newcommandjointLength{0.6}

                          newcounter{lines}

                          begin{document}

                          lforeach[format=#1 #2 #3]{
                          0 0 0, % N°0
                          0 0 0, % N°1
                          0 0 linkLength, % N°2
                          0 0 jointLength, % N°3
                          0 {jointLength*0.5} {linkLength + jointRadio}, % N°4
                          }
                          {%
                          stepcounter{lines}Line thelines is fpeval{#1}~fpeval{#2}~fpeval{#3}par
                          }

                          end{document}


                          With the help of xfp we can even evaluate expressions.



                          The format key sets up a template for each item in the comma separated list given as first mandatory argument, here #1 #2 #3 means the item will consist of things like



                          <subitem><space><subitem><space><subitem>


                          The second mandatory argument is code that uses the arguments set up in the template. There are abbreviations single (default if nothing is specified), double and triple that stand for



                          format=#1
                          format=#1/#2
                          format=#1/#2/#3


                          respectively.



                          enter image description here






                          share|improve this answer













                          Here's some code I'm developing for leisure. Save the following code as extforeach-code.tex



                          % extforeach-code.tex

                          ExplSyntaxOn
                          providecommandfpeval{fp_eval:n}

                          NewDocumentCommand{nforeach}{ m +m }
                          {
                          tl_clear:N l__manual_nforeach_type_tl
                          keys_set:nn { manual/nforeach }
                          {
                          type=integers,start = 1, step = 1, end = 0,
                          }
                          keys_set:nn { manual/nforeach } { #1 }
                          __manual_nforeach_exec:n { #2 }
                          }

                          int_new:N g__manual_foreach_map_int
                          int_new:N g__manual_fp_map_int
                          tl_new:N l__manual_nforeach_type_tl

                          keys_define:nn { manual/nforeach }
                          {
                          type .choice:,
                          type .value_required:n = true,
                          type/integers .code:n = tl_set:Nn l__manual_nforeach_type_tl { integers },
                          type/fp .code:n = tl_set:Nn l__manual_nforeach_type_tl { fp },
                          type/alph .code:n = tl_set:Nn l__manual_nforeach_type_tl { alph },
                          type/Alph .code:n = tl_set:Nn l__manual_nforeach_type_tl { Alph },
                          start .tl_set:N = l__manual_nforeach_start_tl,
                          step .tl_set:N = l__manual_nforeach_step_tl,
                          end .tl_set:N = l__manual_nforeach_end_tl,
                          }

                          cs_new_protected:Nn __manual_nforeach_exec:n
                          {
                          int_gincr:N g__manual_foreach_map_int
                          str_case:Vn l__manual_nforeach_type_tl
                          {
                          {integers}{__manual_nforeach_exec_integers:n { #1 }}
                          {fp} {__manual_nforeach_exec_fp:n { #1 }}
                          {alph} {__manual_nforeach_exec_alph:Nn int_to_alph:n { #1 }}
                          {Alph} {__manual_nforeach_exec_alph:Nn int_to_Alph:n { #1 }}
                          }
                          int_gdecr:N g__manual_foreach_map_int
                          }
                          cs_generate_variant:Nn str_case:nn { V }

                          cs_new_protected:Nn __manual_nforeach_exec_integers:n
                          {
                          int_step_inline:nnnn
                          { l__manual_nforeach_start_tl }
                          { l__manual_nforeach_step_tl }
                          { l__manual_nforeach_end_tl }
                          { #1 }
                          }
                          cs_new_protected:Nn __manual_nforeach_exec_alph:Nn
                          {
                          cs_set:cn { __manual_nforeach_alph_ int_use:N g__manual_foreach_map_int :n } { #2 }
                          cs_generate_variant:cn
                          { __manual_nforeach_alph_ int_use:N g__manual_foreach_map_int :n }
                          { f }
                          int_step_inline:nnnn
                          { int_from_alph:f { l__manual_nforeach_start_tl } }
                          { l__manual_nforeach_step_tl }
                          { int_from_alph:f { l__manual_nforeach_end_tl } }
                          {
                          use:c { __manual_nforeach_alph_ int_use:N g__manual_foreach_map_int :f }
                          { #1 { ##1 } }
                          }
                          }
                          cs_generate_variant:Nn cs_generate_variant:Nn { c }
                          cs_generate_variant:Nn int_from_alph:n { f }

                          cs_new_protected:Nn __manual_nforeach_exec_fp:n
                          {
                          fp_step_inline:nnnn
                          { l__manual_nforeach_start_tl }
                          { l__manual_nforeach_step_tl }
                          { l__manual_nforeach_end_tl }
                          { #1 }
                          }

                          NewDocumentCommand{lforeach}{ s O{} m +m }
                          {
                          IfBooleanTF{#1}
                          {
                          manual_lforeach:non { #2 } { #3 } { #4 }
                          }
                          {
                          manual_lforeach:nnn { #2 } { #3 } { #4 }
                          }
                          }

                          cs_new_protected:Nn manual_lforeach:nnn
                          {
                          keys_set:nn { manual/lforeach } { single }
                          keys_set:nn { manual/lforeach } { #1 }
                          clist_set:Nn l__manual_lforeach_list_clist { #2 }
                          int_gincr:N g__manual_foreach_map_int
                          __manual_lforeach_define:n { #3 }
                          clist_map_inline:Nn l__manual_lforeach_list_clist
                          {
                          use:c { __manual_lforeach_ int_use:N g__manual_foreach_map_int _action:w } ##1 q_stop
                          }
                          int_gdecr:N g__manual_foreach_map_int
                          }
                          cs_generate_variant:Nn manual_lforeach:nnn { no }

                          cs_new_protected:Nn __manual_lforeach_define:n
                          {
                          exp_last_unbraced:NcV
                          cs_set:Npn
                          { __manual_lforeach_ int_use:N g__manual_foreach_map_int _action:w }
                          l__manual_lforeach_format_tl
                          q_stop
                          {#1}
                          }

                          keys_define:nn { manual/lforeach }
                          {
                          format .tl_set:N = l__manual_lforeach_format_tl,
                          single .code:n = tl_set:Nn l__manual_lforeach_format_tl { ##1 },
                          double .code:n = tl_set:Nn l__manual_lforeach_format_tl { ##1/##2 },
                          triple .code:n = tl_set:Nn l__manual_lforeach_format_tl { ##1/##2/##3 },
                          }
                          ExplSyntaxOff


                          Now your document can be



                          documentclass{article}
                          usepackage{xparse,xfp}

                          input{extforeach-code.tex}

                          newcommandlinkLength{1.2}
                          newcommandjointRadio{0.2}
                          newcommandjointLength{0.6}

                          newcounter{lines}

                          begin{document}

                          lforeach[format=#1 #2 #3]{
                          0 0 0, % N°0
                          0 0 0, % N°1
                          0 0 linkLength, % N°2
                          0 0 jointLength, % N°3
                          0 {jointLength*0.5} {linkLength + jointRadio}, % N°4
                          }
                          {%
                          stepcounter{lines}Line thelines is fpeval{#1}~fpeval{#2}~fpeval{#3}par
                          }

                          end{document}


                          With the help of xfp we can even evaluate expressions.



                          The format key sets up a template for each item in the comma separated list given as first mandatory argument, here #1 #2 #3 means the item will consist of things like



                          <subitem><space><subitem><space><subitem>


                          The second mandatory argument is code that uses the arguments set up in the template. There are abbreviations single (default if nothing is specified), double and triple that stand for



                          format=#1
                          format=#1/#2
                          format=#1/#2/#3


                          respectively.



                          enter image description here







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Feb 28 at 14:23









                          egregegreg

                          724k8819183223




                          724k8819183223






























                              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%2f477066%2fmodular-macro-list-structure-to-iterate-it%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

                              Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

                              ComboBox Display Member on multiple fields

                              Is it possible to collect Nectar points via Trainline?