[Tex/LaTex] Iterating through comma-separated arguments

comma-separated listmacros

I've looked all over and can't seem to find a succinct answer to this question. Is it possible (and if so, how) to create a command that will iterate through its `arguments' of comma-separated values and act upon them?

Example mostly stolen from "For loop" in newcommand:

\newcommand{\pdfappendix}[1]{
    for \image in #1
    {
       \includegraphics[scale=0.6]{\image.pdf}
    }
}

The goal here is to create a command that can print a file menu structure (or some arbitrary path) like so:

\ppath{Command,TeXing Options,Generate PDF (C-c C-t C-p)}

potentially with an optional argument for a delimiter (defaulting to \to or something)

which would produce

Command -> TeXing Options -> Generate PDF (C-c C-t C-p)

In the words of holy ed, ?

Best Answer

etoolbox's list processing capabilities are straight forward:

enter image description here

\documentclass{article}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\newcommand{\ppath}[2][$\;\triangleright\;$]{%
  \def\nextitem{\def\nextitem{#1}}% Separator
  \renewcommand*{\do}[1]{\nextitem\textsf{##1}}% How to process each item
  \docsvlist{#2}% Process list
}
\begin{document}
A decent file path is \ppath{File,New,Document}.
\end{document}

The separator \nextitem is defined to do nothing during its first use. \do defines how each item is processed, while \docsvlist processes a comma-separated list. See Cunning (La)TeX tricks for a short discussion on the use of \nextitem.