TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

It's late, so I may not be thinking about this clearly enough, but I could have sworn that there exists a macro (possibly not part of a package, but just something that I picked up somewhere along the way) that is able to take some sort of inline list separated by a certain character and replace that character with another string. For example, something like


would produce something like

apples $\cdot$ oranges $\cdot$ peaches $\cdot$ pears

because somewhere I've specified that semicolons should be replaced with $\cdot$.

I have been searching through all the .tex files I've made in recent memory, and I just can't seem to find this, and it's driving me nuts, so any help is greatly appreciated.

share|improve this question

You can do it in many ways. For instance with xstring:


However this requires you to be very strict in inputting the argument without spaces around the semicolons.

A quite robust solution uses xparse and the LaTeX3 packages:

\NewDocumentCommand{\RealMacro}{ O{~$\cdots$~} m }
  \ryan_change_semicolons:nn { #1 } { #2 }

 \seq_new:N \l_ryan_input_seq

 \cs_new_protected:Npn \ryan_change_semicolons:nn #1 #2
   \seq_set_split:Nnn \l_ryan_input_seq { ; } { #2 }
   \seq_use:Nnnn \l_ryan_input_seq { #1 } { #1 } { #1 }

With this definition you don't have to worry if you input either one of

\RealMacro{apples ; oranges; peaches;pears}

because leading and trailing spaces will be removed. The macro allows also for a call such as

\RealMacro[, ]{apples;oranges;peaches;pears}

and the output would be

apples, oranges, peaches, pears

The default value of the optional argument is <space>$\cdot$<space> as requested.

share|improve this answer

Just to offer an alternative to looping over the list:

enter image description here


\def\ThisImaginaryMacro#1{\gdef~{\cdot}$\mathcode`\;"8000 \mathrm{#1}$}}


share|improve this answer

This kind of task is conveniently done by a recursive macro:

%recursive ``low-level'' macro

%user-friendly ``driver'' macro


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.