For typesetting a religious document explained as below

  1. This contains verses of list of names separated by commas.
  2. A counter is to be initiated and will be incremented with each name.
  3. Each name has to be underlined and this counter has to be printed as subscript

I tried to define a command but I request help in defining an environment which takes a comma separated list of names and that contains some line breaks also, which have to be properly typeset as line breaks only.

I am not an expert of LaTeX but I tried typesetting some Theses which never needed this feature. Thanks in advance.

I tried the following

\documentclass[a4paper, 10pt]{memoir}
%%%%%%%Definition of Name Command
\newcommand {\name}[1]{{\ovline {#1}}
\name{First One}   \name{Second Name}  \name{Third Name}
%%%%%Request for defining an Environment of Names  - as mentioned below
%First One, Second One, Third One \\
%Fourth One, Fifth Name.

1 Answer 1


Here's an implementation with xparse and environ.

The environment's contents is split into lines at \\. Then each line is split at commas and each item is fed as argument to \name. The lines are rebuilt with comma-space between items, and printed in sequence.

Final punctuation must be added as an optional argument to the environment.

\documentclass[a4paper, 10pt]{memoir}

%%%%%%%Definition of Name Command

  \seq_set_split:NnV \l_majety_name_lines_seq { \\ } \BODY
  \seq_pop_left:NN \l_majety_name_lines_seq \l_majety_name_firstline_tl
  \majety_name_process_line:Vn \l_majety_name_firstline_tl { }
  \seq_map_inline:Nn \l_majety_name_lines_seq
    \majety_name_process_line:nn { ##1 } { ,\\ }

\seq_new:N \l_majety_name_lines_seq
\seq_new:N \l_majety_name_oneline_seq
\tl_new:N \l_majety_name_firstline_tl
\tl_new:N \l_majety_name_firstname_tl

\cs_new_protected:Npn \majety_name_process_line:nn #1 #2
  #2 % can be empty or ',\\'
  \seq_set_split:Nnn \l_majety_name_oneline_seq { , } { #1 }
  \seq_pop_left:NN \l_majety_name_oneline_seq \l_majety_name_firstname_tl
  \majety_name_process_name:Vn \l_majety_name_firstname_tl { }
  \seq_map_inline:Nn \l_majety_name_oneline_seq
    \majety_name_process_name:nn { ##1 } { ,~ }

\cs_new_protected:Npn \majety_name_process_name:nn #1 #2
  #2 % can be empty or ',~'

\cs_generate_variant:Nn \majety_name_process_line:nn { V }
\cs_generate_variant:Nn \majety_name_process_name:nn { V }


\name{First One}   \name{Second Name}  \name{Third Name}


First One, Second One, Third One \\
Fourth One, Fifth Name


enter image description here

  • I could not avoid saying thanks to @egreg for quick and perfect reply. Commented Jul 6, 2015 at 10:49
  • @RamaKrishnaMajety You're very welcome! :)
    – egreg
    Commented Jul 6, 2015 at 10:51
  • @RamaKrishnaMajety Of course you may also say thank you by accepting the answer and (as soon as you have enough reputation) up-voting it.
    – moewe
    Commented Jul 6, 2015 at 15:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .