pgfkeys: .store in constructed macroWhy isn't everything expandable?Appending to a style that sets code with...

How to change checkbox react correctly?

Why hasn't the U.S. government paid war reparations to any country it attacked?

Manually select/unselect lines before forwarding to stdout

Is dividends exclusively a part of earnings?

Do First Order blasters maintain a record of when they were fired?

What made Windows ME so crash-prone?

What's the phrasal verb for carbonated drinks exploding out of the can after being shaken?

Why should I cook the flour first when making bechamel sauce?

MQTT subscription topic match

What's the meaning of こそ in this sentence?

Source of story about the Vilna Gaon and immigration policy

Why do candidates not quit if they no longer have a realistic chance to win in the 2020 US presidents election

What are "full piece" and "half piece" in chess?

I won USD 50K! Now what should I do with it?

Too many spies!

Doing research in academia and not liking competition

A scene of Jimmy diversity

Ethical for a company to ask employees to move furniture on the weekend?

Using two linked programs, output ordinal numbers up to n

What systems of robust steganography are out there?

Can you perfectly wrap a cube with this blocky shape?

In special relativity is mass just a measure of all other energy than kinetic?

Was all the fuel expended in each stage of a Saturn V launch?

Mathematica function equivalent to Matlab's residue function (partial fraction expansion)



pgfkeys: .store in constructed macro


Why isn't everything expandable?Appending to a style that sets code with arguments in pgfkeyspgfkeys: Store unknown keys in a commandProblem with pgf library in TexLiveModify `funcdef` macro to use `pgfkeys` instead of `keyval`Difference between pgfkeys that use .estore and .store for subscriptspgfkeys - why .store and pgfkeysvalueof are different?Store coordinate tuple in pgfkeysStoring options for pgfkeys inside macroUsing macros in pgfkeys command






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







3















I'm trying to store a value in a macro that is constructed from the arguments of another macro, but I must be missing something because the macro is not created.



MWE:



documentclass{article}

RequirePackage{pgfkeys}

