Expanding macro defined by csdef to define a style via tikzset

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











up vote
7
down vote

favorite












I need to store tikz option in a csdef:



csdefMy Node Optiondraw=red, thick, fill=yellow


How do I use this definition to define a style via tikzset?
I attempted to use .expand once as per How do I define tikz styles with a xkeyval command?:



tikzsetNode Options/.style/.expand once=csuseMy Node Option


but that leads to a




Package pgfkeys Error: I do not know the key '/tikz/draw=red, thick, fill=yellow' and I am going to ignore it. Perhaps you misspelled it.




The desired result is to modify only the tikzset in the MWE and obtain:



enter image description here



Notes:



  • As egreg commented, spaces in names of commands should be avoided. However, in my actual use case, the command names defined by the csdef are named after file names with paths which include spaces, slashes, numbers, periods.

Code:



documentclassarticle

usepackagetikz
usepackageetoolbox

begindocument


csdefMy Node Optiondraw=red, thick, fill=yellow

noindent
begintikzpicture
tikzsetNode Options/.style/.expand once=csuseMy Node Option%% ????

node [Node Options] at (0,0) Node Text;
endtikzpicture%
enddocument









share|improve this question



















  • 2




    You'd need /.expand thrice, which doesn't exist. But /.expand twice=csname My Node Optionendcsname works. I know that spaces in names of commands and options is bad. ;-)
    – egreg
    8 hours ago














up vote
7
down vote

favorite












I need to store tikz option in a csdef:



csdefMy Node Optiondraw=red, thick, fill=yellow


How do I use this definition to define a style via tikzset?
I attempted to use .expand once as per How do I define tikz styles with a xkeyval command?:



tikzsetNode Options/.style/.expand once=csuseMy Node Option


but that leads to a




Package pgfkeys Error: I do not know the key '/tikz/draw=red, thick, fill=yellow' and I am going to ignore it. Perhaps you misspelled it.




The desired result is to modify only the tikzset in the MWE and obtain:



enter image description here



Notes:



  • As egreg commented, spaces in names of commands should be avoided. However, in my actual use case, the command names defined by the csdef are named after file names with paths which include spaces, slashes, numbers, periods.

Code:



documentclassarticle

usepackagetikz
usepackageetoolbox

begindocument


csdefMy Node Optiondraw=red, thick, fill=yellow

noindent
begintikzpicture
tikzsetNode Options/.style/.expand once=csuseMy Node Option%% ????

node [Node Options] at (0,0) Node Text;
endtikzpicture%
enddocument









share|improve this question



















  • 2




    You'd need /.expand thrice, which doesn't exist. But /.expand twice=csname My Node Optionendcsname works. I know that spaces in names of commands and options is bad. ;-)
    – egreg
    8 hours ago












up vote
7
down vote

favorite









up vote
7
down vote

favorite











I need to store tikz option in a csdef:



csdefMy Node Optiondraw=red, thick, fill=yellow


How do I use this definition to define a style via tikzset?
I attempted to use .expand once as per How do I define tikz styles with a xkeyval command?:



tikzsetNode Options/.style/.expand once=csuseMy Node Option


but that leads to a




Package pgfkeys Error: I do not know the key '/tikz/draw=red, thick, fill=yellow' and I am going to ignore it. Perhaps you misspelled it.




The desired result is to modify only the tikzset in the MWE and obtain:



enter image description here



Notes:



  • As egreg commented, spaces in names of commands should be avoided. However, in my actual use case, the command names defined by the csdef are named after file names with paths which include spaces, slashes, numbers, periods.

Code:



documentclassarticle

usepackagetikz
usepackageetoolbox

begindocument


csdefMy Node Optiondraw=red, thick, fill=yellow

noindent
begintikzpicture
tikzsetNode Options/.style/.expand once=csuseMy Node Option%% ????

node [Node Options] at (0,0) Node Text;
endtikzpicture%
enddocument









share|improve this question















I need to store tikz option in a csdef:



csdefMy Node Optiondraw=red, thick, fill=yellow


How do I use this definition to define a style via tikzset?
I attempted to use .expand once as per How do I define tikz styles with a xkeyval command?:



tikzsetNode Options/.style/.expand once=csuseMy Node Option


but that leads to a




Package pgfkeys Error: I do not know the key '/tikz/draw=red, thick, fill=yellow' and I am going to ignore it. Perhaps you misspelled it.




