是否有通用方法將<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-argument 中混合巨集和普通鍵。如果您需要的話,這不是一個好的程式設計風格。通常,您會從某些過濾中獲得帶有鍵列表的宏,然後程式碼應該對處理有足夠的控制以避免這種混合。
答案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}