[Tex/LaTex] Comma-separated list environment

environmentslistsmacrospunctuation

This question is somewhat of a follow up to an answer to a previous question (https://tex.stackexchange.com/a/11587/13522).

I would like to create a list environment (similar to itemize and enumerate) such that the output of the list environment is a comma-separated list.

For example, the following input:

\begin{commalist}
    \item Item A
    \item Item B
    \item Item C
\end{commalist}

Should produce the following output:

Item A, Item B and Item C.

Additionally, it would be nice to be able to specify the use of a comma instead of the final and (so that the output is instead Item A, Item B, Item C..

Best Answer

\documentclass{article}
\usepackage[inline]{enumitem}
\newlist{commalist}{description*}{4}
\setlist[commalist]{itemjoin={{,}},itemjoin*={{, and}},afterlabel=\unskip{{~}}}

\begin{document}
\begin{commalist}
    \item Item A
    \item Item B
    \item Item C
\end{commalist}
\end{document}

enter image description here

If there should be no comma before and, then delete it in the setting.

Related Question