The desired result is to modify only the tikzset in the MWE and obtain:



enter image description here



Notes:



  • As egreg commented, spaces in names of commands should be avoided. However, in my actual use case, the command names defined by the csdef are named after file names with paths which include spaces, slashes, numbers, periods.

Code:



documentclassarticle

usepackagetikz
usepackageetoolbox

begindocument


csdefMy Node Optiondraw=red, thick, fill=yellow

noindent
begintikzpicture
tikzsetNode Options/.style/.expand once=csuseMy Node Option%% ????

node [Node Options] at (0,0) Node Text;
endtikzpicture%
enddocument






tikz-pgf tikz-styles expansion etoolbox






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 10 mins ago

























asked 9 hours ago









Peter Grill

162k24430736




162k24430736







  • 2




    You'd need /.expand thrice, which doesn't exist. But /.expand twice=csname My Node Optionendcsname works. I know that spaces in names of commands and options is bad. ;-)
    – egreg
    8 hours ago












  • 2




    You'd need /.expand thrice, which doesn't exist. But /.expand twice=csname My Node Optionendcsname works. I know that spaces in names of commands and options is bad. ;-)
    – egreg
    8 hours ago







2




2




You'd need /.expand thrice, which doesn't exist. But /.expand twice=csname My Node Optionendcsname works. I know that spaces in names of commands and options is bad. ;-)
– egreg
8 hours ago




You'd need /.expand thrice, which doesn't exist. But /.expand twice=csname My Node Optionendcsname works. I know that spaces in names of commands and options is bad. ;-)
– egreg
8 hours ago










3 Answers
3






active

oldest

votes

















up vote
8
down vote



accepted










You can use expanded instead of expand once in your MWE:



tikzsetNode Options/.style/.expanded=csuseMy Node Option%% ????






share|improve this answer
















  • 2




    +1 It's better to give a complete minimal working example as an answer to show that your solution works, but I agree that this does work and hence that this is probably the preferred tikz solution.
    – Andrew
    8 hours ago


















up vote
6
down vote













csuse... is not quite the same as csname...endcsname:



% etoolbox.sty, line 883:
newcommand*csuse[1]%
ifcsname#1endcsname
csname#1expandafterendcsname
fi


If you expand once in your context you get



ifcsname My Node Optionendcsnamecsname My Node Optionendcsnamefi


A further expansion step will remove the conditional, leaving



csname My Node Optionendcsnamefi


which requires two expansion steps in order to deliver



draw=red, thick, fill=yellowfi


but then the fi kicks in, because it is shuffled around at the wrong place.



You can do



tikzsetNode Options/.style/.expand twice=csname My Node Optionendcsname


that avoids the problem of the dangling if.



However, the best strategy, in my opinion, is to use styles all around:



documentclassarticle

usepackagetikz

begindocument

tikzsetMy Node Option/.style=draw=red, thick, fill=yellow

begintikzpicture
tikzsetNode Options/.style=My Node Option

node [Node Options] at (0,0) Node Text;
endtikzpicture

enddocument





