What is wrong with the use of `isodd` of `xifthen`?












5














The white/black board can be drawn by testing the parity of node positions as follows:



white-black-board



documentclass[tikz]{standalone}
usepackage{xifthen}

begin{document}
begin{tikzpicture}[every node/.style = {draw, circle, minimum size = 10pt}]
foreach r in {1, ..., 4} {
foreach c in {1, ..., 5} {
pgfmathparse{mod(r + c, 2)}
letparitypgfmathresult

ifthenelse{equal{parity}{0.0}}
{node (rc) [fill = lightgray] at (c, r){}}
{node (rc) at (c, r){}};
}
}
end{tikzpicture}
end{document}


However, using isodd of xifthen does not produce the same result. What is wrong here? Or are there any alternative similar solutions?



white-black-board-wrong



documentclass[tikz]{standalone}
usepackage{xifthen}

begin{document}
begin{tikzpicture}[every node/.style = {draw, circle, minimum size = 10pt}]
foreach r in {1, ..., 4} {
foreach c in {1, ..., 5} {
ifthenelse{NOT isodd{r + c}}
{node (rc) [fill = lightgray] at (c, r){}}
{node (rc) at (c, r){}};
}
}
end{tikzpicture}
end{document}









share|improve this question




















  • 3




    Can I suggest using TeX's ifodd instead of ifthenelse from xifthen? See Why is the ifthen package obsolete?
    – Werner
    Dec 27 '18 at 6:31










  • @Werner Thanks. It is also appreciated. Would you mind posting it as an answer?
    – hengxin
    Dec 27 '18 at 6:34
















5














The white/black board can be drawn by testing the parity of node positions as follows:



white-black-board



documentclass[tikz]{standalone}
usepackage{xifthen}

begin{document}
begin{tikzpicture}[every node/.style = {draw, circle, minimum size = 10pt}]
foreach r in {1, ..., 4} {
foreach c in {1, ..., 5} {
pgfmathparse{mod(r + c, 2)}
letparitypgfmathresult

ifthenelse{equal{parity}{0.0}}
{node (rc) [fill = lightgray] at (c, r){}}
{node (rc) at (c, r){}};
}
}
end{tikzpicture}
end{document}


However, using isodd of xifthen does not produce the same result. What is wrong here? Or are there any alternative similar solutions?



white-black-board-wrong



documentclass[tikz]{standalone}
usepackage{xifthen}

begin{document}
begin{tikzpicture}[every node/.style = {draw, circle, minimum size = 10pt}]
foreach r in {1, ..., 4} {
foreach c in {1, ..., 5} {
ifthenelse{NOT isodd{r + c}}
{node (rc) [fill = lightgray] at (c, r){}}
{node (rc) at (c, r){}};
}
}
end{tikzpicture}
end{document}









share|improve this question




















  • 3




    Can I suggest using TeX's ifodd instead of ifthenelse from xifthen? See Why is the ifthen package obsolete?
    – Werner
    Dec 27 '18 at 6:31










  • @Werner Thanks. It is also appreciated. Would you mind posting it as an answer?
    – hengxin
    Dec 27 '18 at 6:34














5












5








5







The white/black board can be drawn by testing the parity of node positions as follows:



white-black-board



documentclass[tikz]{standalone}
usepackage{xifthen}

begin{document}
begin{tikzpicture}[every node/.style = {draw, circle, minimum size = 10pt}]
foreach r in {1, ..., 4} {
foreach c in {1, ..., 5} {
pgfmathparse{mod(r + c, 2)}
letparitypgfmathresult

ifthenelse{equal{parity}{0.0}}
{node (rc) [fill = lightgray] at (c, r){}}
{node (rc) at (c, r){}};
}
}
end{tikzpicture}
end{document}


However, using isodd of xifthen does not produce the same result. What is wrong here? Or are there any alternative similar solutions?



white-black-board-wrong



documentclass[tikz]{standalone}
usepackage{xifthen}

begin{document}
begin{tikzpicture}[every node/.style = {draw, circle, minimum size = 10pt}]
foreach r in {1, ..., 4} {
foreach c in {1, ..., 5} {
ifthenelse{NOT isodd{r + c}}
{node (rc) [fill = lightgray] at (c, r){}}
{node (rc) at (c, r){}};
}
}
end{tikzpicture}
end{document}









