Problem with condition in a table by using counters












1














I'm trying to make a conditional dynamic table that uses counter for comparison but i got a irrational error, Please see the following code:



% !TEX TS-program = xelatex
documentclass[hidelinks]{article}
usepackage{pgffor}
usepackage{longtable}

newcounter{generalCounter}
begin{document}
defanyy{a}
begin{longtable}{cccc}
setcounter{generalCounter}{0}foreachelement inanyy{stepcounter{generalCounter}}
ifnumthegeneralCounter=1
1 & 2 & 3 & 4 \hline
fi
ifnumthegeneralCounter=2
1 & 2 & 3 & 4 \hline
fi
end{longtable}
end{document}


This code works fine, but if i change defanyy{a} to defanyy{a,b}, can not build and showen error is ! Incomplete ifnum; all text was ignored after line 11.










share|improve this question







New contributor




David Tex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Welcome to TeX.SE!
    – Christian Hupfer
    21 mins ago
















1














I'm trying to make a conditional dynamic table that uses counter for comparison but i got a irrational error, Please see the following code:



% !TEX TS-program = xelatex
documentclass[hidelinks]{article}
usepackage{pgffor}
usepackage{longtable}

newcounter{generalCounter}
begin{document}
defanyy{a}
begin{longtable}{cccc}
setcounter{generalCounter}{0}foreachelement inanyy{stepcounter{generalCounter}}
ifnumthegeneralCounter=1
1 & 2 & 3 & 4 \hline
fi
ifnumthegeneralCounter=2
1 & 2 & 3 & 4 \hline
fi
end{longtable}
end{document}


This code works fine, but if i change defanyy{a} to defanyy{a,b}, can not build and showen error is ! Incomplete ifnum; all text was ignored after line 11.










share|improve this question







New contributor




David Tex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Welcome to TeX.SE!
    – Christian Hupfer
    21 mins ago














1












1








1







I'm trying to make a conditional dynamic table that uses counter for comparison but i got a irrational error, Please see the following code:



% !TEX TS-program = xelatex
documentclass[hidelinks]{article}
usepackage{pgffor}
usepackage{longtable}

newcounter{generalCounter}
begin{document}
defanyy{a}
begin{longtable}{cccc}
setcounter{generalCounter}{0}foreachelement inanyy{stepcounter{generalCounter}}
ifnumthegeneralCounter=1
1 & 2 & 3 & 4 \hline
fi
ifnumthegeneralCounter=2
1 & 2 & 3 & 4 \hline
fi
end{longtable}
end{document}


This code works fine, but if i change defanyy{a} to defanyy{a,b}, can not build and showen error is ! Incomplete ifnum; all text was ignored after line 11.










share|improve this question







New contributor




David Tex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I'm trying to make a conditional dynamic table that uses counter for comparison but i got a irrational error, Please see the following code:



% !TEX TS-program = xelatex
documentclass[hidelinks]{article}
usepackage{pgffor}
usepackage{longtable}

newcounter{generalCounter}
begin{document}
defanyy{a}
begin{longtable}{cccc}
setcounter{generalCounter}{0}foreachelement inanyy{stepcounter{generalCounter}}
ifnumthegeneralCounter=1
1 & 2 & 3 & 4 \hline
fi
ifnumthegeneralCounter=2
1 & 2 & 3 & 4 \hline
fi
end{longtable}
end{document}


This code works fine, but if i change defanyy{a} to defanyy{a,b}, can not build and showen error is ! Incomplete ifnum; all text was ignored after line 11.







tables counters condition






share|improve this question







New contributor




David Tex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




David Tex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




David Tex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 41 mins ago









David Tex

61




61




New contributor




David Tex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





David Tex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






David Tex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • Welcome to TeX.SE!
    – Christian Hupfer
    21 mins ago


















  • Welcome to TeX.SE!
    – Christian Hupfer
    21 mins ago
















