我想创建一个存储数据库的命令。然后我想遍历数据库并打印出将结果添加到文档中。此 MWE 显示了我采取的两种不同方法。但均不起作用。
\documentclass{article}
\usepackage{pgffor,pgfkeys}
\pgfkeys{/ae/breakfast/menu/.cd,
fruit/.initial = grape fruit,
bread/.initial = English muffin,
eggs/.initial = hard boiled,
}
\def\allrecords{%%'
{ fruit=apple,
bread=bagel,
eggs=scrambled
},
{ fruit=orange,
bread=toast,
eggs=fried
}
}
\def\aeget#1{\pgfkeysvalueof{/ae/breakfast/menu/#1}}
\def\whatIordered{ I ordered \aeget{fruit}, \aeget{bread}, and \aeget{eggs}.}
\pagestyle{empty}
\begin{document}
\whatIordered
%<approach 1>% this fails: "whitespace" getting in the way
%%\foreach \x in \allrecords {\pgfkeys{/ae/breakfast/menu/.cd,\x}\whatIordered\newline}
%<approach 2>% this also fails: keys are misread
%%\foreach \x in \allrecords {\foreach \y in \x {\pgfkeys{/ae/breakfast/menu/\y}} \whatIordered\newline}
\end{document}
有没有办法使用pgfkeys
然后迭代通过数据库?
答案1
这只是一个扩展问题。
如果你定义
\pgfkeys{style/.style={#1}}
你可以/style/.expanded=\something
使用\something
来扩展前 pgfkeys
解析它。