![使用宏提供 pgfkey 参数](https://linux22.com/image/377826/%E4%BD%BF%E7%94%A8%E5%AE%8F%E6%8F%90%E4%BE%9B%20pgfkey%20%E5%8F%82%E6%95%B0.png)
我想提前提供特定宏调用的 pgf 参数。但是我收到错误:
程序包 pgfkeys 错误:我不知道密钥“/test/name=test, active=false”,我将忽略它。也许您拼错了。
以下是一个例子:
\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}
编辑:dexteritas 很快就回答了这个问题,但我希望找到以下问题的解决方案。
这是我希望简化的众多文件之一的示例:
\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}
(从此文件复制的示例:https://github.com/luctius/genesys_dark_sun/blob/master/specialisations/arcana.tex)
我希望我可以创建一个例如,它共同构成、和参数\dedicationArgs
的参数。active
ranked
name
这意味着,理想情况下,我希望避免将文本直接放入现在在完全不同的文件中定义的 pgfparameter 列表中。
答案1
您可以定义您的\args
内部pdfkeys
,myargs/.style={name=test, active=false}
而不是使用宏。
编辑:我添加了一个 pgfstyle specialstyle
,它要求这些命令名称的第一部分作为参数(例如grit
或arcanaCaster
)。我刚刚定义了这些命令,因此示例可以正常工作。它会自动设置name
和active
使用这些命令。
\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}
结果: