循环列表并使用其元素作为参数来调用宏

循环列表并使用其元素作为参数来调用宏

我正在尝试自动生成某项活动的参与证书。我尝试使用 LaTeX 迭代形式为 {author, talk} 的对列表,pgffor如下所示。

\documentclass[a4paper]{article}
\usepackage{pgffor}

\def\Talks{
  {John Doe, Very Cool Work on Stuff},
  {Jane Doe, Cooler Work on other Stuff}%
}

\newcommand{\Show}[2]{
\newpage
#1 presented the talk titled #2
}

\begin{document}

\foreach \x in \Talks
{
   % How to send the parameters do \Show?
   \Show{?}{?}
}
\end{document}

我该如何实现这一点?谢谢。

答案1

您的代码几乎无需更改即可运行。使用时首选的分隔符前列腺素是斜线,所以你最好使用

\def\Talks{
      John Doe/Very Cool Work on Stuff,
      Jane Doe/Cooler Work on other Stuff%
 }

一旦你有了这个,你就可以使用

\foreach \author/\talk in \Talks
    {
       % How to send the parameters do \Show?
       \Show{\author}{\talk}
    }

循环讨论以产生:

在此处输入图片描述 在此处输入图片描述

完整代码如下:

\documentclass[a4paper]{article}
\usepackage{pgffor}

\def\Talks{
  John Doe/Very Cool Work on Stuff,
  Jane Doe/Cooler Work on other Stuff%
}

\newcommand{\Show}[2]{
\newpage
#1 presented the talk titled #2
}

\begin{document}

\foreach \author/\talk in \Talks
{
   % How to send the parameters do \Show?
   \Show{\author}{\talk}
}
\end{document}

话虽如此,我可能会使用类似

\newcommand{\ShowTalks}{
    \foreach \author/\talk in \Talks
    {
        \newpage
        \author\space presented the talk titled \talk
    }
}

相关内容