Setting label in newcommand via a pgfkey












0















I'm attempting to set a label in a macro(?) I created with a new command. I'm passing several values to the command in the first argument via pgfkeys, but the label macro is just using the literal string I've put in to expand the pgfkey instead of the actual expanded value.



I've tried both of the solutions presented in these answers, together and separately, but not luck.



https://tex.stackexchange.com/a/308164



https://tex.stackexchange.com/a/125099



I've an inkling that what's happening is related to the timing of the expansion for the pgfkey value, but I'll be honest I don't have a firm understanding of how the underlying tex engine does it's magic. I'm also just learning pgfkeys so my understanding of what's happening there is still at a beginner level.



Here's my mwe of what I'm trying to do:



documentclass[twocolumn]{book}

usepackage[framemethod=TikZ]{mdframed}%boxes
usepackage{pgfkeys}

newcounter{myCounter}

newmdenv[%
frametitlebackgroundcolor=blue,
frametitlefontcolor=white,
backgroundcolor=blue!25,
linecolor=blue,
outerlinewidth=1pt,
roundcorner=1mm,
skipabove=baselineskip,
skipbelow=baselineskip,
font=small,
nobreak=true,
settings={globalrefstepcounter{myCounter}},
]{myTextBox}


%Define Macros
makeatletter

pgfkeys{/mykeys/textbox/.cd,
title/.initial=,
body/.initial=,
label/.initial=,
}