share|improve this question















The white/black board can be drawn by testing the parity of node positions as follows:



white-black-board



documentclass[tikz]{standalone}
usepackage{xifthen}

begin{document}
begin{tikzpicture}[every node/.style = {draw, circle, minimum size = 10pt}]
foreach r in {1, ..., 4} {
foreach c in {1, ..., 5} {
pgfmathparse{mod(r + c, 2)}
letparitypgfmathresult

ifthenelse{equal{parity}{0.0}}
{node (rc) [fill = lightgray] at (c, r){}}
{node (rc) at (c, r){}};
}
}
end{tikzpicture}
end{document}


However, using isodd of xifthen does not produce the same result. What is wrong here? Or are there any alternative similar solutions?



white-black-board-wrong



documentclass[tikz]{standalone}
usepackage{xifthen}

begin{document}
begin{tikzpicture}[every node/.style = {draw, circle, minimum size = 10pt}]
foreach r in {1, ..., 4} {
foreach c in {1, ..., 5} {
ifthenelse{NOT isodd{r + c}}
{node (rc) [fill = lightgray] at (c, r){}}
{node (rc) at (c, r){}};
}
}
end{tikzpicture}
end{document}






nodes foreach xifthen arithmetic






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 27 '18 at 6:41









Werner

437k649591649




437k649591649










asked Dec 27 '18 at 6:21









hengxin

9792825




9792825








  • 3




    Can I suggest using TeX's ifodd instead of ifthenelse from xifthen? See Why is the ifthen package obsolete?
    – Werner
    Dec 27 '18 at 6:31










  • @Werner Thanks. It is also appreciated. Would you mind posting it as an answer?
    – hengxin
    Dec 27 '18 at 6:34














  • 3




    Can I suggest using TeX's ifodd instead of ifthenelse from xifthen? See Why is the ifthen package obsolete?
    – Werner
    Dec 27 '18 at 6:31










  • @Werner Thanks. It is also appreciated. Would you mind posting it as an answer?
    – hengxin
    Dec 27 '18 at 6:34








3




3




Can I suggest using TeX's ifodd instead of ifthenelse from xifthen? See Why is the ifthen package obsolete?
– Werner
Dec 27 '18 at 6:31




Can I suggest using TeX's ifodd instead of ifthenelse from xifthen? See Why is the ifthen package obsolete?
– Werner
Dec 27 '18 at 6:31












@Werner Thanks. It is also appreciated. Would you mind posting it as an answer?
– hengxin
Dec 27 '18 at 6:34




@Werner Thanks. It is also appreciated. Would you mind posting it as an answer?
– hengxin
Dec 27 '18 at 6:34










3 Answers
3






active

oldest

votes


















5














You are implicitly assuming that isodd does calculations. But this is not what happens, it actually simply takes the begin of the argument until it hits something that is no longer a number. So you would need to do the addition first and then fed the result to isodd. Or use the tools of pgf:



documentclass{article}
usepackage{tikz}
usepackage{xifthen}

begin{document}
ifthenelse{isodd{124blub}}{odd}{even}

ifthenelse{isodd{123blub}}{odd}{even}

ifthenelse{isodd{2+3}}{odd}{even}

ifthenelse{isodd{3+2}}{odd}{even}

bigskip
begin{tikzpicture}[every node/.style = {draw, circle, minimum size = 10pt}]
foreach r in {1, ..., 4} {
foreach c in {1, ..., 5} {
pgfmathsetmacromycolor{isodd{numexprr+c}?"lightgray":"white"}
node (rc) [fill =mycolor ] at (c, r){};
}
}
end{tikzpicture}
end{document}


enter image description here






