Conditionals within tikz node specification

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











up vote
4
down vote

favorite












I would like to specify custom hierarchies of tikz nodes where I do a few geometry calculations related to text depth, text width, text height, and so on.



In the process of writing custom commands to automate some of these calculations, I end up wanting to use TeX conditionals mixed in with tikz code. I read in another question that pgfextra can be used for this. However, it seems that this only works at the level of the tikzpicture environment.



A minimal example of what I would like to do is the following:



documentclass[class=minimal, border=0pt]standalone

usepackagetikz

newififDebug
%Debugtrue
Debugfalse

newcommandMyNode
node[anchor=north west,
minimum width=5cm,
minimum height=5cm,
fill=green,
pgfextraifDebug opacity=0.2,fi
] at (current page.north west)

begindocument
begintikzpicture
MyNode;
endtikzpicture
enddocument


The line containing pgfextra is giving me trouble. What should I do to conditionally change arguments to node?



Thanks!










share|improve this question







New contributor




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























    up vote
    4
    down vote

    favorite












    I would like to specify custom hierarchies of tikz nodes where I do a few geometry calculations related to text depth, text width, text height, and so on.



    In the process of writing custom commands to automate some of these calculations, I end up wanting to use TeX conditionals mixed in with tikz code. I read in another question that pgfextra can be used for this. However, it seems that this only works at the level of the tikzpicture environment.



    A minimal example of what I would like to do is the following:



    documentclass[class=minimal, border=0pt]standalone

    usepackagetikz

    newififDebug
    %Debugtrue
    Debugfalse

    newcommandMyNode
    node[anchor=north west,
    minimum width=5cm,
    minimum height=5cm,
    fill=green,
    pgfextraifDebug opacity=0.2,fi
    ] at (current page.north west)

    begindocument
    begintikzpicture
    MyNode;
    endtikzpicture
    enddocument


    The line containing pgfextra is giving me trouble. What should I do to conditionally change arguments to node?



    Thanks!










    share|improve this question







    New contributor




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





















      up vote
      4
      down vote

      favorite









      up vote
      4
      down vote

      favorite











      I would like to specify custom hierarchies of tikz nodes where I do a few geometry calculations related to text depth, text width, text height, and so on.



      In the process of writing custom commands to automate some of these calculations, I end up wanting to use TeX conditionals mixed in with tikz code. I read in another question that pgfextra can be used for this. However, it seems that this only works at the level of the tikzpicture environment.



      A minimal example of what I would like to do is the following:



      documentclass[class=minimal, border=0pt]standalone

      usepackagetikz

      newififDebug
      %Debugtrue
      Debugfalse

      newcommandMyNode
      node[anchor=north west,
      minimum width=5cm,
      minimum height=5cm,
      fill=green,
      pgfextraifDebug opacity=0.2,fi
      ] at (current page.north west)

      begindocument
      begintikzpicture
      MyNode;
      endtikzpicture
      enddocument


      The line containing pgfextra is giving me trouble. What should I do to conditionally change arguments to node?



      Thanks!










      share|improve this question







      New contributor




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











      I would like to specify custom hierarchies of tikz nodes where I do a few geometry calculations related to text depth, text width, text height, and so on.



      In the process of writing custom commands to automate some of these calculations, I end up wanting to use TeX conditionals mixed in with tikz code. I read in another question that pgfextra can be used for this. However, it seems that this only works at the level of the tikzpicture environment.



      A minimal example of what I would like to do is the following:



      documentclass[class=minimal, border=0pt]standalone

      usepackagetikz

      newififDebug
      %Debugtrue
      Debugfalse

      newcommandMyNode
      node[anchor=north west,
      minimum width=5cm,
      minimum height=5cm,
      fill=green,
      pgfextraifDebug opacity=0.2,fi
      ] at (current page.north west)

      begindocument
      begintikzpicture
      MyNode;
      endtikzpicture
      enddocument


      The line containing pgfextra is giving me trouble. What should I do to conditionally change arguments to node?



      Thanks!







      tikz-pgf






      share|improve this question







      New contributor




      sblatt 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




      sblatt 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




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









      asked 2 days ago









      sblatt

      333




      333




      New contributor




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





      New contributor





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






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




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          5
          down vote



          accepted










          Welcome to TeX.SE! Please try to avoid all pgfextra stuff. You can achieve almost everything with pgfkeys, also here.



          documentclass[class=minimal, border=0pt]standalone

          usepackagetikz

          newififDebug
          %Debugtrue
          Debugfalse

          tikzsetDebug/.code=ifDebugpgfkeysalsoopacity=0.2fi

          newcommandMyNode
          node[anchor=north west,
          minimum width=5cm,
          minimum height=5cm,
          fill=green,
          Debug,
          ] at (current page.north west)

          begindocument
          begintikzpicture
          Debugtrue
          MyNode;
          endtikzpicture
          enddocument


          enter image description here



          If I comment out Debugtrue, I get.



          enter image description here






          share|improve this answer



























            up vote
            4
            down vote













            With a Tikz style (implemented with the /.code handler) this is rather straightforward:



            documentclass[class=minimal, border=0pt]standalone

            usepackagetikz

            newififDebug
            Debugtrue
            %Debugfalse

            tikzset
            my node/.code=
            tikzset
            anchor=north west,
            minimum width=5cm,
            minimum height=5cm,
            fill=green,

            ifDebug
            tikzsetopacity=0.2
            fi



            begindocument
            begintikzpicture
            node[my node];
            Debugfalse
            node[my node] at (6,0);
            endtikzpicture
            enddocument


            enter image description here



            As mentioned by marmot in his answer you should stay away from pgfextra in general. My personal preference is also to stay away from custom commands where styles can do the same, but that really is personal.






            share|improve this answer


















            • 1




              You were faster, +1. I don't know why someone would upvote only my answer, but not yours. Sad.
              – marmot
              2 days ago










            • @marmot Well if someone thinks your solution is cleaner (which I could agree with) then it's a normal reaction :)
              – Max
              2 days ago










            • Thanks to both of you for the quick replies!
              – sblatt
              2 days ago










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



            );






            sblatt 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%2f450236%2fconditionals-within-tikz-node-specification%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
            5
            down vote



            accepted










            Welcome to TeX.SE! Please try to avoid all pgfextra stuff. You can achieve almost everything with pgfkeys, also here.



            documentclass[class=minimal, border=0pt]standalone

            usepackagetikz

            newififDebug
            %Debugtrue
            Debugfalse

            tikzsetDebug/.code=ifDebugpgfkeysalsoopacity=0.2fi

            newcommandMyNode
            node[anchor=north west,
            minimum width=5cm,
            minimum height=5cm,
            fill=green,
            Debug,
            ] at (current page.north west)

            begindocument
            begintikzpicture
            Debugtrue
            MyNode;
            endtikzpicture
            enddocument


            enter image description here



            If I comment out Debugtrue, I get.



            enter image description here






            share|improve this answer
























              up vote
              5
              down vote



              accepted










              Welcome to TeX.SE! Please try to avoid all pgfextra stuff. You can achieve almost everything with pgfkeys, also here.



              documentclass[class=minimal, border=0pt]standalone

              usepackagetikz

              newififDebug
              %Debugtrue
              Debugfalse

              tikzsetDebug/.code=ifDebugpgfkeysalsoopacity=0.2fi

              newcommandMyNode
              node[anchor=north west,
              minimum width=5cm,
              minimum height=5cm,
              fill=green,
              Debug,
              ] at (current page.north west)

              begindocument
              begintikzpicture
              Debugtrue
              MyNode;
              endtikzpicture
              enddocument


              enter image description here



              If I comment out Debugtrue, I get.



              enter image description here






              share|improve this answer






















                up vote
                5
                down vote



                accepted







                up vote
                5
                down vote



                accepted






                Welcome to TeX.SE! Please try to avoid all pgfextra stuff. You can achieve almost everything with pgfkeys, also here.



                documentclass[class=minimal, border=0pt]standalone

                usepackagetikz

                newififDebug
                %Debugtrue
                Debugfalse

                tikzsetDebug/.code=ifDebugpgfkeysalsoopacity=0.2fi

                newcommandMyNode
                node[anchor=north west,
                minimum width=5cm,
                minimum height=5cm,
                fill=green,
                Debug,
                ] at (current page.north west)

                begindocument
                begintikzpicture
                Debugtrue
                MyNode;
                endtikzpicture
                enddocument


                enter image description here



                If I comment out Debugtrue, I get.



                enter image description here






                share|improve this answer












                Welcome to TeX.SE! Please try to avoid all pgfextra stuff. You can achieve almost everything with pgfkeys, also here.



                documentclass[class=minimal, border=0pt]standalone

                usepackagetikz

                newififDebug
                %Debugtrue
                Debugfalse

                tikzsetDebug/.code=ifDebugpgfkeysalsoopacity=0.2fi

                newcommandMyNode
                node[anchor=north west,
                minimum width=5cm,
                minimum height=5cm,
                fill=green,
                Debug,
                ] at (current page.north west)

                begindocument
                begintikzpicture
                Debugtrue
                MyNode;
                endtikzpicture
                enddocument


                enter image description here



                If I comment out Debugtrue, I get.



                enter image description here







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 2 days ago









                marmot

                56.8k462124




                56.8k462124




















                    up vote
                    4
                    down vote













                    With a Tikz style (implemented with the /.code handler) this is rather straightforward:



                    documentclass[class=minimal, border=0pt]standalone

                    usepackagetikz

                    newififDebug
                    Debugtrue
                    %Debugfalse

                    tikzset
                    my node/.code=
                    tikzset
                    anchor=north west,
                    minimum width=5cm,
                    minimum height=5cm,
                    fill=green,

                    ifDebug
                    tikzsetopacity=0.2
                    fi



                    begindocument
                    begintikzpicture
                    node[my node];
                    Debugfalse
                    node[my node] at (6,0);
                    endtikzpicture
                    enddocument


                    enter image description here



                    As mentioned by marmot in his answer you should stay away from pgfextra in general. My personal preference is also to stay away from custom commands where styles can do the same, but that really is personal.






                    share|improve this answer


















                    • 1




                      You were faster, +1. I don't know why someone would upvote only my answer, but not yours. Sad.
                      – marmot
                      2 days ago










                    • @marmot Well if someone thinks your solution is cleaner (which I could agree with) then it's a normal reaction :)
                      – Max
                      2 days ago










                    • Thanks to both of you for the quick replies!
                      – sblatt
                      2 days ago














                    up vote
                    4
                    down vote













                    With a Tikz style (implemented with the /.code handler) this is rather straightforward:



                    documentclass[class=minimal, border=0pt]standalone

                    usepackagetikz

                    newififDebug
                    Debugtrue
                    %Debugfalse

                    tikzset
                    my node/.code=
                    tikzset
                    anchor=north west,
                    minimum width=5cm,
                    minimum height=5cm,
                    fill=green,

                    ifDebug
                    tikzsetopacity=0.2
                    fi



                    begindocument
                    begintikzpicture
                    node[my node];
                    Debugfalse
                    node[my node] at (6,0);
                    endtikzpicture
                    enddocument


                    enter image description here



                    As mentioned by marmot in his answer you should stay away from pgfextra in general. My personal preference is also to stay away from custom commands where styles can do the same, but that really is personal.






                    share|improve this answer


















                    • 1




                      You were faster, +1. I don't know why someone would upvote only my answer, but not yours. Sad.
                      – marmot
                      2 days ago










                    • @marmot Well if someone thinks your solution is cleaner (which I could agree with) then it's a normal reaction :)
                      – Max
                      2 days ago










                    • Thanks to both of you for the quick replies!
                      – sblatt
                      2 days ago












                    up vote
                    4
                    down vote










                    up vote
                    4
                    down vote









                    With a Tikz style (implemented with the /.code handler) this is rather straightforward:



                    documentclass[class=minimal, border=0pt]standalone

                    usepackagetikz

                    newififDebug
                    Debugtrue
                    %Debugfalse

                    tikzset
                    my node/.code=
                    tikzset
                    anchor=north west,
                    minimum width=5cm,
                    minimum height=5cm,
                    fill=green,

                    ifDebug
                    tikzsetopacity=0.2
                    fi



                    begindocument
                    begintikzpicture
                    node[my node];
                    Debugfalse
                    node[my node] at (6,0);
                    endtikzpicture
                    enddocument


                    enter image description here



                    As mentioned by marmot in his answer you should stay away from pgfextra in general. My personal preference is also to stay away from custom commands where styles can do the same, but that really is personal.






                    share|improve this answer














                    With a Tikz style (implemented with the /.code handler) this is rather straightforward:



                    documentclass[class=minimal, border=0pt]standalone

                    usepackagetikz

                    newififDebug
                    Debugtrue
                    %Debugfalse

                    tikzset
                    my node/.code=
                    tikzset
                    anchor=north west,
                    minimum width=5cm,
                    minimum height=5cm,
                    fill=green,

                    ifDebug
                    tikzsetopacity=0.2
                    fi



                    begindocument
                    begintikzpicture
                    node[my node];
                    Debugfalse
                    node[my node] at (6,0);
                    endtikzpicture
                    enddocument


                    enter image description here



                    As mentioned by marmot in his answer you should stay away from pgfextra in general. My personal preference is also to stay away from custom commands where styles can do the same, but that really is personal.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited 2 days ago

























                    answered 2 days ago









                    Max

                    6,14311727




                    6,14311727







                    • 1




                      You were faster, +1. I don't know why someone would upvote only my answer, but not yours. Sad.
                      – marmot
                      2 days ago










                    • @marmot Well if someone thinks your solution is cleaner (which I could agree with) then it's a normal reaction :)
                      – Max
                      2 days ago










                    • Thanks to both of you for the quick replies!
                      – sblatt
                      2 days ago












                    • 1




                      You were faster, +1. I don't know why someone would upvote only my answer, but not yours. Sad.
                      – marmot
                      2 days ago










                    • @marmot Well if someone thinks your solution is cleaner (which I could agree with) then it's a normal reaction :)
                      – Max
                      2 days ago










                    • Thanks to both of you for the quick replies!
                      – sblatt
                      2 days ago







                    1




                    1




                    You were faster, +1. I don't know why someone would upvote only my answer, but not yours. Sad.
                    – marmot
                    2 days ago




                    You were faster, +1. I don't know why someone would upvote only my answer, but not yours. Sad.
                    – marmot
                    2 days ago












                    @marmot Well if someone thinks your solution is cleaner (which I could agree with) then it's a normal reaction :)
                    – Max
                    2 days ago




                    @marmot Well if someone thinks your solution is cleaner (which I could agree with) then it's a normal reaction :)
                    – Max
                    2 days ago












                    Thanks to both of you for the quick replies!
                    – sblatt
                    2 days ago




                    Thanks to both of you for the quick replies!
                    – sblatt
                    2 days ago










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









                     

                    draft saved


                    draft discarded


















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












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











                    sblatt 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%2f450236%2fconditionals-within-tikz-node-specification%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

                    Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

                    Confectionery