# join list with separator

I'm wondering if it's possible to create a command that takes some kind of list and joins it with some separator in between each entry.

For example, given something like:

parameters:
first
second with spaces
third

separator:
·


I'd want it to output:

first · second with spaces · third


With the spacing around the separator.

Perhaps this is more trouble than it's worth. Mainly it'd be to deal with the hassle of having to keep repasting the · character appropriately over any slight modification.

Otherwise, maybe I can leverage an environment, such as points, to join the \items with · on the interior? I don't mind if it ends up being more typing, at least it'd be easier to manage and I wouldn't have to keep repasting the separator over any slight modification, since each entry would correspond to an independent \item.

Based on expl3s clist:

\documentclass[]{article}

\usepackage{xparse}
\ExplSyntaxOn
\clist_new:N \l_jorge_list_clist
\clist_new:N \l_jorge_tmp_clist
\NewExpandableDocumentCommand \usemylist { m }
{
\clist_use:Nn \l_jorge_list_clist { #1 }
}
\NewDocumentCommand \setmylist { m }
{
\clist_set:Nn \l_jorge_list_clist { #1 }
}
\NewDocumentCommand \formatlist { m m }
{
\clist_set:Nn \l_jorge_tmp_clist { #1 }
\clist_use:Nn \l_jorge_tmp_clist { #2 }
}
\ExplSyntaxOff

\setmylist{first, second with spaces, third}

\begin{document}
\usemylist{.}

\formatlist{foo,bar,baz}{ FOOBAR }
\end{document}

• Thanks! I'll have multiple of these lists, should I just keep doing \setmylist before each \usemylist? Any way to combine the two to make it less tedious? If not, no big deal. – Jorge Israel Peña May 17 '18 at 18:15
• I accidentally hit enter before I finished typing my comment. It's updated. – Jorge Israel Peña May 17 '18 at 18:16
• @JorgeIsraelPeña updated with both a local adhoc variant and a variant to save a list first. – Skillmon May 17 '18 at 18:19
• That works beautifully. Thank you very much! – Jorge Israel Peña May 17 '18 at 18:22