[pstricks] General question about loops

Toche, Patrick ptoche at cityu.edu.hk
Mon Nov 14 11:39:40 CET 2011


I have a very general question about loops, it's not so much a PSTricks question, but since loops are commonly used by the PSTicks community I figure that this may be the right place to ask. I'm pretty sure some of you write loops like these all the time. If my question is out of place, please forgive me and ignore it.

I want to include a list of figures located in a given directory.

If the figures are named Name1, Name2, etc. the following loop, based on the pgffor package, will work:

%%%%%%%%%%%%%%%%%%
\documentclass{}% article/beamer
\usepackage{graphicx}%
\usepackage{pgffor}%
\begin{document}%
\foreach \index in {1, ..., 2}{%
  \includegraphics[width=\textwidth]{Name\index.ps}\par%
}%
\end{document}
%%%%%%%%%%%%%%%%%%

But if instead the names are in a list, as in,

%%%%%%%%%%%%%%%%%%
\documentclass{}% article/beamer
\usepackage{graphicx}%
\usepackage{pgffor}%
\newcommand*{\List}{%
  OddName.ps,
  FunnyName.ps
}%

\begin{document}%
\foreach \name in \List{%
  \begin{minipage}[b]{\textwidth}%
  \includegraphics[width=\textwidth]{\name}%
  \end{minipage}%
}%
\end{document}
%%%%%%%%%%%%%%%%%%

well it doesn't work. Any ideas of what went wrong in the code above?

I tried with the multido package instead of pgffor, but again failed to make it work. Can multido be tweaked to take a list of names rather than indices?

%%%%%%%%%%%%%%%%%%
\documentclass{}% article/beamer
\usepackage{graphicx}%
\usepackage{multido}%
\newcommand*{\List}{%
  OddName.ps,
  FunnyName.ps
}%

\newcommand{\insertfigure}[1]{%
   \includegraphics[width=\textwidth]{"Name#1"}%
 }%

\begin{document}%

\insertfigure{OddName.ps}%works

\multido{\name=\List}{2}{\insertfigure{\name}}%doesn't work

\end{document}
%%%%%%%%%%%%%%%%%%



More information about the PSTricks mailing list