4

I would like to supply the pgf argument of a particular macro call in advance. However I get the error:

Package pgfkeys Error: I do not know the key '/test/name=test, active=false' and I am going to ignore it. Perhaps you misspelled it.

Here is an example:

\documentclass{report}
\usepackage{pgfkeys}

\newcommand{\args}{name=test, active=false}

\pgfkeys{
    /test/.is family, /test,
    % Here are the options that a user can pass
    default/.style = {
        name = Unnamed,
        active = false,
    },
    name/.estore in = \testName,
    active/.estore in = \testActive,
}

\newcommand\test[2][]{
    \pgfkeys{/test, default, #1}
    \noindent%
    name: \testName \\
    active: \testActive \\
    text: #2 \\
}

\begin{document}
    % This works as normal
    \test[name=test, active=false]{ipsum}

    %This gives the following error:
    %Package pgfkeys Error: I do not know the key '/test/name=test, active=false' and I am going to ignore it. Perhaps you misspelled it.
    \test[\args]{ipsum}
\end{document}

Edit: dexteritas answered the question as stated very quickly, but I was hoping to find a solution for the following problem.

This is a sample of one of many files which I am hoping to simplify:

\begin{tikzpicture}
        \draw ( 0,  0) node[anchor=north east](aa){\TalentBox[tier=5,  width=14em, active=\gritActive,            ranked=\gritRanked,            name=\gritTitle]            {\gritDescription}}
              ( 6,  0) node[anchor=north east](ab){\TalentBox[tier=5,  width=14em, active=\arcanaCasterActive,    ranked=\arcanaCasterRanked,    name=\arcanaCasterTitle]    {\arcanaCasterDescription}}
              (12,  0) node[anchor=north east](ac){\TalentBox[tier=5,  width=14em, active=\gritActive,            ranked=\gritRanked,            name=\gritTitle]            {\gritDescription}}
              ( 0, -5) node[anchor=north east](ba){\TalentBox[tier=10, width=14em, active=\gentlePreserverActive, ranked=\gentlePreserverRanked, name=\gentlePreserverTitle] {\gentlePreserverDescription}}
              ( 6, -5) node[anchor=north east](bb){\TalentBox[tier=10, width=14em, active=\disguiseCastingActive, ranked=\disguiseCastingRanked, name=\disguiseCastingTitle] {\disguiseCastingDescription}}
              (12, -5) node[anchor=north east](bc){\TalentBox[tier=10, width=14em, active=\potentDefilerActive,   ranked=\potentDefilerRanked,   name=\potentDefilerTitle]   {\potentDefilerDescription}}
              ( 0,-10) node[anchor=north east](ca){\TalentBox[tier=15, width=14em, active=\gentlePreserverActive, ranked=\gentlePreserverRanked, name=\gentlePreserverTitle] {\gentlePreserverDescription}}
              ( 6,-10) node[anchor=north east](cb){\TalentBox[tier=15, width=14em, active=\signatureSpellActive,  ranked=\signatureSpellRanked,  name=\signatureSpellTitle]  {\signatureSpellDescription}}
              (12,-10) node[anchor=north east](cc){\TalentBox[tier=15, width=14em, active=\potentDefilerActive,   ranked=\potentDefilerRanked,   name=\potentDefilerTitle]   {\potentDefilerDescription}}
              ( 0,-15) node[anchor=north east](da){\TalentBox[tier=20, width=14em, active=\lingeringSpellActive,  ranked=\lingeringSpellRanked,  name=\lingeringSpellTitle]  {\lingeringSpellDescription}}
              ( 6,-15) node[anchor=north east](db){\TalentBox[tier=20, width=14em, active=\distantSpellActive,    ranked=\distantSpellRanked,    name=\distantSpellTitle]    {\disguiseCastingDescription}}
              (12,-15) node[anchor=north east](dc){\TalentBox[tier=20, width=14em, active=\shapeSpellActive,      ranked=\shapeSpellRanked,      name=\shapeSpellTitle]      {\shapeSpellDescription}}
              ( 0,-20) node[anchor=north east](ea){\TalentBox[tier=25, width=14em, active=\quickenSpellActive,    ranked=\quickenSpellRanked,    name=\quickenSpellTitle]    {\quickenSpellDescription}}
              ( 6,-20) node[anchor=north east](eb){\TalentBox[tier=25, width=14em, active=\dedicationActive,      ranked=\dedicationRanked,      name=\dedicationTitle]      {\dedicationDescription}}
              (12,-20) node[anchor=north east](ec){\TalentBox[tier=25, width=14em, active=\signatureSpellActive,  ranked=\signatureSpellRanked,  name=\signatureSpellTitle]  {\signatureSpellDescription}}
\end{tikzpicture}

(sample copied from this file: https://github.com/luctius/genesys_dark_sun/blob/master/specialisations/arcana.tex)

I am hoping that I can create for example an \dedicationArgs which together form the arguments for what are the active, ranked and name parameters.

This means that, ideally I would like to avoid putting text directly into the pgfparameter list which are now defined in completely different files.

5

You could define your \args inside pdfkeys with myargs/.style={name=test, active=false} instead of using a macro for that.

Edit: I added a pgfstyle specialstyle witch expects the first part of the name of these commands as parameter (e.g. grit or arcanaCaster). I just defined these commands, so the example works. It automatically sets name and active using the commands.

\documentclass{report}
\usepackage{pgfkeys}

\newcommand{\gritTitle}{Grit}
\newcommand{\gritActive}{true}
\newcommand{\arcanaCasterTitle}{Arcana Caster}
\newcommand{\arcanaCasterActive}{false}

\pgfkeys{
    /test/.is family, /test,
    % Here are the options that a user can pass
    default/.style = {
        name = Unnamed,
        active = false,
    },
    name/.estore in = \testName,
    active/.estore in = \testActive,
    myargs/.style={name=test, active=false},
    specialstyle/.style={
        name=\csname #1Title\endcsname,
        active=\csname #1Active\endcsname
    }
}

\newcommand\test[2][]{
    \pgfkeys{/test, default, #1}
    \noindent%
    name: \testName \\
    active: \testActive \\
    text: #2 \\
}

\begin{document}
    \test[name=test, active=false]{ipsum}

    \test[myargs]{ipsum}

    \test[specialstyle=grit]{ipsum}

    \test[specialstyle=arcanaCaster]{ipsum}
\end{document}

Result:

enter image description here

  • Thank you for your quick solution. I'm not going to accept it just yet, because the ultimate problem is a bit more difficult. I will update my question. – luctius Jun 14 '18 at 9:25
  • This is Perfect! – luctius Jun 14 '18 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.