Tikz `ifeven` triggering error

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












Why the following sample fails to compile in pdflatex when ifeven is used?



It fails with many errors in line 34 (where the last closing brackets are). The errors are like: Undefined control sequence. }, Extra }, or forgoten endgroup.}, Extra else.}, Extra fi }.



documentclass[tikz]standalone

newcommandstencilptreg[4]node[circle,fill,draw,inner sep=1.5pt,label=below:#4,#1] at (#2) (#3)
newcommandstencilptstg[4]node[circle,fill,white,draw=black,inner sep=1.5pt,label=below:#4,#1] at (#2) (#3)

begindocument
begintikzpicture[x=2cm,y=2cm]
pgfmathsetmacroN5;
pgfmathsetmacroM3;

pgfmathsetmacroNN(N*2); % Number of points in staggered grid
pgfmathsetmacroMM(M*2); % Number of points in staggered grid

foreach j [evaluate=j as q using int(j/2)] in 0,1,...,MM

ifoddj
draw [black!50,thin] (0,j) node[red,left] $n=fracj2$ -- (N,j);
else
draw [black!50,thin] (0,j) node[red,left] $n=q$ -- (N,j);
fi

foreach i [evaluate=i as p using (i/2)] in 0,1,...,NN

ifoddi
ifoddj
stencilptstgp,jx-i-j$p$;
fi
else
%ifevenj
pgfmathsetmacropint(p);
stencilptregp,jx-i-j$p$;
%fi
fi


endtikzpicture
enddocument









share|improve this question



























    up vote
    2
    down vote

    favorite












    Why the following sample fails to compile in pdflatex when ifeven is used?



    It fails with many errors in line 34 (where the last closing brackets are). The errors are like: Undefined control sequence. }, Extra }, or forgoten endgroup.}, Extra else.}, Extra fi }.



    documentclass[tikz]standalone

    newcommandstencilptreg[4]node[circle,fill,draw,inner sep=1.5pt,label=below:#4,#1] at (#2) (#3)
    newcommandstencilptstg[4]node[circle,fill,white,draw=black,inner sep=1.5pt,label=below:#4,#1] at (#2) (#3)

    begindocument
    begintikzpicture[x=2cm,y=2cm]
    pgfmathsetmacroN5;
    pgfmathsetmacroM3;

    pgfmathsetmacroNN(N*2); % Number of points in staggered grid
    pgfmathsetmacroMM(M*2); % Number of points in staggered grid

    foreach j [evaluate=j as q using int(j/2)] in 0,1,...,MM

    ifoddj
    draw [black!50,thin] (0,j) node[red,left] $n=fracj2$ -- (N,j);
    else
    draw [black!50,thin] (0,j) node[red,left] $n=q$ -- (N,j);
    fi

    foreach i [evaluate=i as p using (i/2)] in 0,1,...,NN

    ifoddi
    ifoddj
    stencilptstgp,jx-i-j$p$;
    fi
    else
    %ifevenj
    pgfmathsetmacropint(p);
    stencilptregp,jx-i-j$p$;
    %fi
    fi


    endtikzpicture
    enddocument









    share|improve this question

























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      Why the following sample fails to compile in pdflatex when ifeven is used?



      It fails with many errors in line 34 (where the last closing brackets are). The errors are like: Undefined control sequence. }, Extra }, or forgoten endgroup.}, Extra else.}, Extra fi }.



      documentclass[tikz]standalone

      newcommandstencilptreg[4]node[circle,fill,draw,inner sep=1.5pt,label=below:#4,#1] at (#2) (#3)
      newcommandstencilptstg[4]node[circle,fill,white,draw=black,inner sep=1.5pt,label=below:#4,#1] at (#2) (#3)

      begindocument
      begintikzpicture[x=2cm,y=2cm]
      pgfmathsetmacroN5;
      pgfmathsetmacroM3;

      pgfmathsetmacroNN(N*2); % Number of points in staggered grid
      pgfmathsetmacroMM(M*2); % Number of points in staggered grid

      foreach j [evaluate=j as q using int(j/2)] in 0,1,...,MM

      ifoddj
      draw [black!50,thin] (0,j) node[red,left] $n=fracj2$ -- (N,j);
      else
      draw [black!50,thin] (0,j) node[red,left] $n=q$ -- (N,j);
      fi

      foreach i [evaluate=i as p using (i/2)] in 0,1,...,NN

      ifoddi
      ifoddj
      stencilptstgp,jx-i-j$p$;
      fi
      else
      %ifevenj
      pgfmathsetmacropint(p);
      stencilptregp,jx-i-j$p$;
      %fi
      fi


      endtikzpicture
      enddocument









      share|improve this question















      Why the following sample fails to compile in pdflatex when ifeven is used?



      It fails with many errors in line 34 (where the last closing brackets are). The errors are like: Undefined control sequence. }, Extra }, or forgoten endgroup.}, Extra else.}, Extra fi }.



      documentclass[tikz]standalone

      newcommandstencilptreg[4]node[circle,fill,draw,inner sep=1.5pt,label=below:#4,#1] at (#2) (#3)
      newcommandstencilptstg[4]node[circle,fill,white,draw=black,inner sep=1.5pt,label=below:#4,#1] at (#2) (#3)

      begindocument
      begintikzpicture[x=2cm,y=2cm]
      pgfmathsetmacroN5;
      pgfmathsetmacroM3;

      pgfmathsetmacroNN(N*2); % Number of points in staggered grid
      pgfmathsetmacroMM(M*2); % Number of points in staggered grid

      foreach j [evaluate=j as q using int(j/2)] in 0,1,...,MM

      ifoddj
      draw [black!50,thin] (0,j) node[red,left] $n=fracj2$ -- (N,j);
      else
      draw [black!50,thin] (0,j) node[red,left] $n=q$ -- (N,j);
      fi

      foreach i [evaluate=i as p using (i/2)] in 0,1,...,NN

      ifoddi
      ifoddj
      stencilptstgp,jx-i-j$p$;
      fi
      else
      %ifevenj
      pgfmathsetmacropint(p);
      stencilptregp,jx-i-j$p$;
      %fi
      fi


      endtikzpicture
      enddocument






      conditionals






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 27 mins ago









      Werner

      427k589361609




      427k589361609










      asked 38 mins ago









      Lin

      2747




      2747




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          Because there is no ifeven. However, it's equivalent to



          ifoddjelse
          % <ifeven> content
          fi


          enter image description here






          share|improve this answer
















          • 1




            Omg, I have read about ifeven in SO.
            – Lin
            29 mins ago










          • @Lin: See What are the most common mistakes that beginners of (La)TeX and Friends make?
            – Werner
            24 mins ago










          • @Lin Most engines nowadays have the unless primitive, which "reverses" the conditional, so ifoddjelse...fi does the same as unlessifoddj...fi
            – Phelype Oleinik
            13 mins ago


















          up vote
          2
          down vote













          You should look in the log file for the precise error message, rather than relying on the short tags shown by TeXStudio or other front-ends.



          Running your file in batch mode, the first error message is



          ! Extra }, or forgotten endgroup.
          <argument> ...p ,j }x-i -j $p $; fi fi }

          l.36 }


          Not really clear, but a few lines down you see



          ! Extra else.
          pgffor@collectargument ...pgffor@body #1}else
          expandafter long expand...
          l.36 }

          I'm ignoring this; it doesn't match any if.

          ! Extra fi.
          pgffor@collectargument ...r pgffor@body #1fi
          pgffor@iterate
          l.36 }


          We're getting closer! Let's go down some more:



          ! Undefined control sequence.
          pgffor@body ...i -j }$p $; fi else ifeven
          j pgfmathsetmacro p ...
          l.36

          The control sequence at the end of the top line
          of your error message was never def'ed. If you have
          misspelled it (e.g., `hobx'), type `I' and the correct
          spelling (e.g., `Ihbox'). Otherwise just continue,
          and I'll forget about whatever was undefined.


          Hey! That's the problem!



          TeX has no ifeven and TikZ doesn't provide it. Actually, it is not possible to define an ifeven command that works the same as ifodd just reversing the test.



          You can choose between



           unlessifoddjrelax
          pgfmathsetmacropint(p);
          stencilptregp,jx-i-j$p$;
          fi


          or



           ifoddjrelaxelse
          pgfmathsetmacropint(p);
          stencilptregp,jx-i-j$p$;
          fi


          I recommend relax in order not to trigger premature expansions. Not a big deal here, but in other circumstances it could be crucial. However, it's not to be added for any numeric conditionals, particularly in contexts where full expansion is needed.



          A safer protection might be



          ifoddnumexprjrelaxelse


          or



          unlessifoddnumexprjrelax


          but in this case it would be a waste.






          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',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            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%2f457420%2ftikz-ifeven-triggering-error%23new-answer', 'question_page');

            );

            Post as a guest






























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            3
            down vote



            accepted










            Because there is no ifeven. However, it's equivalent to



            ifoddjelse
            % <ifeven> content
            fi


            enter image description here






            share|improve this answer
















            • 1




              Omg, I have read about ifeven in SO.
              – Lin
              29 mins ago










            • @Lin: See What are the most common mistakes that beginners of (La)TeX and Friends make?
              – Werner
              24 mins ago










            • @Lin Most engines nowadays have the unless primitive, which "reverses" the conditional, so ifoddjelse...fi does the same as unlessifoddj...fi
              – Phelype Oleinik
              13 mins ago















            up vote
            3
            down vote



            accepted










            Because there is no ifeven. However, it's equivalent to



            ifoddjelse
            % <ifeven> content
            fi


            enter image description here






            share|improve this answer
















            • 1




              Omg, I have read about ifeven in SO.
              – Lin
              29 mins ago










            • @Lin: See What are the most common mistakes that beginners of (La)TeX and Friends make?
              – Werner
              24 mins ago










            • @Lin Most engines nowadays have the unless primitive, which "reverses" the conditional, so ifoddjelse...fi does the same as unlessifoddj...fi
              – Phelype Oleinik
              13 mins ago













            up vote
            3
            down vote



            accepted







            up vote
            3
            down vote



            accepted






            Because there is no ifeven. However, it's equivalent to



            ifoddjelse
            % <ifeven> content
            fi


            enter image description here






            share|improve this answer












            Because there is no ifeven. However, it's equivalent to



            ifoddjelse
            % <ifeven> content
            fi


            enter image description here







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 30 mins ago









            Werner

            427k589361609




            427k589361609







            • 1




              Omg, I have read about ifeven in SO.
              – Lin
              29 mins ago










            • @Lin: See What are the most common mistakes that beginners of (La)TeX and Friends make?
              – Werner
              24 mins ago










            • @Lin Most engines nowadays have the unless primitive, which "reverses" the conditional, so ifoddjelse...fi does the same as unlessifoddj...fi
              – Phelype Oleinik
              13 mins ago













            • 1




              Omg, I have read about ifeven in SO.
              – Lin
              29 mins ago










            • @Lin: See What are the most common mistakes that beginners of (La)TeX and Friends make?
              – Werner
              24 mins ago










            • @Lin Most engines nowadays have the unless primitive, which "reverses" the conditional, so ifoddjelse...fi does the same as unlessifoddj...fi
              – Phelype Oleinik
              13 mins ago








            1




            1




            Omg, I have read about ifeven in SO.
            – Lin
            29 mins ago




            Omg, I have read about ifeven in SO.
            – Lin
            29 mins ago












            @Lin: See What are the most common mistakes that beginners of (La)TeX and Friends make?
            – Werner
            24 mins ago




            @Lin: See What are the most common mistakes that beginners of (La)TeX and Friends make?
            – Werner
            24 mins ago












            @Lin Most engines nowadays have the unless primitive, which "reverses" the conditional, so ifoddjelse...fi does the same as unlessifoddj...fi
            – Phelype Oleinik
            13 mins ago





            @Lin Most engines nowadays have the unless primitive, which "reverses" the conditional, so ifoddjelse...fi does the same as unlessifoddj...fi
            – Phelype Oleinik
            13 mins ago











            up vote
            2
            down vote













            You should look in the log file for the precise error message, rather than relying on the short tags shown by TeXStudio or other front-ends.



            Running your file in batch mode, the first error message is



            ! Extra }, or forgotten endgroup.
            <argument> ...p ,j }x-i -j $p $; fi fi }

            l.36 }


            Not really clear, but a few lines down you see



            ! Extra else.
            pgffor@collectargument ...pgffor@body #1}else
            expandafter long expand...
            l.36 }

            I'm ignoring this; it doesn't match any if.

            ! Extra fi.
            pgffor@collectargument ...r pgffor@body #1fi
            pgffor@iterate
            l.36 }


            We're getting closer! Let's go down some more:



            ! Undefined control sequence.
            pgffor@body ...i -j }$p $; fi else ifeven
            j pgfmathsetmacro p ...
            l.36

            The control sequence at the end of the top line
            of your error message was never def'ed. If you have
            misspelled it (e.g., `hobx'), type `I' and the correct
            spelling (e.g., `Ihbox'). Otherwise just continue,
            and I'll forget about whatever was undefined.


            Hey! That's the problem!



            TeX has no ifeven and TikZ doesn't provide it. Actually, it is not possible to define an ifeven command that works the same as ifodd just reversing the test.



            You can choose between



             unlessifoddjrelax
            pgfmathsetmacropint(p);
            stencilptregp,jx-i-j$p$;
            fi


            or



             ifoddjrelaxelse
            pgfmathsetmacropint(p);
            stencilptregp,jx-i-j$p$;
            fi


            I recommend relax in order not to trigger premature expansions. Not a big deal here, but in other circumstances it could be crucial. However, it's not to be added for any numeric conditionals, particularly in contexts where full expansion is needed.



            A safer protection might be



            ifoddnumexprjrelaxelse


            or



            unlessifoddnumexprjrelax


            but in this case it would be a waste.






            share|improve this answer
























              up vote
              2
              down vote













              You should look in the log file for the precise error message, rather than relying on the short tags shown by TeXStudio or other front-ends.



              Running your file in batch mode, the first error message is



              ! Extra }, or forgotten endgroup.
              <argument> ...p ,j }x-i -j $p $; fi fi }

              l.36 }


              Not really clear, but a few lines down you see



              ! Extra else.
              pgffor@collectargument ...pgffor@body #1}else
              expandafter long expand...
              l.36 }

              I'm ignoring this; it doesn't match any if.

              ! Extra fi.
              pgffor@collectargument ...r pgffor@body #1fi
              pgffor@iterate
              l.36 }


              We're getting closer! Let's go down some more:



              ! Undefined control sequence.
              pgffor@body ...i -j }$p $; fi else ifeven
              j pgfmathsetmacro p ...
              l.36

              The control sequence at the end of the top line
              of your error message was never def'ed. If you have
              misspelled it (e.g., `hobx'), type `I' and the correct
              spelling (e.g., `Ihbox'). Otherwise just continue,
              and I'll forget about whatever was undefined.


              Hey! That's the problem!



              TeX has no ifeven and TikZ doesn't provide it. Actually, it is not possible to define an ifeven command that works the same as ifodd just reversing the test.



              You can choose between



               unlessifoddjrelax
              pgfmathsetmacropint(p);
              stencilptregp,jx-i-j$p$;
              fi


              or



               ifoddjrelaxelse
              pgfmathsetmacropint(p);
              stencilptregp,jx-i-j$p$;
              fi


              I recommend relax in order not to trigger premature expansions. Not a big deal here, but in other circumstances it could be crucial. However, it's not to be added for any numeric conditionals, particularly in contexts where full expansion is needed.



              A safer protection might be



              ifoddnumexprjrelaxelse


              or



              unlessifoddnumexprjrelax


              but in this case it would be a waste.






              share|improve this answer






















                up vote
                2
                down vote










                up vote
                2
                down vote









                You should look in the log file for the precise error message, rather than relying on the short tags shown by TeXStudio or other front-ends.



                Running your file in batch mode, the first error message is



                ! Extra }, or forgotten endgroup.
                <argument> ...p ,j }x-i -j $p $; fi fi }

                l.36 }


                Not really clear, but a few lines down you see



                ! Extra else.
                pgffor@collectargument ...pgffor@body #1}else
                expandafter long expand...
                l.36 }

                I'm ignoring this; it doesn't match any if.

                ! Extra fi.
                pgffor@collectargument ...r pgffor@body #1fi
                pgffor@iterate
                l.36 }


                We're getting closer! Let's go down some more:



                ! Undefined control sequence.
                pgffor@body ...i -j }$p $; fi else ifeven
                j pgfmathsetmacro p ...
                l.36

                The control sequence at the end of the top line
                of your error message was never def'ed. If you have
                misspelled it (e.g., `hobx'), type `I' and the correct
                spelling (e.g., `Ihbox'). Otherwise just continue,
                and I'll forget about whatever was undefined.


                Hey! That's the problem!



                TeX has no ifeven and TikZ doesn't provide it. Actually, it is not possible to define an ifeven command that works the same as ifodd just reversing the test.



                You can choose between



                 unlessifoddjrelax
                pgfmathsetmacropint(p);
                stencilptregp,jx-i-j$p$;
                fi


                or



                 ifoddjrelaxelse
                pgfmathsetmacropint(p);
                stencilptregp,jx-i-j$p$;
                fi


                I recommend relax in order not to trigger premature expansions. Not a big deal here, but in other circumstances it could be crucial. However, it's not to be added for any numeric conditionals, particularly in contexts where full expansion is needed.



                A safer protection might be



                ifoddnumexprjrelaxelse


                or



                unlessifoddnumexprjrelax


                but in this case it would be a waste.






                share|improve this answer












                You should look in the log file for the precise error message, rather than relying on the short tags shown by TeXStudio or other front-ends.



                Running your file in batch mode, the first error message is



                ! Extra }, or forgotten endgroup.
                <argument> ...p ,j }x-i -j $p $; fi fi }

                l.36 }


                Not really clear, but a few lines down you see



                ! Extra else.
                pgffor@collectargument ...pgffor@body #1}else
                expandafter long expand...
                l.36 }

                I'm ignoring this; it doesn't match any if.

                ! Extra fi.
                pgffor@collectargument ...r pgffor@body #1fi
                pgffor@iterate
                l.36 }


                We're getting closer! Let's go down some more:



                ! Undefined control sequence.
                pgffor@body ...i -j }$p $; fi else ifeven
                j pgfmathsetmacro p ...
                l.36

                The control sequence at the end of the top line
                of your error message was never def'ed. If you have
                misspelled it (e.g., `hobx'), type `I' and the correct
                spelling (e.g., `Ihbox'). Otherwise just continue,
                and I'll forget about whatever was undefined.


                Hey! That's the problem!



                TeX has no ifeven and TikZ doesn't provide it. Actually, it is not possible to define an ifeven command that works the same as ifodd just reversing the test.



                You can choose between



                 unlessifoddjrelax
                pgfmathsetmacropint(p);
                stencilptregp,jx-i-j$p$;
                fi


                or



                 ifoddjrelaxelse
                pgfmathsetmacropint(p);
                stencilptregp,jx-i-j$p$;
                fi


                I recommend relax in order not to trigger premature expansions. Not a big deal here, but in other circumstances it could be crucial. However, it's not to be added for any numeric conditionals, particularly in contexts where full expansion is needed.



                A safer protection might be



                ifoddnumexprjrelaxelse


                or



                unlessifoddnumexprjrelax


                but in this case it would be a waste.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 14 mins ago









                egreg

                693k8518443094




                693k8518443094



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f457420%2ftikz-ifeven-triggering-error%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    Long meetings (6-7 hours a day): Being “babysat” by supervisor

                    What does second last employer means? [closed]

                    One-line joke