Welcome to TeX.SE!
– Christian Hupfer
21 mins ago




Welcome to TeX.SE!
– Christian Hupfer
21 mins ago










1 Answer
1






active

oldest

votes


















0














enter image description here



The looping with foreach isn't the issue, but anyy isn't getting expanded correctly. In addition, the test ifnum begins in one tabular cell and ends in other ones -- this is weird and can be catched only with tricks.



A simpler way is to use prg_replicate:nn here, a, expl3 macro, that performs expandable loops and survives the grouping involved with tabular cells.



The helper macro generatelines stores the argument in a clist and counts its elements with clist_count:N, which is the number of repetitions to be made.



The actual tabular line entry is another, 'freely' configurable helper macro, e.g. modeltableentry.



documentclass{article}
usepackage{longtable}

usepackage{xparse}

newcommand{modeltableentry}{%
1 & 2 & 3 & 4 tabularnewline hline
}
ExplSyntaxOn

NewDocumentCommand{generatelines}{+m}{%
clist_set:Nx l_tmpa_clist {#1}
prg_replicate:nn {clist_count:N l_tmpa_clist } {modeltableentry}
}
ExplSyntaxOff
begin{document}
newcommand{anyy}{a,b}
begin{longtable}{cccc}
generatelines{anyy}
end{longtable}


renewcommand{anyy}{a,b,c,d,e,f,g,h,i,j,k}

begin{longtable}{cccc}
generatelines{anyy}
end{longtable}

end{document}





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
    });


    }
    });






    David Tex is a new contributor. Be nice, and check out our Code of Conduct.










    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f467709%2fproblem-with-condition-in-a-table-by-using-counters%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    enter image description here



    The looping with foreach isn't the issue, but anyy isn't getting expanded correctly. In addition, the test ifnum begins in one tabular cell and ends in other ones -- this is weird and can be catched only with tricks.



    A simpler way is to use prg_replicate:nn here, a, expl3 macro, that performs expandable loops and survives the grouping involved with tabular cells.



    The helper macro generatelines stores the argument in a clist and counts its elements with clist_count:N, which is the number of repetitions to be made.



    The actual tabular line entry is another, 'freely' configurable helper macro, e.g. modeltableentry.



    documentclass{article}
    usepackage{longtable}

    usepackage{xparse}

    newcommand{modeltableentry}{%
    1 & 2 & 3 & 4 tabularnewline hline
    }
    ExplSyntaxOn

    NewDocumentCommand{generatelines}{+m}{%
    clist_set:Nx l_tmpa_clist {#1}
    prg_replicate:nn {clist_count:N l_tmpa_clist } {modeltableentry}
    }
    ExplSyntaxOff
    begin{document}
    newcommand{anyy}{a,b}
    begin{longtable}{cccc}
    generatelines{anyy}
    end{longtable}


    renewcommand{anyy}{a,b,c,d,e,f,g,h,i,j,k}

    begin{longtable}{cccc}
    generatelines{anyy}
    end{longtable}

    end{document}





    share|improve this answer




























      0














      enter image description here



      The looping with foreach isn't the issue, but anyy isn't getting expanded correctly. In addition, the test ifnum begins in one tabular cell and ends in other ones -- this is weird and can be catched only with tricks.



      A simpler way is to use prg_replicate:nn here, a, expl3 macro, that performs expandable loops and survives the grouping involved with tabular cells.



      The helper macro generatelines stores the argument in a clist and counts its elements with clist_count:N, which is the number of repetitions to be made.



      The actual tabular line entry is another, 'freely' configurable helper macro, e.g. modeltableentry.



      documentclass{article}
      usepackage{longtable}

      usepackage{xparse}

      newcommand{modeltableentry}{%
      1 & 2 & 3 & 4 tabularnewline hline
      }
      ExplSyntaxOn

      NewDocumentCommand{generatelines}{+m}{%
      clist_set:Nx l_tmpa_clist {#1}
      prg_replicate:nn {clist_count:N l_tmpa_clist } {modeltableentry}
      }
      ExplSyntaxOff
      begin{document}
      newcommand{anyy}{a,b}
      begin{longtable}{cccc}
      generatelines{anyy}
      end{longtable}


      renewcommand{anyy}{a,b,c,d,e,f,g,h,i,j,k}

      begin{longtable}{cccc}
      generatelines{anyy}
      end{longtable}

      end{document}





      share|improve this answer


























        0












        0








        0






        enter image description here



        The looping with foreach isn't the issue, but anyy isn't getting expanded correctly. In addition, the test ifnum begins in one tabular cell and ends in other ones -- this is weird and can be catched only with tricks.



        A simpler way is to use prg_replicate:nn here, a, expl3 macro, that performs expandable loops and survives the grouping involved with tabular cells.



        The helper macro generatelines stores the argument in a clist and counts its elements with clist_count:N, which is the number of repetitions to be made.



        The actual tabular line entry is another, 'freely' configurable helper macro, e.g. modeltableentry.



        documentclass{article}
        usepackage{longtable}

        usepackage{xparse}

        newcommand{modeltableentry}{%
        1 & 2 & 3 & 4 tabularnewline hline
        }
        ExplSyntaxOn

        NewDocumentCommand{generatelines}{+m}{%
        clist_set:Nx l_tmpa_clist {#1}
        prg_replicate:nn {clist_count:N l_tmpa_clist } {modeltableentry}
        }
        ExplSyntaxOff
        begin{document}
        newcommand{anyy}{a,b}
        begin{longtable}{cccc}
        generatelines{anyy}
        end{longtable}


        renewcommand{anyy}{a,b,c,d,e,f,g,h,i,j,k}

        begin{longtable}{cccc}
        generatelines{anyy}
        end{longtable}

        end{document}





        share|improve this answer














        enter image description here



        The looping with foreach isn't the issue, but anyy isn't getting expanded correctly. In addition, the test ifnum begins in one tabular cell and ends in other ones -- this is weird and can be catched only with tricks.



        A simpler way is to use prg_replicate:nn here, a, expl3 macro, that performs expandable loops and survives the grouping involved with tabular cells.



        The helper macro generatelines stores the argument in a clist and counts its elements with clist_count:N, which is the number of repetitions to be made.



        The actual tabular line entry is another, 'freely' configurable helper macro, e.g. modeltableentry.



        documentclass{article}
        usepackage{longtable}

        usepackage{xparse}

        newcommand{modeltableentry}{%
        1 & 2 & 3 & 4 tabularnewline hline
        }
        ExplSyntaxOn

        NewDocumentCommand{generatelines}{+m}{%
        clist_set:Nx l_tmpa_clist {#1}
        prg_replicate:nn {clist_count:N l_tmpa_clist } {modeltableentry}
        }
        ExplSyntaxOff
        begin{document}
        newcommand{anyy}{a,b}
        begin{longtable}{cccc}
        generatelines{anyy}
        end{longtable}


        renewcommand{anyy}{a,b,c,d,e,f,g,h,i,j,k}

        begin{longtable}{cccc}
        generatelines{anyy}
        end{longtable}

        end{document}






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 21 mins ago

























        answered 26 mins ago









        Christian Hupfer

        147k14192384




        147k14192384






















            David Tex is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            David Tex is a new contributor. Be nice, and check out our Code of Conduct.













            David Tex is a new contributor. Be nice, and check out our Code of Conduct.












            David Tex is a new contributor. Be nice, and check out our Code of Conduct.
















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


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

            But avoid



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

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


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





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f467709%2fproblem-with-condition-in-a-table-by-using-counters%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

            サソリ

            広島県道265号伴広島線

            Accessing regular linux commands in Huawei's Dopra Linux