2

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}
\usepackage{amsmath,ulem}
%%%%%%%Definition of Name Command
\newcommand{\scdots}[2][]{\mathinner{#1\overset{#2}{\cdots}#1}}
\newcommand\ovline{\bgroup\markoverwith{{\rule[-0.5ex]{5pt}{0.4pt}}}\ULon}
\newcounter{nameCounter}
%\setcounter{\nameCounter}{0}
\newcommand {\name}[1]{{\ovline {#1}}
\stepcounter{nameCounter}$_{\arabic{nameCounter}}$}
\begin{document}
\name{First One}   \name{Second Name}  \name{Third Name}
%%%%%Request for defining an Environment of Names  - as mentioned below
%\begin{names}
%First One, Second One, Third One \\
%Fourth One, Fifth Name.
%\end{names}
\end{document}
1

1 Answer 1

2

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}
\usepackage{amsmath,ulem,xparse,environ}

%%%%%%%Definition of Name Command
\newcommand{\scdots}[2][]{%
  \mathinner{#1\overset{#2}{\cdots}#1}%
}
\newcommand\ovline{%
  \bgroup\markoverwith{\rule[-0.5ex]{5pt}{0.4pt}}\ULon
}
\newcounter{nameCounter}
%\setcounter{\nameCounter}{0}
\newcommand{\name}[1]{%
  \ovline{#1}%
  \stepcounter{nameCounter}$\,_{\arabic{nameCounter}}$%
}

\ExplSyntaxOn
\NewEnviron{names}[1][]
 {
  \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 } { ,\\ }
   }
  #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 ',~'
  \name{#1}
 }

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

\ExplSyntaxOff

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

\bigskip

\begin{names}[.]
First One, Second One, Third One \\
Fourth One, Fifth Name
\end{names}

\end{document}

enter image description here

3
  • 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 .