defmykeys@set@textbox@keys#1{%%
pgfkeys{/mykeys/textbox/.cd,#1}}
defmykeys@get@textbox#1{%%
pgfkeysvalueof{/mykeys/textbox/#1}}

newcommandmyBox[1]{%%
bgroup
mykeys@set@textbox@keys{#1}%%
begin{myTextBox}[frametitle=textbf{mykeys@get@textbox{title}hfill NOTE}]
mykeys@get@textbox{body}
label{box:mykeys@get@textbox{label}}
end{myTextBox}
egroup
}

makeatother

begin{document}
section{A Section}
myBox{
title=Box Title,
body=A not so long string of text to go in the box,
label=firstbox
}
ref{firstbox}

end{document}


Here's my current result:



current result



I'm not tied to a particular solution (I would prefer a solution that works with pgfkeys) as long as I can get labels and references working properly.









share



























    0















    I'm attempting to set a label in a macro(?) I created with a new command. I'm passing several values to the command in the first argument via pgfkeys, but the label macro is just using the literal string I've put in to expand the pgfkey instead of the actual expanded value.



    I've tried both of the solutions presented in these answers, together and separately, but not luck.



    https://tex.stackexchange.com/a/308164



    https://tex.stackexchange.com/a/125099



    I've an inkling that what's happening is related to the timing of the expansion for the pgfkey value, but I'll be honest I don't have a firm understanding of how the underlying tex engine does it's magic. I'm also just learning pgfkeys so my understanding of what's happening there is still at a beginner level.



    Here's my mwe of what I'm trying to do:



    documentclass[twocolumn]{book}

    usepackage[framemethod=TikZ]{mdframed}%boxes
    usepackage{pgfkeys}

    newcounter{myCounter}

    newmdenv[%
    frametitlebackgroundcolor=blue,
    frametitlefontcolor=white,
    backgroundcolor=blue!25,
    linecolor=blue,
    outerlinewidth=1pt,
    roundcorner=1mm,
    skipabove=baselineskip,
    skipbelow=baselineskip,
    font=small,
    nobreak=true,
    settings={globalrefstepcounter{myCounter}},
    ]{myTextBox}


    %Define Macros
    makeatletter

    pgfkeys{/mykeys/textbox/.cd,
    title/.initial=,
    body/.initial=,
    label/.initial=,
    }

    defmykeys@set@textbox@keys#1{%%
    pgfkeys{/mykeys/textbox/.cd,#1}}
    defmykeys@get@textbox#1{%%
    pgfkeysvalueof{/mykeys/textbox/#1}}

    newcommandmyBox[1]{%%
    bgroup
    mykeys@set@textbox@keys{#1}%%
    begin{myTextBox}[frametitle=textbf{mykeys@get@textbox{title}hfill NOTE}]
    mykeys@get@textbox{body}
    label{box:mykeys@get@textbox{label}}
    end{myTextBox}
    egroup
    }

    makeatother

    begin{document}
    section{A Section}
    myBox{
    title=Box Title,
    body=A not so long string of text to go in the box,
    label=firstbox
    }
    ref{firstbox}

    end{document}


    Here's my current result:



    current result



    I'm not tied to a particular solution (I would prefer a solution that works with pgfkeys) as long as I can get labels and references working properly.









    share

























      0












      0








      0








      I'm attempting to set a label in a macro(?) I created with a new command. I'm passing several values to the command in the first argument via pgfkeys, but the label macro is just using the literal string I've put in to expand the pgfkey instead of the actual expanded value.



      I've tried both of the solutions presented in these answers, together and separately, but not luck.



      https://tex.stackexchange.com/a/308164



      https://tex.stackexchange.com/a/125099



      I've an inkling that what's happening is related to the timing of the expansion for the pgfkey value, but I'll be honest I don't have a firm understanding of how the underlying tex engine does it's magic. I'm also just learning pgfkeys so my understanding of what's happening there is still at a beginner level.



      Here's my mwe of what I'm trying to do:



      documentclass[twocolumn]{book}

      usepackage[framemethod=TikZ]{mdframed}%boxes
      usepackage{pgfkeys}

      newcounter{myCounter}

      newmdenv[%
      frametitlebackgroundcolor=blue,
      frametitlefontcolor=white,
      backgroundcolor=blue!25,
      linecolor=blue,
      outerlinewidth=1pt,
      roundcorner=1mm,
      skipabove=baselineskip,
      skipbelow=baselineskip,
      font=small,
      nobreak=true,
      settings={globalrefstepcounter{myCounter}},
      ]{myTextBox}


      %Define Macros
      makeatletter

      pgfkeys{/mykeys/textbox/.cd,
      title/.initial=,
      body/.initial=,
      label/.initial=,
      }

      defmykeys@set@textbox@keys#1{%%
      pgfkeys{/mykeys/textbox/.cd,#1}}
      defmykeys@get@textbox#1{%%
      pgfkeysvalueof{/mykeys/textbox/#1}}

      newcommandmyBox[1]{%%
      bgroup
      mykeys@set@textbox@keys{#1}%%
      begin{myTextBox}[frametitle=textbf{mykeys@get@textbox{title}hfill NOTE}]
      mykeys@get@textbox{body}
      label{box:mykeys@get@textbox{label}}
      end{myTextBox}
      egroup
      }

      makeatother

      begin{document}
      section{A Section}
      myBox{
      title=Box Title,
      body=A not so long string of text to go in the box,
      label=firstbox
      }
      ref{firstbox}

      end{document}


      Here's my current result:



      current result



      I'm not tied to a particular solution (I would prefer a solution that works with pgfkeys) as long as I can get labels and references working properly.









      share














      I'm attempting to set a label in a macro(?) I created with a new command. I'm passing several values to the command in the first argument via pgfkeys, but the label macro is just using the literal string I've put in to expand the pgfkey instead of the actual expanded value.



      I've tried both of the solutions presented in these answers, together and separately, but not luck.



      https://tex.stackexchange.com/a/308164



      https://tex.stackexchange.com/a/125099



      I've an inkling that what's happening is related to the timing of the expansion for the pgfkey value, but I'll be honest I don't have a firm understanding of how the underlying tex engine does it's magic. I'm also just learning pgfkeys so my understanding of what's happening there is still at a beginner level.



      Here's my mwe of what I'm trying to do:



      documentclass[twocolumn]{book}

      usepackage[framemethod=TikZ]{mdframed}%boxes
      usepackage{pgfkeys}

      newcounter{myCounter}

      newmdenv[%
      frametitlebackgroundcolor=blue,
      frametitlefontcolor=white,
      backgroundcolor=blue!25,
      linecolor=blue,
      outerlinewidth=1pt,
      roundcorner=1mm,
      skipabove=baselineskip,
      skipbelow=baselineskip,
      font=small,
      nobreak=true,
      settings={globalrefstepcounter{myCounter}},
      ]{myTextBox}


      %Define Macros
      makeatletter

      pgfkeys{/mykeys/textbox/.cd,
      title/.initial=,
      body/.initial=,
      label/.initial=,
      }

      defmykeys@set@textbox@keys#1{%%
      pgfkeys{/mykeys/textbox/.cd,#1}}
      defmykeys@get@textbox#1{%%
      pgfkeysvalueof{/mykeys/textbox/#1}}

      newcommandmyBox[1]{%%
      bgroup
      mykeys@set@textbox@keys{#1}%%
      begin{myTextBox}[frametitle=textbf{mykeys@get@textbox{title}hfill NOTE}]
      mykeys@get@textbox{body}
      label{box:mykeys@get@textbox{label}}
      end{myTextBox}
      egroup
      }

      makeatother

      begin{document}
      section{A Section}
      myBox{
      title=Box Title,
      body=A not so long string of text to go in the box,
      label=firstbox
      }
      ref{firstbox}

      end{document}


      Here's my current result:



      current result



      I'm not tied to a particular solution (I would prefer a solution that works with pgfkeys) as long as I can get labels and references working properly.







      tikz-pgf cross-referencing





      share












      share










      share



      share










      asked 7 mins ago









      TuffwerTuffwer

      1507




      1507






















          0






          active

          oldest

          votes











          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%2f479387%2fsetting-label-in-newcommand-via-a-pgfkey%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          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%2f479387%2fsetting-label-in-newcommand-via-a-pgfkey%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

          Entries order in /etc/network/interfaces

          新発田市

          Grub takes very long (several minutes) to open Menu (in Multi-Boot-System)