# From a list of words to listed words

I would like to go from a list of words through a dedicated command, for instance \listofwords{one word;one longer word;word and word} to the expanded list of the same words, ie:

\begin{list}{}
\item one word
\item one longer word
\item word and word
\end{list}


and the initial list could store more (or less) semicolon-separated words.

Edit The following may be more challenging: how to go from two different lists, \listofwords{word;wordd;worddd} and \listofterms{term;termm;termmm} to

\begin{list}{}{}
\item word term
\item wordd termm
\item worddd termmm
\end{list}


where worddd (or any other of the lists above) could store several space-separated words. Based on the previous answers, I had a look at the xparse and etoolbox packages but could no find any useful solution :(

-
Does it have to use semicolon as the delimiter, or would commas work as well? –  Jake Sep 6 '12 at 21:14
semicolon are preferred because commas could be part of the words. Is this a problem? –  pluton Sep 6 '12 at 21:20
@pluton and semicolons can't be part of the words? –  Gonzalo Medina Sep 6 '12 at 21:22
well, no they are not supposed to but \listofwords{one word}{one longer word}{word and word} would be acceptable as well. –  pluton Sep 6 '12 at 21:24

etoolbox provides list processing capabilities to suit this requirement:

\documentclass{article}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter
\newcommand{\listofwords}[1]{%
\renewcommand{\do}[1]{\item ##1}% Update how the list items will be processed
\begin{list}{}{}%
\@listofwords{#1}% Process items
\end{list}%
}
\DeclareListParser{\@listofwords}{;}% \@listofwords{<word>;<word>;...}
\makeatother
\begin{document}
\listofwords{one word;one longer word;word and word}

\begin{list}{}{}
\item one word
\item one longer word
\item word and word
\end{list}
\end{document}​


\DeclareListParser{\@listofwords}{;} creates a list parser \@listofwords that processes its separated by ;.

-

This is easy with xparse:

\documentclass{article}
\usepackage{xparse}
\NewDocumentCommand{\listofwords}{>{\SplitList{;}}m}
{\begin{list}{}{}
\end{list}}

\begin{document}
\listofwords{one word;one longer word;word and word}

\begin{list}{}{}
\item one word
\item one longer word
\item word and word
\end{list}
\end{document}


The list environment is just to show that the output is identical. (Note that list takes two arguments.)

-
I am giving points to Werner so that you are not too far ahead :) –  pluton Sep 7 '12 at 7:59