是否有一种通用方法可以将<key list>
宏中包含的内容传递给命令\pgfkeys
,以便以通常的方式处理它?在简单的示例中,\expandafter
这很有帮助,但我真的不知道如何在更复杂的情况下进行处理。特别是,如果我想\pgfkeys
显式地传递给某些键并通过宏传递给某些键,我该怎么做?
\documentclass[varwidth,border=1mm]{standalone}
\usepackage{pgf}
\def\x{g/a=1,g/b=2}
\def\y{a=3,b=4}
\pgfkeys{%
/g/.is family, /g,
a/.code={(a is #1)},
b/.code={(b is #1)},
c/.code={(c is #1)}
}
\begin{document}
%\pgfkeys{\x} % CLEARLY FAILING
\expandafter\pgfkeys\expandafter{\x} \\
%\pgfkeys{\x,g/c=7} % CLEARLY FAILING
\expandafter\pgfkeys\expandafter{\x,g/c=7} \\
%\pgfkeys{g,c=5,\y} % CLEARLY FAILING
%\pgfqkeys{/g}{c=5,\y} % CLEARLY FAILING
\pgfkeys{g,c=5,a=3,b=4} \\ % <-- What I'd like to get from
\pgfqkeys{/g}{c=5,a=3,b=4} % <-- the previous two lines
\end{document}
我偶然发现了这一点,并应用了86.6.3 未处理键的处理程序手册的部分pgf
,尝试使用\pgfkeys
保存到宏中的过滤掉的键再次进行处理\remainingoptions
。
答案1
您可以使用以下方式处理宏中的键\pgfkeysalsofrom
:
\documentclass[varwidth,border=1mm]{standalone}
\usepackage{pgf}
\def\x{g/a=1,g/b=2}
\def\y{a=3,b=4}
\pgfkeys{%
/g/.is family, /g,
a/.code={(a is #1)},
b/.code={(b is #1)},
c/.code={(c is #1)}
}
\begin{document}
\pgfkeysalsofrom{\x}
\end{document}
但是您不应该尝试在一个 \pgfkeys 参数中混合宏和普通键。如果您需要这样做,这不是一个好的编程风格。您通常会从某些过滤中获得带有键列表的宏,然后代码应该对处理有足够的控制以避免这种混合。
答案2
像这样吗?
\documentclass[varwidth,border=1mm]{standalone}
\usepackage{pgf}
\def\x{g/a=1,g/b=2}
\def\y{a=3,b=4}
\pgfkeys{%
/g/.is family, /g,
a/.code={(a is #1)},
b/.code={(b is #1)},
c/.code={(c is #1)}
}
\begin{document}
%\pgfkeys{\x} % CLEARLY FAILING
%\expandafter\pgfkeys\expandafter{\x} \\
%\pgfkeys{\x,g/c=7} % CLEARLY FAILING
\edef\temp{\noexpand\pgfkeys\expandafter{\x,g/c=7}}\temp \\
%\pgfkeys{g,c=5,\y} % CLEARLY FAILING
%\pgfqkeys{/g}{c=5,\y} % CLEARLY FAILING
\pgfkeys{g,c=5,a=3,b=4} \\ % <-- What I'd like to get from
\pgfqkeys{/g}{c=5,a=3,b=4} % <-- the previous two lines
\end{document}
或者
\documentclass[varwidth,border=1mm]{standalone}
\usepackage{pgf}
\def\x{g/a=1,g/b=2}
\def\y{a=3,b=4}
\pgfkeys{%
/g/.is family, /g,
a/.code={(a is #1)},
b/.code={(b is #1)},
c/.code={(c is #1)}
}
\begin{document}
%\pgfkeys{\x} % CLEARLY FAILING
%\expandafter\pgfkeys\expandafter{\x} \\
%\pgfkeys{\x,g/c=7} % CLEARLY FAILING
\edef\temp{\noexpand\pgfkeys\expandafter{\x,g/c=7}}\temp \\
\edef\temp{\noexpand\pgfkeys{g,c=5,\y} }\temp
%\pgfqkeys{/g}{c=5,\y} % CLEARLY FAILING
%\pgfkeys{g,c=5,a=3,b=4} \\ % <-- What I'd like to get from
%\pgfqkeys{/g}{c=5,a=3,b=4} % <-- the previous two lines
\end{document}