share|improve this answer





























    5














    I'd suggest using TeX's ifodd (or etoolbox); xifthen-and-friends may be considered obsolete:



    enter image description here



    documentclass{article}

    usepackage{xfp,tikz}

    begin{document}

    begin{tikzpicture}[every node/.style = {draw, circle, minimum size = 10pt}]
    foreach r in {1, ..., 4} {
    foreach c in {1, ..., 5} {
    ifoddinteval{r+c}
    node (rc) [fill = lightgray] at (c, r) {};
    else
    node (rc) at (c, r) {};
    fi
    }
    }
    end{tikzpicture}

    end{document}


    I use xfp since it is convenient and provides an expandable inteval for integer evaluation that can be used in conditioning options like ifodd. You can also do it without xfp:



          ifoddnumexprr+crelax
    %...





    share|improve this answer





























      3














      isodd doesn't compute; you might do



      expandafterifthenelseexpandafter{expandafterNOTexpandafterisoddexpandafter{thenumexprr+c}}


      but it's not something I'd use myself. ;-)



      Here's a (partial) reimplementation of xifthen allowing expressions; the syntax is different, though: for parentheses you use ( and ) rather than ( and ). For the connectives, AND, OR and NOT are replaced respectively by &&, || and !.



      documentclass{article}
      usepackage{xparse}
      usepackage{tikz} % for the application

      ExplSyntaxOn
      NewExpandableDocumentCommand{xifthenelse}{mmm}
      {
      bool_if:nTF { #1 } { #2 } { #3 }
      }

      cs_new_eq:NN numtest int_compare_p:n
      cs_new_eq:NN oddtest int_if_odd_p:n
      cs_new_eq:NN dimtest dim_compare_p:n
      cs_new_eq:NN deftest cs_if_exist_p:N
      cs_new_eq:NN namedeftest cs_if_exist_p:c
      cs_new_eq:NN eqdeftest token_if_eq_meaning_p:NN
      cs_new_eq:NN streqtest str_if_eq_p:ee
      cs_new_eq:NN emptytest tl_if_blank_p:n
      prg_new_conditional:Nnn xxifthen_legacy_conditional:n { p,T,F,TF }
      {
      use:c { if#1 } prg_return_true: else: prg_return_false: fi:
      }
      cs_new_eq:NN boolean xxifthen_legacy_conditional_p:n
      ExplSyntaxOff

      begin{document}

      xifthenelse{emptytest{}}{true}{false} true

      xifthenelse{emptytest{ }}{true}{false} true

      xifthenelse{emptytest{ foo }}{true}{false} false

      xifthenelse{numtest{10 * 10 + 1 > 100}}{true}{false} true

      xifthenelse{numtest{10 * 10 + 1 > 100 * 100}}{true}{false} false

      xifthenelse{eqdeftest{usepackage}{RequirePackage}}{true}{false} true

      xifthenelse{eqdeftest{usepackage}{textit}}{true}{false} false

      xifthenelse{namedeftest{@foo}}{true}{false} false

      xifthenelse{namedeftest{@for}}{true}{false} true

      xifthenelse{namedeftest{@for} || numtest{1>2}}{true}{false} true

      xifthenelse{namedeftest{@for} && numtest{1>2}}{true}{false} false

      xifthenelse{namedeftest{@for} && !numtest{1>2}}{true}{false} true

      xifthenelse{!oddtest{1+3}}{true}{false} true

      xifthenelse{boolean{mmode}}{true}{false} false

      $xifthenelse{boolean{mmode}}{true}{false}$ true

      bigskip

      begin{tikzpicture}[every node/.style = {draw, circle, minimum size = 10pt}]
      foreach r in {1, ..., 4} {
      foreach c in {1, ..., 5} {
      xifthenelse{!oddtest{r+c}}
      {node (rc) [fill = lightgray] at (c, r){}}
      {node (rc) at (c, r){}};
      }
      }
      end{tikzpicture}

      end{document}


      enter image description here



      Of course, using PGF methods for the picture case is much easier.






      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%2f467485%2fwhat-is-wrong-with-the-use-of-isodd-of-xifthen%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        5














        You are implicitly assuming that isodd does calculations. But this is not what happens, it actually simply takes the begin of the argument until it hits something that is no longer a number. So you would need to do the addition first and then fed the result to isodd. Or use the tools of pgf:



        documentclass{article}
        usepackage{tikz}
        usepackage{xifthen}

        begin{document}
        ifthenelse{isodd{124blub}}{odd}{even}

        ifthenelse{isodd{123blub}}{odd}{even}

        ifthenelse{isodd{2+3}}{odd}{even}

        ifthenelse{isodd{3+2}}{odd}{even}

        bigskip
        begin{tikzpicture}[every node/.style = {draw, circle, minimum size = 10pt}]
        foreach r in {1, ..., 4} {
        foreach c in {1, ..., 5} {
        pgfmathsetmacromycolor{isodd{numexprr+c}?"lightgray":"white"}
        node (rc) [fill =mycolor ] at (c, r){};
        }
        }
        end{tikzpicture}
        end{document}


        enter image description here






        share|improve this answer


























          5














          You are implicitly assuming that isodd does calculations. But this is not what happens, it actually simply takes the begin of the argument until it hits something that is no longer a number. So you would need to do the addition first and then fed the result to isodd. Or use the tools of pgf:



          documentclass{article}
          usepackage{tikz}
          usepackage{xifthen}

          begin{document}
          ifthenelse{isodd{124blub}}{odd}{even}

          ifthenelse{isodd{123blub}}{odd}{even}

          ifthenelse{isodd{2+3}}{odd}{even}

          ifthenelse{isodd{3+2}}{odd}{even}

          bigskip
          begin{tikzpicture}[every node/.style = {draw, circle, minimum size = 10pt}]
          foreach r in {1, ..., 4} {
          foreach c in {1, ..., 5} {
          pgfmathsetmacromycolor{isodd{numexprr+c}?"lightgray":"white"}
          node (rc) [fill =mycolor ] at (c, r){};
          }
          }
          end{tikzpicture}
          end{document}


          enter image description here






          share|improve this answer
























            5












            5








            5






            You are implicitly assuming that isodd does calculations. But this is not what happens, it actually simply takes the begin of the argument until it hits something that is no longer a number. So you would need to do the addition first and then fed the result to isodd. Or use the tools of pgf:



            documentclass{article}
            usepackage{tikz}
            usepackage{xifthen}

            begin{document}
            ifthenelse{isodd{124blub}}{odd}{even}

            ifthenelse{isodd{123blub}}{odd}{even}

            ifthenelse{isodd{2+3}}{odd}{even}

            ifthenelse{isodd{3+2}}{odd}{even}

            bigskip
            begin{tikzpicture}[every node/.style = {draw, circle, minimum size = 10pt}]
            foreach r in {1, ..., 4} {
            foreach c in {1, ..., 5} {
            pgfmathsetmacromycolor{isodd{numexprr+c}?"lightgray":"white"}
            node (rc) [fill =mycolor ] at (c, r){};
            }
            }
            end{tikzpicture}
            end{document}


            enter image description here






            share|improve this answer












            You are implicitly assuming that isodd does calculations. But this is not what happens, it actually simply takes the begin of the argument until it hits something that is no longer a number. So you would need to do the addition first and then fed the result to isodd. Or use the tools of pgf:



            documentclass{article}
            usepackage{tikz}
            usepackage{xifthen}

            begin{document}
            ifthenelse{isodd{124blub}}{odd}{even}

            ifthenelse{isodd{123blub}}{odd}{even}

            ifthenelse{isodd{2+3}}{odd}{even}

            ifthenelse{isodd{3+2}}{odd}{even}

            bigskip
            begin{tikzpicture}[every node/.style = {draw, circle, minimum size = 10pt}]
            foreach r in {1, ..., 4} {
            foreach c in {1, ..., 5} {
            pgfmathsetmacromycolor{isodd{numexprr+c}?"lightgray":"white"}
            node (rc) [fill =mycolor ] at (c, r){};
            }
            }
            end{tikzpicture}
            end{document}


            enter image description here







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Dec 27 '18 at 10:18









            Ulrike Fischer

            186k7290669




            186k7290669























                5














                I'd suggest using TeX's ifodd (or etoolbox); xifthen-and-friends may be considered obsolete:



                enter image description here



                documentclass{article}

                usepackage{xfp,tikz}

                begin{document}

                begin{tikzpicture}[every node/.style = {draw, circle, minimum size = 10pt}]
                foreach r in {1, ..., 4} {
                foreach c in {1, ..., 5} {
                ifoddinteval{r+c}
                node (rc) [fill = lightgray] at (c, r) {};
                else
                node (rc) at (c, r) {};
                fi
                }
                }
                end{tikzpicture}

                end{document}


                I use xfp since it is convenient and provides an expandable inteval for integer evaluation that can be used in conditioning options like ifodd. You can also do it without xfp:



                      ifoddnumexprr+crelax
                %...





                share|improve this answer


























                  5














                  I'd suggest using TeX's ifodd (or etoolbox); xifthen-and-friends may be considered obsolete:



                  enter image description here



                  documentclass{article}

                  usepackage{xfp,tikz}

                  begin{document}

                  begin{tikzpicture}[every node/.style = {draw, circle, minimum size = 10pt}]
                  foreach r in {1, ..., 4} {
                  foreach c in {1, ..., 5} {
                  ifoddinteval{r+c}
                  node (rc) [fill = lightgray] at (c, r) {};
                  else
                  node (rc) at (c, r) {};
                  fi
                  }
                  }
                  end{tikzpicture}

                  end{document}


                  I use xfp since it is convenient and provides an expandable inteval for integer evaluation that can be used in conditioning options like ifodd. You can also do it without xfp:



                        ifoddnumexprr+crelax
                  %...





                  share|improve this answer
























                    5












                    5








                    5






                    I'd suggest using TeX's ifodd (or etoolbox); xifthen-and-friends may be considered obsolete:



                    enter image description here



                    documentclass{article}

                    usepackage{xfp,tikz}

                    begin{document}

                    begin{tikzpicture}[every node/.style = {draw, circle, minimum size = 10pt}]
                    foreach r in {1, ..., 4} {
                    foreach c in {1, ..., 5} {
                    ifoddinteval{r+c}
                    node (rc) [fill = lightgray] at (c, r) {};
                    else
                    node (rc) at (c, r) {};
                    fi
                    }
                    }
                    end{tikzpicture}

                    end{document}


                    I use xfp since it is convenient and provides an expandable inteval for integer evaluation that can be used in conditioning options like ifodd. You can also do it without xfp:



                          ifoddnumexprr+crelax
                    %...





                    share|improve this answer












                    I'd suggest using TeX's ifodd (or etoolbox); xifthen-and-friends may be considered obsolete:



                    enter image description here



                    documentclass{article}

                    usepackage{xfp,tikz}

                    begin{document}

                    begin{tikzpicture}[every node/.style = {draw, circle, minimum size = 10pt}]
                    foreach r in {1, ..., 4} {
                    foreach c in {1, ..., 5} {
                    ifoddinteval{r+c}
                    node (rc) [fill = lightgray] at (c, r) {};
                    else
                    node (rc) at (c, r) {};
                    fi
                    }
                    }
                    end{tikzpicture}

                    end{document}


                    I use xfp since it is convenient and provides an expandable inteval for integer evaluation that can be used in conditioning options like ifodd. You can also do it without xfp:



                          ifoddnumexprr+crelax
                    %...






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Dec 27 '18 at 6:40









                    Werner

                    437k649591649




                    437k649591649























                        3














                        isodd doesn't compute; you might do



                        expandafterifthenelseexpandafter{expandafterNOTexpandafterisoddexpandafter{thenumexprr+c}}


                        but it's not something I'd use myself. ;-)



                        Here's a (partial) reimplementation of xifthen allowing expressions; the syntax is different, though: for parentheses you use ( and ) rather than ( and ). For the connectives, AND, OR and NOT are replaced respectively by &&, || and !.



                        documentclass{article}
                        usepackage{xparse}
                        usepackage{tikz} % for the application

                        ExplSyntaxOn
                        NewExpandableDocumentCommand{xifthenelse}{mmm}
                        {
                        bool_if:nTF { #1 } { #2 } { #3 }
                        }

                        cs_new_eq:NN numtest int_compare_p:n
                        cs_new_eq:NN oddtest int_if_odd_p:n
                        cs_new_eq:NN dimtest dim_compare_p:n
                        cs_new_eq:NN deftest cs_if_exist_p:N
                        cs_new_eq:NN namedeftest cs_if_exist_p:c
                        cs_new_eq:NN eqdeftest token_if_eq_meaning_p:NN
                        cs_new_eq:NN streqtest str_if_eq_p:ee
                        cs_new_eq:NN emptytest tl_if_blank_p:n
                        prg_new_conditional:Nnn xxifthen_legacy_conditional:n { p,T,F,TF }
                        {
                        use:c { if#1 } prg_return_true: else: prg_return_false: fi:
                        }
                        cs_new_eq:NN boolean xxifthen_legacy_conditional_p:n
                        ExplSyntaxOff

                        begin{document}

                        xifthenelse{emptytest{}}{true}{false} true

                        xifthenelse{emptytest{ }}{true}{false} true

                        xifthenelse{emptytest{ foo }}{true}{false} false

                        xifthenelse{numtest{10 * 10 + 1 > 100}}{true}{false} true

                        xifthenelse{numtest{10 * 10 + 1 > 100 * 100}}{true}{false} false

                        xifthenelse{eqdeftest{usepackage}{RequirePackage}}{true}{false} true

                        xifthenelse{eqdeftest{usepackage}{textit}}{true}{false} false

                        xifthenelse{namedeftest{@foo}}{true}{false} false

                        xifthenelse{namedeftest{@for}}{true}{false} true

                        xifthenelse{namedeftest{@for} || numtest{1>2}}{true}{false} true

                        xifthenelse{namedeftest{@for} && numtest{1>2}}{true}{false} false

                        xifthenelse{namedeftest{@for} && !numtest{1>2}}{true}{false} true

                        xifthenelse{!oddtest{1+3}}{true}{false} true

                        xifthenelse{boolean{mmode}}{true}{false} false

                        $xifthenelse{boolean{mmode}}{true}{false}$ true

                        bigskip

                        begin{tikzpicture}[every node/.style = {draw, circle, minimum size = 10pt}]
                        foreach r in {1, ..., 4} {
                        foreach c in {1, ..., 5} {
                        xifthenelse{!oddtest{r+c}}
                        {node (rc) [fill = lightgray] at (c, r){}}
                        {node (rc) at (c, r){}};
                        }
                        }
                        end{tikzpicture}

                        end{document}


                        enter image description here



                        Of course, using PGF methods for the picture case is much easier.






                        share|improve this answer


























                          3














                          isodd doesn't compute; you might do



                          expandafterifthenelseexpandafter{expandafterNOTexpandafterisoddexpandafter{thenumexprr+c}}


                          but it's not something I'd use myself. ;-)



                          Here's a (partial) reimplementation of xifthen allowing expressions; the syntax is different, though: for parentheses you use ( and ) rather than ( and ). For the connectives, AND, OR and NOT are replaced respectively by &&, || and !.



                          documentclass{article}
                          usepackage{xparse}
                          usepackage{tikz} % for the application

                          ExplSyntaxOn
                          NewExpandableDocumentCommand{xifthenelse}{mmm}
                          {
                          bool_if:nTF { #1 } { #2 } { #3 }
                          }

                          cs_new_eq:NN numtest int_compare_p:n
                          cs_new_eq:NN oddtest int_if_odd_p:n
                          cs_new_eq:NN dimtest dim_compare_p:n
                          cs_new_eq:NN deftest cs_if_exist_p:N
                          cs_new_eq:NN namedeftest cs_if_exist_p:c
                          cs_new_eq:NN eqdeftest token_if_eq_meaning_p:NN
                          cs_new_eq:NN streqtest str_if_eq_p:ee
                          cs_new_eq:NN emptytest tl_if_blank_p:n
                          prg_new_conditional:Nnn xxifthen_legacy_conditional:n { p,T,F,TF }
                          {
                          use:c { if#1 } prg_return_true: else: prg_return_false: fi:
                          }
                          cs_new_eq:NN boolean xxifthen_legacy_conditional_p:n
                          ExplSyntaxOff

                          begin{document}

                          xifthenelse{emptytest{}}{true}{false} true

                          xifthenelse{emptytest{ }}{true}{false} true

                          xifthenelse{emptytest{ foo }}{true}{false} false

                          xifthenelse{numtest{10 * 10 + 1 > 100}}{true}{false} true

                          xifthenelse{numtest{10 * 10 + 1 > 100 * 100}}{true}{false} false

                          xifthenelse{eqdeftest{usepackage}{RequirePackage}}{true}{false} true

                          xifthenelse{eqdeftest{usepackage}{textit}}{true}{false} false

                          xifthenelse{namedeftest{@foo}}{true}{false} false

                          xifthenelse{namedeftest{@for}}{true}{false} true

                          xifthenelse{namedeftest{@for} || numtest{1>2}}{true}{false} true

                          xifthenelse{namedeftest{@for} && numtest{1>2}}{true}{false} false

                          xifthenelse{namedeftest{@for} && !numtest{1>2}}{true}{false} true

                          xifthenelse{!oddtest{1+3}}{true}{false} true

                          xifthenelse{boolean{mmode}}{true}{false} false

                          $xifthenelse{boolean{mmode}}{true}{false}$ true

                          bigskip

                          begin{tikzpicture}[every node/.style = {draw, circle, minimum size = 10pt}]
                          foreach r in {1, ..., 4} {
                          foreach c in {1, ..., 5} {
                          xifthenelse{!oddtest{r+c}}
                          {node (rc) [fill = lightgray] at (c, r){}}
                          {node (rc) at (c, r){}};
                          }
                          }
                          end{tikzpicture}

                          end{document}


                          enter image description here



                          Of course, using PGF methods for the picture case is much easier.






                          share|improve this answer
























                            3












                            3








                            3






                            isodd doesn't compute; you might do



                            expandafterifthenelseexpandafter{expandafterNOTexpandafterisoddexpandafter{thenumexprr+c}}


                            but it's not something I'd use myself. ;-)



                            Here's a (partial) reimplementation of xifthen allowing expressions; the syntax is different, though: for parentheses you use ( and ) rather than ( and ). For the connectives, AND, OR and NOT are replaced respectively by &&, || and !.



                            documentclass{article}
                            usepackage{xparse}
                            usepackage{tikz} % for the application

                            ExplSyntaxOn
                            NewExpandableDocumentCommand{xifthenelse}{mmm}
                            {
                            bool_if:nTF { #1 } { #2 } { #3 }
                            }

                            cs_new_eq:NN numtest int_compare_p:n
                            cs_new_eq:NN oddtest int_if_odd_p:n
                            cs_new_eq:NN dimtest dim_compare_p:n
                            cs_new_eq:NN deftest cs_if_exist_p:N
                            cs_new_eq:NN namedeftest cs_if_exist_p:c
                            cs_new_eq:NN eqdeftest token_if_eq_meaning_p:NN
                            cs_new_eq:NN streqtest str_if_eq_p:ee
                            cs_new_eq:NN emptytest tl_if_blank_p:n
                            prg_new_conditional:Nnn xxifthen_legacy_conditional:n { p,T,F,TF }
                            {
                            use:c { if#1 } prg_return_true: else: prg_return_false: fi:
                            }
                            cs_new_eq:NN boolean xxifthen_legacy_conditional_p:n
                            ExplSyntaxOff

                            begin{document}

                            xifthenelse{emptytest{}}{true}{false} true

                            xifthenelse{emptytest{ }}{true}{false} true

                            xifthenelse{emptytest{ foo }}{true}{false} false

                            xifthenelse{numtest{10 * 10 + 1 > 100}}{true}{false} true

                            xifthenelse{numtest{10 * 10 + 1 > 100 * 100}}{true}{false} false

                            xifthenelse{eqdeftest{usepackage}{RequirePackage}}{true}{false} true

                            xifthenelse{eqdeftest{usepackage}{textit}}{true}{false} false

                            xifthenelse{namedeftest{@foo}}{true}{false} false

                            xifthenelse{namedeftest{@for}}{true}{false} true

                            xifthenelse{namedeftest{@for} || numtest{1>2}}{true}{false} true

                            xifthenelse{namedeftest{@for} && numtest{1>2}}{true}{false} false

                            xifthenelse{namedeftest{@for} && !numtest{1>2}}{true}{false} true

                            xifthenelse{!oddtest{1+3}}{true}{false} true

                            xifthenelse{boolean{mmode}}{true}{false} false

                            $xifthenelse{boolean{mmode}}{true}{false}$ true

                            bigskip

                            begin{tikzpicture}[every node/.style = {draw, circle, minimum size = 10pt}]
                            foreach r in {1, ..., 4} {
                            foreach c in {1, ..., 5} {
                            xifthenelse{!oddtest{r+c}}
                            {node (rc) [fill = lightgray] at (c, r){}}
                            {node (rc) at (c, r){}};
                            }
                            }
                            end{tikzpicture}

                            end{document}


                            enter image description here



                            Of course, using PGF methods for the picture case is much easier.






                            share|improve this answer












                            isodd doesn't compute; you might do



                            expandafterifthenelseexpandafter{expandafterNOTexpandafterisoddexpandafter{thenumexprr+c}}


                            but it's not something I'd use myself. ;-)



                            Here's a (partial) reimplementation of xifthen allowing expressions; the syntax is different, though: for parentheses you use ( and ) rather than ( and ). For the connectives, AND, OR and NOT are replaced respectively by &&, || and !.



                            documentclass{article}
                            usepackage{xparse}
                            usepackage{tikz} % for the application

                            ExplSyntaxOn
                            NewExpandableDocumentCommand{xifthenelse}{mmm}
                            {
                            bool_if:nTF { #1 } { #2 } { #3 }
                            }

                            cs_new_eq:NN numtest int_compare_p:n
                            cs_new_eq:NN oddtest int_if_odd_p:n
                            cs_new_eq:NN dimtest dim_compare_p:n
                            cs_new_eq:NN deftest cs_if_exist_p:N
                            cs_new_eq:NN namedeftest cs_if_exist_p:c
                            cs_new_eq:NN eqdeftest token_if_eq_meaning_p:NN
                            cs_new_eq:NN streqtest str_if_eq_p:ee
                            cs_new_eq:NN emptytest tl_if_blank_p:n
                            prg_new_conditional:Nnn xxifthen_legacy_conditional:n { p,T,F,TF }
                            {
                            use:c { if#1 } prg_return_true: else: prg_return_false: fi:
                            }
                            cs_new_eq:NN boolean xxifthen_legacy_conditional_p:n
                            ExplSyntaxOff

                            begin{document}

                            xifthenelse{emptytest{}}{true}{false} true

                            xifthenelse{emptytest{ }}{true}{false} true

                            xifthenelse{emptytest{ foo }}{true}{false} false

                            xifthenelse{numtest{10 * 10 + 1 > 100}}{true}{false} true

                            xifthenelse{numtest{10 * 10 + 1 > 100 * 100}}{true}{false} false

                            xifthenelse{eqdeftest{usepackage}{RequirePackage}}{true}{false} true

                            xifthenelse{eqdeftest{usepackage}{textit}}{true}{false} false

                            xifthenelse{namedeftest{@foo}}{true}{false} false

                            xifthenelse{namedeftest{@for}}{true}{false} true

                            xifthenelse{namedeftest{@for} || numtest{1>2}}{true}{false} true

                            xifthenelse{namedeftest{@for} && numtest{1>2}}{true}{false} false

                            xifthenelse{namedeftest{@for} && !numtest{1>2}}{true}{false} true

                            xifthenelse{!oddtest{1+3}}{true}{false} true

                            xifthenelse{boolean{mmode}}{true}{false} false

                            $xifthenelse{boolean{mmode}}{true}{false}$ true

                            bigskip

                            begin{tikzpicture}[every node/.style = {draw, circle, minimum size = 10pt}]
                            foreach r in {1, ..., 4} {
                            foreach c in {1, ..., 5} {
                            xifthenelse{!oddtest{r+c}}
                            {node (rc) [fill = lightgray] at (c, r){}}
                            {node (rc) at (c, r){}};
                            }
                            }
                            end{tikzpicture}

                            end{document}


                            enter image description here



                            Of course, using PGF methods for the picture case is much easier.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Dec 27 '18 at 12:19









                            egreg

                            709k8618823165




                            709k8618823165






























                                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.





                                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%2f467485%2fwhat-is-wrong-with-the-use-of-isodd-of-xifthen%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

                                Terni

                                A new problem with tex4ht and tikz

                                Sun Ra