0

This is what I want to do:

\newcommand{\foobar}[n]{%
  \hspace*{1.5ex}-\hspace{1ex}\emph{#n}\\%
}

And then use it like this:

\foobar
  {Hello}
  {World}

However this doesnt actually work. I want

\hspace*{1.5ex}-\hspace{1ex}\emph{#n}\\%

To appear for as many arguments as I supply to \foobar. How do I do this?

NOTE

To clarify, what I want finally is this:

- Hello
- World
- N number of other arguments
  • 1
    Please, make clearer what you want; in any case you can't specify an arbitrary number of arguments. Usually one solves it by giving as single argument a comma separated list. – egreg Sep 02 '15 at 17:05
  • How do I split by comma given a list? – dopatraman Sep 02 '15 at 17:06
  • 1
    Choose a duplicate by looking at http://tex.stackexchange.com/search?q=variable+number+arguments – egreg Sep 02 '15 at 17:09
  • How your theoretical \foobar macro recognizes that {World} (in your example) is the last parameter? I. e. that n=2. Is there a symbol or mark for that? – wipet Sep 02 '15 at 17:21
  • No. I assumed LaTeX had some sort of iterator for rendering an arbitrary number of arguments. I guess this isnt the case? – dopatraman Sep 02 '15 at 17:26
  • 1
    a macro argument only needs to be surrounded by braces if it is more than one tokens so \foobar abc is typically legal with a b and c being #1, #2, #3. You need some kind of terminator but as others have said the latex syntax here should be \foobar{a,b,c,d,e} – David Carlisle Sep 02 '15 at 17:29
  • 1
    Any automaton (LaTeX or another) must know which argument is the last one. How to recognize the last argument or the number of arguments? Human must say something about it. – wipet Sep 02 '15 at 17:29
  • 2

1 Answers1

1

This is the 'traditional' comma-separated-value approach, using etoolbox and storing the csv-arguments to a list and displaying it. The \showme command is just an example what to do with the individual values.

Improved solutions are based on a precise definition of the question.

But as stated already in the comments: There must be some information which is the last argument, an arbitrary number isn't possible this way.

\documentclass{article}

\usepackage{etoolbox}

\newcommand{\showme}[1]{%
#1

}

\newcommand{\mycmd}[1]{%
\def\templist{}
\forcsvlist{\listadd\templist}{#1}
\forlistloop{\showme}{\templist}
}


\begin{document}

\mycmd{a,b,c,d,e,f,some longer text}

\end{document}

enter image description here