2

I think this is an easy for-loop question, but I can't seem to get it to work...

I frequently need to put a CC list at the end of the documents that I prepare. I have been making the list manually, doing something like

\noindent
\begin{tabular}{l l}
CC: & Dr. A. Name \\
    & Mr. B. Name \\
    & Dr. C. Name 
\end{tabular}

How would I make a macro that accepts that list of names as an argument and outputs the tabular? I would like to declare a variable in my document

\cc{Dr. A Name, Mr. B Name, Dr. C Name}

then at the end of the doc do something like

\makecclist

which puts in the formatted cc list table at the end.

Thanks for any help!

Mensch
  • 65,388
user31313
  • 123

1 Answers1

3

It's a breeze with expl3: we just need to deliver the list with \\ & between the items.

\documentclass{article}
%\usepackage{xparse} % uncomment if using LaTeX release prior to 2020-10-01

\ExplSyntaxOn

% declare a variable \clist_new:N \g_userx_cc_names_clist

% populate the variable \NewDocumentCommand{\cc}{m} { \clist_gset:Nn \g_userx_cc_names_clist { #1 } }

% use the variable \NewDocumentCommand{\makecclist}{} { \clist_if_empty:NF \g_userx_cc_names_clist { \begin{tabular}{ @{} l l @{} } CC: & \clist_use:Nn \g_userx_cc_names_clist { \ & } \end{tabular} } }

\ExplSyntaxOff

\begin{document}

\cc{Dr. A Name, Mr. B Name, Dr. C Name}

\makecclist

\end{document}

enter image description here

egreg
  • 1,121,712