newcommandzkeys[1]{pgfkeys{/prefix/.cd,#1}}

newcommandzsetup[2]{
zkeys{
#1/.store in=z#2,
}
}
zsetup{keya}{storagea}
zsetup{keyb}{storageb}

zkeys{
keya=test,
}

begin{document}

zstoragea % Undefined control sequence.

end{document}









share|improve this question





























    3















    I'm trying to store a value in a macro that is constructed from the arguments of another macro, but I must be missing something because the macro is not created.



    MWE:



    documentclass{article}

    RequirePackage{pgfkeys}

    newcommandzkeys[1]{pgfkeys{/prefix/.cd,#1}}

    newcommandzsetup[2]{
    zkeys{
    #1/.store in=z#2,
    }
    }
    zsetup{keya}{storagea}
    zsetup{keyb}{storageb}

    zkeys{
    keya=test,
    }

    begin{document}

    zstoragea % Undefined control sequence.

    end{document}









    share|improve this question

























      3












      3








      3








      I'm trying to store a value in a macro that is constructed from the arguments of another macro, but I must be missing something because the macro is not created.



      MWE:



      documentclass{article}

      RequirePackage{pgfkeys}

      newcommandzkeys[1]{pgfkeys{/prefix/.cd,#1}}

      newcommandzsetup[2]{
      zkeys{
      #1/.store in=z#2,
      }
      }
      zsetup{keya}{storagea}
      zsetup{keyb}{storageb}

      zkeys{
      keya=test,
      }

      begin{document}

      zstoragea % Undefined control sequence.

      end{document}









      share|improve this question














      I'm trying to store a value in a macro that is constructed from the arguments of another macro, but I must be missing something because the macro is not created.



      MWE:



      documentclass{article}

      RequirePackage{pgfkeys}

      newcommandzkeys[1]{pgfkeys{/prefix/.cd,#1}}

      newcommandzsetup[2]{
      zkeys{
      #1/.store in=z#2,
      }
      }
      zsetup{keya}{storagea}
      zsetup{keyb}{storageb}

      zkeys{
      keya=test,
      }

      begin{document}

      zstoragea % Undefined control sequence.

      end{document}






      expansion pgfkeys






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 8 hours ago









      meidemeide

      4302 silver badges9 bronze badges




      4302 silver badges9 bronze badges






















          2 Answers
          2






          active

          oldest

          votes


















          4














          New solution



          Another, more flexible approach is to extend the handlers pgfkeys accepts by a new one .store in cs which does basically the same as .store in, but doesn't take a complete control sequence name as value but a list of characters from that the final control sequence is built. So the following calls would be equal:



          foo/.store in=mymacro
          foo/.store in cs=mymacro


          The full example then looks like



          documentclass{article}
          RequirePackage{pgfkeys}

          newcommandzkeys[1]{pgfkeys{/prefix/.cd,#1}}

          pgfkeys{/handlers/.store in cs/.code=pgfkeysalso{%
          pgfkeyscurrentpath/.code=expandafterdefcsname#1endcsname{##1}}%
          }

          newcommandzsetup[2]{%
          zkeys{
          #1/.store in cs=z#2,
          }%
          }
          zsetup{keya}{storagea}
          zsetup{keyb}{storageb}

          zkeys{
          keya=test,
          }

          begin{document}

          zstoragea % Undefined control sequence.

          end{document}




          Old solution



          When you type z#2, TeX parses this as the command name z followed by the tokens inserted from the second argument. If you want to build a new control sequence from a series of characters/tokens, you have to use the sequence csname ...endcsname, where ... would be z#2 in this case.



          However, in this specific situation store in=csname z#2endcsname wouldn't work, because the csname call must be expanded exactly once to build the actual new control sequence from the characters, but not more than once, otherwise the built macro would be tried to expanded itself.



          A possible solution is to wrap the whole key definitions into an edef, prefix all commands in it by noexpand, and use unexpandedexpandafter{...} in each place, we want exactly one expansion step:



          newcommandzsetup[2]{
          edeftemp{%
          noexpandzkeys{
          #1/.store in=unexpandedexpandafter{csname z#2endcsname},
          }%
          }temp
          }


          zstoragea will then expand to test.






          share|improve this answer

































            2














            Here are two solutions. They both take care not to expand the first argument of zsetup before passing it to zkeys, nor to define or overwrite any macro in the current group as a side effect.



            First solution



            documentclass{article}
            usepackage{pgfkeys}

            newcommand{zkeys}[1]{pgfkeys{/prefix/.cd,#1}}

            newcommand*{zsetup}[2]{%
            begingroup
            edefarg{unexpanded{#1/.store in=}%
            expandafternoexpandcsname z#2endcsname}%
            expandafter
            endgroup
            expandafterzkeysexpandafter{arg}%
            }

            zsetup{keya}{storagea}
            zsetup{keyb}{storageb}

            zkeys{
            keya=test,
            }

            begin{document}

            zstoragea % Print 'test'

            end{document}


            Second solution



            Same code, except for the definition of zsetup:



            newcommand*{zsetup}[2]{%
            begingroup
            deftmp##1{zkeys{#1/.store in=##1}}%
            expandafterexpandafterexpandafter
            endgroup
            expandaftertmpcsname z#2endcsname
            }





            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%2f500098%2fpgfkeys-store-in-constructed-macro%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              4














              New solution



              Another, more flexible approach is to extend the handlers pgfkeys accepts by a new one .store in cs which does basically the same as .store in, but doesn't take a complete control sequence name as value but a list of characters from that the final control sequence is built. So the following calls would be equal:



              foo/.store in=mymacro
              foo/.store in cs=mymacro


              The full example then looks like



              documentclass{article}
              RequirePackage{pgfkeys}

              newcommandzkeys[1]{pgfkeys{/prefix/.cd,#1}}

              pgfkeys{/handlers/.store in cs/.code=pgfkeysalso{%
              pgfkeyscurrentpath/.code=expandafterdefcsname#1endcsname{##1}}%
              }

              newcommandzsetup[2]{%
              zkeys{
              #1/.store in cs=z#2,
              }%
              }
              zsetup{keya}{storagea}
              zsetup{keyb}{storageb}

              zkeys{
              keya=test,
              }

              begin{document}

              zstoragea % Undefined control sequence.

              end{document}




              Old solution



              When you type z#2, TeX parses this as the command name z followed by the tokens inserted from the second argument. If you want to build a new control sequence from a series of characters/tokens, you have to use the sequence csname ...endcsname, where ... would be z#2 in this case.



              However, in this specific situation store in=csname z#2endcsname wouldn't work, because the csname call must be expanded exactly once to build the actual new control sequence from the characters, but not more than once, otherwise the built macro would be tried to expanded itself.



              A possible solution is to wrap the whole key definitions into an edef, prefix all commands in it by noexpand, and use unexpandedexpandafter{...} in each place, we want exactly one expansion step:



              newcommandzsetup[2]{
              edeftemp{%
              noexpandzkeys{
              #1/.store in=unexpandedexpandafter{csname z#2endcsname},
              }%
              }temp
              }


              zstoragea will then expand to test.






              share|improve this answer






























                4














                New solution



                Another, more flexible approach is to extend the handlers pgfkeys accepts by a new one .store in cs which does basically the same as .store in, but doesn't take a complete control sequence name as value but a list of characters from that the final control sequence is built. So the following calls would be equal:



                foo/.store in=mymacro
                foo/.store in cs=mymacro


                The full example then looks like



                documentclass{article}
                RequirePackage{pgfkeys}

                newcommandzkeys[1]{pgfkeys{/prefix/.cd,#1}}

                pgfkeys{/handlers/.store in cs/.code=pgfkeysalso{%
                pgfkeyscurrentpath/.code=expandafterdefcsname#1endcsname{##1}}%
                }

                newcommandzsetup[2]{%
                zkeys{
                #1/.store in cs=z#2,
                }%
                }
                zsetup{keya}{storagea}
                zsetup{keyb}{storageb}

                zkeys{
                keya=test,
                }

                begin{document}

                zstoragea % Undefined control sequence.

                end{document}




                Old solution



                When you type z#2, TeX parses this as the command name z followed by the tokens inserted from the second argument. If you want to build a new control sequence from a series of characters/tokens, you have to use the sequence csname ...endcsname, where ... would be z#2 in this case.



                However, in this specific situation store in=csname z#2endcsname wouldn't work, because the csname call must be expanded exactly once to build the actual new control sequence from the characters, but not more than once, otherwise the built macro would be tried to expanded itself.



                A possible solution is to wrap the whole key definitions into an edef, prefix all commands in it by noexpand, and use unexpandedexpandafter{...} in each place, we want exactly one expansion step:



                newcommandzsetup[2]{
                edeftemp{%
                noexpandzkeys{
                #1/.store in=unexpandedexpandafter{csname z#2endcsname},
                }%
                }temp
                }


                zstoragea will then expand to test.






                share|improve this answer




























                  4












                  4








                  4







                  New solution



                  Another, more flexible approach is to extend the handlers pgfkeys accepts by a new one .store in cs which does basically the same as .store in, but doesn't take a complete control sequence name as value but a list of characters from that the final control sequence is built. So the following calls would be equal:



                  foo/.store in=mymacro
                  foo/.store in cs=mymacro


                  The full example then looks like



                  documentclass{article}
                  RequirePackage{pgfkeys}

                  newcommandzkeys[1]{pgfkeys{/prefix/.cd,#1}}

                  pgfkeys{/handlers/.store in cs/.code=pgfkeysalso{%
                  pgfkeyscurrentpath/.code=expandafterdefcsname#1endcsname{##1}}%
                  }

                  newcommandzsetup[2]{%
                  zkeys{
                  #1/.store in cs=z#2,
                  }%
                  }
                  zsetup{keya}{storagea}
                  zsetup{keyb}{storageb}

                  zkeys{
                  keya=test,
                  }

                  begin{document}

                  zstoragea % Undefined control sequence.

                  end{document}




                  Old solution



                  When you type z#2, TeX parses this as the command name z followed by the tokens inserted from the second argument. If you want to build a new control sequence from a series of characters/tokens, you have to use the sequence csname ...endcsname, where ... would be z#2 in this case.



                  However, in this specific situation store in=csname z#2endcsname wouldn't work, because the csname call must be expanded exactly once to build the actual new control sequence from the characters, but not more than once, otherwise the built macro would be tried to expanded itself.



                  A possible solution is to wrap the whole key definitions into an edef, prefix all commands in it by noexpand, and use unexpandedexpandafter{...} in each place, we want exactly one expansion step:



                  newcommandzsetup[2]{
                  edeftemp{%
                  noexpandzkeys{
                  #1/.store in=unexpandedexpandafter{csname z#2endcsname},
                  }%
                  }temp
                  }


                  zstoragea will then expand to test.






                  share|improve this answer















                  New solution



                  Another, more flexible approach is to extend the handlers pgfkeys accepts by a new one .store in cs which does basically the same as .store in, but doesn't take a complete control sequence name as value but a list of characters from that the final control sequence is built. So the following calls would be equal:



                  foo/.store in=mymacro
                  foo/.store in cs=mymacro


                  The full example then looks like



                  documentclass{article}
                  RequirePackage{pgfkeys}

                  newcommandzkeys[1]{pgfkeys{/prefix/.cd,#1}}

                  pgfkeys{/handlers/.store in cs/.code=pgfkeysalso{%
                  pgfkeyscurrentpath/.code=expandafterdefcsname#1endcsname{##1}}%
                  }

                  newcommandzsetup[2]{%
                  zkeys{
                  #1/.store in cs=z#2,
                  }%
                  }
                  zsetup{keya}{storagea}
                  zsetup{keyb}{storageb}

                  zkeys{
                  keya=test,
                  }

                  begin{document}

                  zstoragea % Undefined control sequence.

                  end{document}




                  Old solution



                  When you type z#2, TeX parses this as the command name z followed by the tokens inserted from the second argument. If you want to build a new control sequence from a series of characters/tokens, you have to use the sequence csname ...endcsname, where ... would be z#2 in this case.



                  However, in this specific situation store in=csname z#2endcsname wouldn't work, because the csname call must be expanded exactly once to build the actual new control sequence from the characters, but not more than once, otherwise the built macro would be tried to expanded itself.



                  A possible solution is to wrap the whole key definitions into an edef, prefix all commands in it by noexpand, and use unexpandedexpandafter{...} in each place, we want exactly one expansion step:



                  newcommandzsetup[2]{
                  edeftemp{%
                  noexpandzkeys{
                  #1/.store in=unexpandedexpandafter{csname z#2endcsname},
                  }%
                  }temp
                  }


                  zstoragea will then expand to test.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 6 hours ago

























                  answered 7 hours ago









                  siracusasiracusa

                  7,0171 gold badge18 silver badges33 bronze badges




                  7,0171 gold badge18 silver badges33 bronze badges

























                      2














                      Here are two solutions. They both take care not to expand the first argument of zsetup before passing it to zkeys, nor to define or overwrite any macro in the current group as a side effect.



                      First solution



                      documentclass{article}
                      usepackage{pgfkeys}

                      newcommand{zkeys}[1]{pgfkeys{/prefix/.cd,#1}}

                      newcommand*{zsetup}[2]{%
                      begingroup
                      edefarg{unexpanded{#1/.store in=}%
                      expandafternoexpandcsname z#2endcsname}%
                      expandafter
                      endgroup
                      expandafterzkeysexpandafter{arg}%
                      }

                      zsetup{keya}{storagea}
                      zsetup{keyb}{storageb}

                      zkeys{
                      keya=test,
                      }

                      begin{document}

                      zstoragea % Print 'test'

                      end{document}


                      Second solution



                      Same code, except for the definition of zsetup:



                      newcommand*{zsetup}[2]{%
                      begingroup
                      deftmp##1{zkeys{#1/.store in=##1}}%
                      expandafterexpandafterexpandafter
                      endgroup
                      expandaftertmpcsname z#2endcsname
                      }





                      share|improve this answer






























                        2














                        Here are two solutions. They both take care not to expand the first argument of zsetup before passing it to zkeys, nor to define or overwrite any macro in the current group as a side effect.



                        First solution



                        documentclass{article}
                        usepackage{pgfkeys}

                        newcommand{zkeys}[1]{pgfkeys{/prefix/.cd,#1}}

                        newcommand*{zsetup}[2]{%
                        begingroup
                        edefarg{unexpanded{#1/.store in=}%
                        expandafternoexpandcsname z#2endcsname}%
                        expandafter
                        endgroup
                        expandafterzkeysexpandafter{arg}%
                        }

                        zsetup{keya}{storagea}
                        zsetup{keyb}{storageb}

                        zkeys{
                        keya=test,
                        }

                        begin{document}

                        zstoragea % Print 'test'

                        end{document}


                        Second solution



                        Same code, except for the definition of zsetup:



                        newcommand*{zsetup}[2]{%
                        begingroup
                        deftmp##1{zkeys{#1/.store in=##1}}%
                        expandafterexpandafterexpandafter
                        endgroup
                        expandaftertmpcsname z#2endcsname
                        }





                        share|improve this answer




























                          2












                          2








                          2







                          Here are two solutions. They both take care not to expand the first argument of zsetup before passing it to zkeys, nor to define or overwrite any macro in the current group as a side effect.



                          First solution



                          documentclass{article}
                          usepackage{pgfkeys}

                          newcommand{zkeys}[1]{pgfkeys{/prefix/.cd,#1}}

                          newcommand*{zsetup}[2]{%
                          begingroup
                          edefarg{unexpanded{#1/.store in=}%
                          expandafternoexpandcsname z#2endcsname}%
                          expandafter
                          endgroup
                          expandafterzkeysexpandafter{arg}%
                          }

                          zsetup{keya}{storagea}
                          zsetup{keyb}{storageb}

                          zkeys{
                          keya=test,
                          }

                          begin{document}

                          zstoragea % Print 'test'

                          end{document}


                          Second solution



                          Same code, except for the definition of zsetup:



                          newcommand*{zsetup}[2]{%
                          begingroup
                          deftmp##1{zkeys{#1/.store in=##1}}%
                          expandafterexpandafterexpandafter
                          endgroup
                          expandaftertmpcsname z#2endcsname
                          }





                          share|improve this answer















                          Here are two solutions. They both take care not to expand the first argument of zsetup before passing it to zkeys, nor to define or overwrite any macro in the current group as a side effect.



                          First solution



                          documentclass{article}
                          usepackage{pgfkeys}

                          newcommand{zkeys}[1]{pgfkeys{/prefix/.cd,#1}}

                          newcommand*{zsetup}[2]{%
                          begingroup
                          edefarg{unexpanded{#1/.store in=}%
                          expandafternoexpandcsname z#2endcsname}%
                          expandafter
                          endgroup
                          expandafterzkeysexpandafter{arg}%
                          }

                          zsetup{keya}{storagea}
                          zsetup{keyb}{storageb}

                          zkeys{
                          keya=test,
                          }

                          begin{document}

                          zstoragea % Print 'test'

                          end{document}


                          Second solution



                          Same code, except for the definition of zsetup:



                          newcommand*{zsetup}[2]{%
                          begingroup
                          deftmp##1{zkeys{#1/.store in=##1}}%
                          expandafterexpandafterexpandafter
                          endgroup
                          expandaftertmpcsname z#2endcsname
                          }






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited 6 hours ago

























                          answered 6 hours ago









                          frougonfrougon

                          4,9071 gold badge10 silver badges20 bronze badges




                          4,9071 gold badge10 silver badges20 bronze badges






























                              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.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f500098%2fpgfkeys-store-in-constructed-macro%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

                              Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

                              Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

                              Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...