share|improve this answer



























    up vote
    5
    down vote













    You can use the begingroupedefxendgroup <stuff to expand>x expansion trick:



    documentclassarticle

    usepackagetikz
    usepackageetoolbox

    begindocument

    csdefMy Node Optiondraw=red, thick, fill=yellow

    noindent
    begintikzpicture
    begingroupedefxendgroup
    noexpandtikzsetNode Options/.style=csuseMy Node Option%
    x

    node [Node Options] at (0,0) Node Text;
    endtikzpicture%

    enddocument


    Note the additional braces around the csuse.






    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%2f457429%2fexpanding-macro-defined-by-csdef-to-define-a-style-via-tikzset%23new-answer', 'question_page');

      );

      Post as a guest






























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      8
      down vote



      accepted










      You can use expanded instead of expand once in your MWE:



      tikzsetNode Options/.style/.expanded=csuseMy Node Option%% ????






      share|improve this answer
















      • 2




        +1 It's better to give a complete minimal working example as an answer to show that your solution works, but I agree that this does work and hence that this is probably the preferred tikz solution.
        – Andrew
        8 hours ago















      up vote
      8
      down vote



      accepted










      You can use expanded instead of expand once in your MWE:



      tikzsetNode Options/.style/.expanded=csuseMy Node Option%% ????






      share|improve this answer
















      • 2




        +1 It's better to give a complete minimal working example as an answer to show that your solution works, but I agree that this does work and hence that this is probably the preferred tikz solution.
        – Andrew
        8 hours ago













      up vote
      8
      down vote



      accepted







      up vote
      8
      down vote



      accepted






      You can use expanded instead of expand once in your MWE:



      tikzsetNode Options/.style/.expanded=csuseMy Node Option%% ????






      share|improve this answer












      You can use expanded instead of expand once in your MWE:



      tikzsetNode Options/.style/.expanded=csuseMy Node Option%% ????







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered 8 hours ago









      corporal

      64135




      64135







      • 2




        +1 It's better to give a complete minimal working example as an answer to show that your solution works, but I agree that this does work and hence that this is probably the preferred tikz solution.
        – Andrew
        8 hours ago













      • 2




        +1 It's better to give a complete minimal working example as an answer to show that your solution works, but I agree that this does work and hence that this is probably the preferred tikz solution.
        – Andrew
        8 hours ago








      2




      2




      +1 It's better to give a complete minimal working example as an answer to show that your solution works, but I agree that this does work and hence that this is probably the preferred tikz solution.
      – Andrew
      8 hours ago





      +1 It's better to give a complete minimal working example as an answer to show that your solution works, but I agree that this does work and hence that this is probably the preferred tikz solution.
      – Andrew
      8 hours ago











      up vote
      6
      down vote













      csuse... is not quite the same as csname...endcsname:



      % etoolbox.sty, line 883:
      newcommand*csuse[1]%
      ifcsname#1endcsname
      csname#1expandafterendcsname
      fi


      If you expand once in your context you get



      ifcsname My Node Optionendcsnamecsname My Node Optionendcsnamefi


      A further expansion step will remove the conditional, leaving



      csname My Node Optionendcsnamefi


      which requires two expansion steps in order to deliver



      draw=red, thick, fill=yellowfi


      but then the fi kicks in, because it is shuffled around at the wrong place.



      You can do



      tikzsetNode Options/.style/.expand twice=csname My Node Optionendcsname


      that avoids the problem of the dangling if.



      However, the best strategy, in my opinion, is to use styles all around:



      documentclassarticle

      usepackagetikz

      begindocument

      tikzsetMy Node Option/.style=draw=red, thick, fill=yellow

      begintikzpicture
      tikzsetNode Options/.style=My Node Option

      node [Node Options] at (0,0) Node Text;
      endtikzpicture

      enddocument





      share|improve this answer
























        up vote
        6
        down vote













        csuse... is not quite the same as csname...endcsname:



        % etoolbox.sty, line 883:
        newcommand*csuse[1]%
        ifcsname#1endcsname
        csname#1expandafterendcsname
        fi


        If you expand once in your context you get



        ifcsname My Node Optionendcsnamecsname My Node Optionendcsnamefi


        A further expansion step will remove the conditional, leaving



        csname My Node Optionendcsnamefi


        which requires two expansion steps in order to deliver



        draw=red, thick, fill=yellowfi


        but then the fi kicks in, because it is shuffled around at the wrong place.



        You can do



        tikzsetNode Options/.style/.expand twice=csname My Node Optionendcsname


        that avoids the problem of the dangling if.



        However, the best strategy, in my opinion, is to use styles all around:



        documentclassarticle

        usepackagetikz

        begindocument

        tikzsetMy Node Option/.style=draw=red, thick, fill=yellow

        begintikzpicture
        tikzsetNode Options/.style=My Node Option

        node [Node Options] at (0,0) Node Text;
        endtikzpicture

        enddocument





        share|improve this answer






















          up vote
          6
          down vote










          up vote
          6
          down vote









          csuse... is not quite the same as csname...endcsname:



          % etoolbox.sty, line 883:
          newcommand*csuse[1]%
          ifcsname#1endcsname
          csname#1expandafterendcsname
          fi


          If you expand once in your context you get



          ifcsname My Node Optionendcsnamecsname My Node Optionendcsnamefi


          A further expansion step will remove the conditional, leaving



          csname My Node Optionendcsnamefi


          which requires two expansion steps in order to deliver



          draw=red, thick, fill=yellowfi


          but then the fi kicks in, because it is shuffled around at the wrong place.



          You can do



          tikzsetNode Options/.style/.expand twice=csname My Node Optionendcsname


          that avoids the problem of the dangling if.



          However, the best strategy, in my opinion, is to use styles all around:



          documentclassarticle

          usepackagetikz

          begindocument

          tikzsetMy Node Option/.style=draw=red, thick, fill=yellow

          begintikzpicture
          tikzsetNode Options/.style=My Node Option

          node [Node Options] at (0,0) Node Text;
          endtikzpicture

          enddocument





          share|improve this answer












          csuse... is not quite the same as csname...endcsname:



          % etoolbox.sty, line 883:
          newcommand*csuse[1]%
          ifcsname#1endcsname
          csname#1expandafterendcsname
          fi


          If you expand once in your context you get



          ifcsname My Node Optionendcsnamecsname My Node Optionendcsnamefi


          A further expansion step will remove the conditional, leaving



          csname My Node Optionendcsnamefi


          which requires two expansion steps in order to deliver



          draw=red, thick, fill=yellowfi


          but then the fi kicks in, because it is shuffled around at the wrong place.



          You can do



          tikzsetNode Options/.style/.expand twice=csname My Node Optionendcsname


          that avoids the problem of the dangling if.



          However, the best strategy, in my opinion, is to use styles all around:



          documentclassarticle

          usepackagetikz

          begindocument

          tikzsetMy Node Option/.style=draw=red, thick, fill=yellow

          begintikzpicture
          tikzsetNode Options/.style=My Node Option

          node [Node Options] at (0,0) Node Text;
          endtikzpicture

          enddocument






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 7 hours ago









          egreg

          693k8518443094




          693k8518443094




















              up vote
              5
              down vote













              You can use the begingroupedefxendgroup <stuff to expand>x expansion trick:



              documentclassarticle

              usepackagetikz
              usepackageetoolbox

              begindocument

              csdefMy Node Optiondraw=red, thick, fill=yellow

              noindent
              begintikzpicture
              begingroupedefxendgroup
              noexpandtikzsetNode Options/.style=csuseMy Node Option%
              x

              node [Node Options] at (0,0) Node Text;
              endtikzpicture%

              enddocument


              Note the additional braces around the csuse.






              share|improve this answer
























                up vote
                5
                down vote













                You can use the begingroupedefxendgroup <stuff to expand>x expansion trick:



                documentclassarticle

                usepackagetikz
                usepackageetoolbox

                begindocument

                csdefMy Node Optiondraw=red, thick, fill=yellow

                noindent
                begintikzpicture
                begingroupedefxendgroup
                noexpandtikzsetNode Options/.style=csuseMy Node Option%
                x

                node [Node Options] at (0,0) Node Text;
                endtikzpicture%

                enddocument


                Note the additional braces around the csuse.






                share|improve this answer






















                  up vote
                  5
                  down vote










                  up vote
                  5
                  down vote









                  You can use the begingroupedefxendgroup <stuff to expand>x expansion trick:



                  documentclassarticle

                  usepackagetikz
                  usepackageetoolbox

                  begindocument

                  csdefMy Node Optiondraw=red, thick, fill=yellow

                  noindent
                  begintikzpicture
                  begingroupedefxendgroup
                  noexpandtikzsetNode Options/.style=csuseMy Node Option%
                  x

                  node [Node Options] at (0,0) Node Text;
                  endtikzpicture%

                  enddocument


                  Note the additional braces around the csuse.






                  share|improve this answer












                  You can use the begingroupedefxendgroup <stuff to expand>x expansion trick:



                  documentclassarticle

                  usepackagetikz
                  usepackageetoolbox

                  begindocument

                  csdefMy Node Optiondraw=red, thick, fill=yellow

                  noindent
                  begintikzpicture
                  begingroupedefxendgroup
                  noexpandtikzsetNode Options/.style=csuseMy Node Option%
                  x

                  node [Node Options] at (0,0) Node Text;
                  endtikzpicture%

                  enddocument


                  Note the additional braces around the csuse.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 8 hours ago









                  Werner

                  427k589361610




                  427k589361610



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f457429%2fexpanding-macro-defined-by-csdef-to-define-a-style-via-tikzset%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Comments

                      Popular posts from this blog

                      List of Gilmore Girls characters

                      What does second last employer means? [closed]

                      One-line joke