0

I'm relatively new to LaTeX (within a year or so). I found an attempt at a legal document file online, and have been modifying it to work as I'd like, and attempting to change the functionality around.

I'm producing something that looks like the attached photo.enter image description here

Ideally, I would enter the parties like this: \party[x]{name}, where x is claimant, defendant, intervener, or any other group. Then, when it comes to formatting the legal heading, it would group them by [x], and produce something like this:

(1) NAME

(2) NAME [Claimants]

-and-

(1) NAME [Defendant]

-and-

(1) NAME [Other]

-and

(1) NAME (2) NAME [Xs]

etc... (if there were other [x]s).

I've been trying to get it such that it only adds an -and- where there is another group going below the -and-, but I'm going round in circles. I'd also like it to only add a (plural or singular) label to the final entry in a group. Without this functionality, and using two separate commands, this is what I've been using:

 % Identification \NeedsTeXFormat{LaTeX2e} \ProvidesClass{skeleton} \DeclareOption{fullserif}{ \newcommand{\@fullserif}{} } \DeclareOption{detailedhead}{ \newcommand{\@detailedhead}{} } \DeclareOption*{% \PassOptionsToClass{\CurrentOption}{memoir} } \ProcessOptions\relax % Load Article Class \LoadClass{memoir} \RequirePackage{arrayjob} \RequirePackage{multido} \RequirePackage{xifthen} \RequirePackage{tramlines} \RequirePackage[calcwidth]{titlesec} \RequirePackage{luacensor-dev} \RequirePackage[british]{babel} \RequirePackage[babel=true]{microtype} \RequirePackage{setspace} \RequirePackage{multicol} \RequirePackage{dashbox} \RequirePackage{textcsc} \RequirePackage{lua-ul} \RequirePackage{soul} \sodef\an{}{.2em}{0em}{.5em} % %LAYOUT SETTINGS % \stockaiv \settrimmedsize{\stockheight}{\stockwidth}{*} \semiisopage \setlrmargins{*}{*}{1} \checkandfixthelayout \addtolength{\skip\footins}{2pc plus 5pt} \newcommand{\partysize}{\large} \newcommand{\@temp}{} % %PARAGRAPH NUMBERING % %Set up counter \newcounter{legalcount} %Create the counter \setcounter{legalcount}{0} %Set it to zero %Create paragraph command \newcommand{\pa}{\refstepcounter{legalcount}\hangfrom{\makebox[0em][r]{\thelegalcount. }}} \newcommand{\ph}{\pa \OnehalfSpacing}% \newcommand{\pd}{\pa \DoubleSpacing}% % % LEGAL HEADING AND SIGNATURE % % Set up commands for inputing case information \newcommand{\@casenumber}{} \newcommand{\casenumber}[1]{\renewcommand{\@casenumber}{#1}} \newarray\Claimants \newarray\ClDescr \newcounter{claimantcount} \setcounter{claimantcount}{0} %We have no claimants until a \claimant{} is issued. \newcommand{\@claimant}{} \newcommand{\claimant}[2][Claimant]{ \stepcounter{claimantcount} \Claimants(\value{claimantcount})={#2} \ClDescr(\value{claimantcount})={#1} \ifthenelse{\value{claimantcount}=1}{ \renewcommand{\@claimant}{#2} }{} } \newarray\Respondents \newarray\RpDescr \newcounter{respondentcount} \setcounter{respondentcount}{0} %We have no claimants until a \respondent{} is issued. \newcommand{\@respondent}{} \newcommand{\respondent}[2][Respondent]{ \stepcounter{respondentcount} \Respondents(\value{respondentcount})={#2} \RpDescr(\value{respondentcount})={#1} \ifthenelse{\value{respondentcount}=1}{ \renewcommand{\@respondent}{#2} }{} } \newcommand{\@venue}{} \newcommand{\venue}[1]{\renewcommand{\@venue}{#1}} \newcommand{\@doctype}{} \newcommand{\doctype}[1]{\renewcommand{\@doctype}{#1}} \newcommand{\@counsel}{} \newcommand{\counsel}[1]{\renewcommand{\@counsel}{#1}} \newcommand{\@chambers}{} \newcommand{\chambers}[1]{\renewcommand{\@chambers}{#1}} % Create Legal Heading \newcommand{\legalhead} { \thispagestyle{plain} \LARGE \noindent \begin{minipage}[t]{.45\linewidth} \vspace{0pt} \raggedright \noindent \underLine{\textcsc{IN THE \@venue}} \end{minipage} \hfill \begin{minipage}[t]{.45\linewidth} \vspace{0pt} \raggedleft \noindent \underLine{\textcsc{\oldstylenums{\@casenumber}}} \end{minipage} \vspace{1ex} \noindent {\LARGE\textcsc{\an{BETWEEN}}} \vspace{1ex} \LARGE \begin{center} \multido{\iClaimant=1+1}{\value{claimantcount}}{% \noindent \partysize \parbox{0.215\textwidth}{% \ifthenelse{\isundefined{\@detailedhead}} {\rule{2mm}{0pt}} {\normalsize (\iClaimant)} } \parbox{0.55\textwidth}{% \LARGE \centering {\bfseries\textcsc{\Claimants(\iClaimant)}} } \parbox{0.215\textwidth}{% \ifthenelse{\isundefined{\@detailedhead}} {\rule{2mm}{0pt}} {\raggedleft \normalsize \textcsc{[\ClDescr(\iClaimant)]}} } \newline \LARGE \newline } \vspace{-1em} \large -and- \vspace{1em} \multido{\iRespondent=1+1}{\value{respondentcount}}{% \noindent \partysize \parbox{0.215\textwidth}{% \ifthenelse{\isundefined{\@detailedhead}} {\rule{2mm}{0pt}} {\large (\iRespondent)} } \parbox{0.55\textwidth}{% \LARGE \centering {\bfseries\textcsc{\Respondents(\iRespondent)}} } \parbox{0.215\textwidth}{% \ifthenelse{\isundefined{\@detailedhead}} {\rule{2mm}{0pt}} {\raggedleft \small \textcsc{[\RpDescr(\iRespondent)]}} } \newline \LARGE \newline } \vspace{-1.6em} \tramlines{{{\LARGE\bfseries\textcsc{\@doctype}}}} \end{center} \normalsize \pagenumbering{arabic} } % Create Short Heading for Internal Docs \newcommand{\shorthead} { \thispagestyle{empty} \begin{center} \noindent \textcsc{\@claimant} v. \textcsc{\@respondent}\\ \tramlines{\@doctype} \end{center} } % Create Legal Signature \newcommand{\sign} { \begin{flushright} \textcsc{\@counsel}\\* \textsc{\@chambers}\\* \@date \end{flushright}} %Create Box and Signature \newcommand{\longsign} { \begin{multicols}{2} \noindent\dashbox[4cm]{\rule{0pt}{15mm}} \columnbreak \begin{flushright} \textcsc{\@counsel}\\* \textcsc{\@chambers}\\* \@date \end{flushright} \end{multicols} \begin{center} \begin{tabular}{@{}l@{}} \rule{4cm}{0pt}\\ \hline Signed by NAME \end{tabular} \end{center} }% % %SECTIONS % % Suppress numbered sections \setcounter{secnumdepth}{-2} \ifthenelse{\isundefined{\@fullserif}}{ %If fullserif is undefined - i.e. normal %Format Chapter \titleformat{\chapter}{\rmfamily\Large\bfseries\uppercase} {leftmargin} {0em} {}[]% \titlespacing*{\chapter}% {-2em}% {0em}% {0em}% \newcommand{\legaltitle}[1]{\begingroup \let \clearpage \relax \chapter{#1} \endgroup} %Format Section \titleformat{\section}{\rmfamily\large\bfseries} {leftmargin} {0em} {}[\titleline*{\titlerule}]% \titlespacing*{\section}% {-1.5em}% {0em}% {\parskip}% %Format SubSection \titleformat{\subsection}{\rmfamily\normalsize} {leftmargin} {0em} {}[\titleline*{\titlerule}]% \titlespacing*{\subsection}% {0em}% {0em}% {\parskip}% %Format SubSubSection \titleformat{\subsubsection}{\rmfamily\normalsize\itshape} {leftmargin} {0em} {}[]% \titlespacing*{\subsubsection}% {0em}% {0em}% {\parskip}% }{ %if \@fullsans has been defined: %Format Chapter \renewcommand\chapter{\@startsection {section}{1}{0mm}% {-\baselineskip}% {0.5\baselineskip}% {\LARGE}% } %Format Section \renewcommand\section{\@startsection {section}{1}{0mm}% {-\baselineskip}% {0.5\baselineskip}% {\Large}% } %Format SubSection \renewcommand\subsection{\@startsection {subsection}{2}{0mm}% {-\baselineskip}% {0.25\baselineskip}% {\large}% } %Format SubSubSection \renewcommand\subsubsection{\@startsection {subsubsection}{3}{0mm}% {-\baselineskip}% {0.1\baselineskip}% {\normalsize\slshape}% } } %Format Paragraph \renewcommand\paragraph{\@startsection {paragraph}{4}{0mm}% {-\baselineskip}% {0.1\baselineskip}% {\normalfont\normalsize}% } % %FORMATTING % \defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase} \setmainfont{Times New Roman} %Use letters in enumerate \renewcommand{\labelenumi}{\alph{enumi}.} \renewcommand{\labelenumii}{\arabic{enumii})} %Adjust distance after paragraphs \setlength{\parskip}{1em} %Apply running headers \makepagestyle{running} \makepsmarks{running}{% \nouppercaseheads \createmark{chapter}{both}{nonumber}{}{} \createmark{section}{right}{shownumber}{}{. \space} \createplainmark{toc}{both}{\contentsname} \createplainmark{lof}{both}{\listfigurename} \createplainmark{lot}{both}{\listtablename} \createplainmark{bib}{both}{\bibname} \createplainmark{index}{both}{\indexname} \createplainmark{glossary}{both}{\glossaryname} } \makeheadrule{running}{\textwidth}{0.2pt} \makeevenhead{running}{}{}{\rightmark} \makeoddhead{running}{}{}{\rightmark} \makeevenfoot{running}{}{}{\thepage} \makeoddfoot{running}{}{}{\thepage} %Format Table of Contents \usepackage{titletoc} \contentsmargin{0pt} \titlecontents{section}[0pt] {\ssfseries\large\thecontentspage\quad} {}{}{}{} \newcommand\xquad {\hspace{1em plus.4em minus.4em}} \titlecontents*{subsection}[0pt] {\filright\small}{}{} {,~\thecontentspage} [\xquad\textbullet\xquad][] \setcounter{tocdepth}{2} %Typeset legislation \newenvironment{statquote}% {% \vspace{-2ex}\OnehalfSpacing% \begin{list}{}% {% \setlength{\topsep}{0ex}% \setlength{\partopsep}{1ex}% \setlength{\parsep}{0.5ex}% \setlength{\itemsep}{0ex}% \addtolength{\leftmargin}{1em}% \addtolength{\rightmargin}{1.5em}% }% \item[]}% {\end{list}% \vspace{1ex}% }% \newenvironment{instatquote}% {% \vspace{-4ex}% \begin{list}{}% {% \setlength{\topsep}{0.5ex}% \setlength{\partopsep}{1ex}% \setlength{\parsep}{0.5ex}% \setlength{\itemsep}{0ex}% }% \item[]}% {\end{list}% }% \newcommand*\statquotelabel[1]{} \newcommand{\stat}[2]{ \item[(#1)]#2 } \newcommand{\stathead}[2]{ \item[\textbf{#1}]\textbf{#2} } 

I've had a few attempts at working this out, including trying to use Expl3, but I just cannot figure it out.

Any help would be greatly appreciated!

EDIT: My attempt at making the automatic -and- function work:

 % test.cls \NeedsTeXFormat{LaTeX2e} \ProvidesClass{test} \DeclareOption{fullserif}{ \newcommand{\@fullserif}{} } \DeclareOption{detailedhead}{ \newcommand{\@detailedhead}{} } \DeclareOption*{% \PassOptionsToClass{\CurrentOption}{memoir} } \ProcessOptions\relax % Required Packages \RequirePackage{arrayjob} \RequirePackage{multido} \RequirePackage{xifthen} \RequirePackage{tramlines} \RequirePackage[calcwidth]{titlesec} \RequirePackage{luacensor-dev} \RequirePackage[british]{babel} \RequirePackage[babel=true]{microtype} \RequirePackage{setspace} \RequirePackage{multicol} \RequirePackage{dashbox} \RequirePackage{textcsc} \RequirePackage{lua-ul} \RequirePackage{soul} \sodef\an{}{.2em}{0em}{.5em} % Layout Settings \stockaiv \settrimmedsize{\stockheight}{\stockwidth}{*} \semiisopage \setlrmargins{*}{*}{1} \checkandfixthelayout \addtolength{\skip\footins}{2pc plus 5pt} \newcommand{\partysize}{\large} \newcommand{\@temp}{} \RequirePackage{expl3} \ExplSyntaxOn \seq_new:N \l_parties_claimant_seq \seq_new:N \l_parties_defendant_seq \seq_new:N \l_parties_intervenor_seq \seq_new:N \l_parties_other_seq \NewDocumentCommand{\party}{mm} { \str_case:nn { #1 } { {claimant} { \seq_put_right:Nn \l_parties_claimant_seq { #2 } } {defendant} { \seq_put_right:Nn \l_parties_defendant_seq { #2 } } {intervenor} { \seq_put_right:Nn \l_parties_intervenor_seq { #2 } } {other} { \seq_put_right:Nn \l_parties_other_seq { #2 } } } } \NewDocumentCommand{\legalhead}{} { \thispagestyle{plain} \LARGE \noindent \begin{minipage}[t]{.45\linewidth} \vspace{0pt} \raggedright \noindent \underLine{\textcsc{IN THE \@venue}} \end{minipage} \hfill \begin{minipage}[t]{.45\linewidth} \vspace{0pt} \raggedleft \noindent \underLine{\textcsc{\oldstylenums{\@casenumber}}} \end{minipage} \vspace{1ex} \noindent {\LARGE\textcsc{\an{BETWEEN}}} \vspace{1ex} \LARGE \begin{center} \__print_parties:nn {claimant} {Claimants} \__print_and:n {defendant} \__print_parties:nn {defendant} {Defendants} \__print_and:n {intervenor} \__print_parties:nn {intervenor} {Intervenors} \__print_and:n {other} \__print_parties:nn {other} {Others} \end{center} \normalsize \pagenumbering{arabic} } \cs_new_protected:Npn \__print_parties:nn #1 #2 { \seq_if_empty:NTF \l_parties_#1_seq {} { \seq_map_indexed:Nn \l_parties_#1_seq { \__print_party:nn { ##2 } { ##1 } } \__print_label:n { #2 } } } \cs_new_protected:Npn \__print_party:nn #1 #2 { \noindent \partysize \parbox{0.215\textwidth} { \ifthenelse{\isundefined{\@detailedhead}} {\rule{2mm}{0pt}} {\normalsize (#2)} } \parbox{0.55\textwidth} { \LARGE \centering {\bfseries\textcsc{#1}} } \parbox{0.215\textwidth} { \ifthenelse{\isundefined{\@detailedhead}} {\rule{2mm}{0pt}} {} } \newline \LARGE \newline } \cs_new_protected:Npn \__print_label:n #1 { \hfill \textsc{[#1]} } \cs_new_protected:Npn \__print_and:n #1 { \seq_if_empty:NTF \l_parties_#1_seq {} { \vspace{-1em} \large -and- \vspace{1em} } } \ExplSyntaxOff \newcommand{\@venue}{} \newcommand{\venue}[1]{\renewcommand{\@venue}{#1}} \newcommand{\@doctype}{} % \newcommand{\doctype}[1]{\renewcommand{\@doctype}{#1}} % Removed as it's not defined \newcommand{\@counsel}{} \newcommand{\counsel}[1]{\renewcommand{\@counsel}{#1}} \newcommand{\@chambers}{} \newcommand{\chambers}[1]{\renewcommand{\@chambers}{#1}} 

But this doesn't work with this input:

\documentclass{test} \begin{document} \venue{HCoJ-CD} \casenumber{123456} \doctype{Skeleton Argument...} \party{claimant}{Random A} \party{claimant}{Random B} \party{defendant}{Random C} \party{defendant}{Random D} \party{other}{Random E} \legalhead \end{document} 
8
  • 2
    Hi and welcome! It is polite to mention that you asked the same question elsewhere. Commented Jun 6, 2024 at 20:01
  • Oh sure - I also asked the same question on Reddit, here: reddit.com/r/LaTeX/comments/1d9ozok/… Commented Jun 6, 2024 at 20:04
  • Is the output what you need? What decides whether the word on the right is singular or plural e.g. why 'intervener' and not 'interveners'? Commented Jun 6, 2024 at 20:59
  • Ideally, the word on the right would be plural if there was more than one party in that group (i.e. intervener if only one, interveners if more than one). Commented Jun 6, 2024 at 21:01
  • Can you please minimise your code? We don't need everything to reproduce this particular problem ;). But you've also not given us code for the input which should produce that output. Commented Jun 6, 2024 at 21:02

1 Answer 1

1

Recommendations:

  1. Include an appropriate (hopefully unique) 'module' name before the _<descriptor>_<type> when naming expl3 functions and variables.
  2. Use c type functions rather than N when you want to construct the name of a variable before using it e.g. \tl_set:cn {l__latexlawyer_#1_tl} {#2} or whatever, since #1 is not a letter and cannot be used in a variable name (and, even if it could, it wouldn't be the variable name you want). This is the equivalent of saying e.g. \expandafter\def\csname latexlawyer@#1\endcsname{#2} etc.
  3. Consider using a key-value interface of some sort. Example below, but probably far from ideal.
  4. Learn to minimise the code you post when asking a question so that it focuses on the specific issue you're concerned with. I gave up trying to understand and correct your code because there was too much of it.
  5. Pass british as a class option when using babel.
  6. Note that even if the licence allows you to use the code you found without attribution here, it would be a courtesy to both the original author and people here if you included a link. Note that I am not a lawyer and this is not legal advice.

\documentclass[british]{memoir} \usepackage{babel} % ateb: https://tex.stackexchange.com/a/719930/ \ExplSyntaxOn \clist_new:N \l__latexlawyer_tmpa_clist \clist_new:N \l__latexlawyer_parties_clist \seq_new:N \l__latexlawyer_parties_seq \int_new:N \l__latexlawyer_tmpa_int \cs_new_protected:Nn \latexlawyer_party_style: {} \cs_new_protected:Nn \latexlawyer_label_style:n {} \keys_define:nn { latexlawyer } { and .tl_set:N = \l__latexlawyer_and_tl, and .initial:n = { \textmd{ --and-- } }, label ~ style .code:n = { \cs_set_protected:Nn \latexlawyer_label_style:n { #1 } }, label ~ style .initial:n = { \raggedleft\normalsize\textbf{#1} }, labels .code:n = { \keys_set:nn { latexlawyer / labels } { #1 } }, order .clist_set:N = \l__latexlawyer_parties_clist, order .initial:n = { claimant, defendant, intervenor, interestedparty, other }, parties .code:n = { \keys_set:nn { latexlawyer / parties } { #1 } }, party ~ style .code:n = { \cs_set_protected:Nn \latexlawyer_party_style: { #1 } }, party ~ style .initial:n = { \LARGE\bfseries }, } \keys_define:nn { latexlawyer / parties } { claimant .clist_set:N = \l__latexlawyer_claimant_clist, defendant .clist_set:N = \l__latexlawyer_defendant_clist, interestedparty .clist_set:N = \l__latexlawyer_interestedparty_clist, intervenor .clist_set:N = \l__latexlawyer_intervenor_clist, other .clist_set:N = \l__latexlawyer_other_clist, unknown .code:n = { \clist_if_exist:cF { l__latexlawyer_ \l_keys_key_str _clist } { \clist_new:c { l__latexlawyer_ \l_keys_key_str _clist } } \clist_set:cV { l__latexlawyer_ \l_keys_key_str _clist } \l_keys_value_tl \clist_put_right:NV \l__latexlawyer_parties_clist \l_keys_key_str }, } \keys_define:nn { latexlawyer / labels } { interestedparty .tl_set:N = \l__latexlawyer_interestedparty_label_tl, interestedparty .initial:n = {interested ~ party}, interestedpartys .tl_set:N = \l__latexlawyer_interestedpartys_label_tl, interestedpartys .initial:n = {interested ~ parties}, unknown .code:n = { \tl_if_exist:cF { l__latexlawyer_ \l_keys_key_str _label_tl } { \tl_new:c { l__latexlawyer_ \l_keys_key_str _label_tl } } \tl_set:cV { l__latexlawyer_ \l_keys_key_str _label_tl } \l_keys_value_tl }, } \NewDocumentCommand \llset { +m } { \keys_set:nn { latexlawyer } { #1 } } \NewDocumentCommand \llprintparties { o } { \IfValueT { #1 } { \keys_set:nn { latexlawyer / parties } { #1 } } \seq_clear:N \l__latexlawyer_parties_seq \clist_map_inline:Nn \l__latexlawyer_parties_clist { \int_zero:N \l__latexlawyer_tmpa_int \clist_clear:N \l__latexlawyer_tmpa_clist \tl_if_exist:cF { l__latexlawyer_##1_tl } { \tl_new:c { l__latexlawyer_##1_tl } } \int_case:nnF { \clist_count:c { l__latexlawyer_##1_clist} } { { 0 } { \tl_clear:c { l__latexlawyer_##1_tl } } { 1 } { \tl_set:ce { l__latexlawyer_##1_tl } { { \centering \latexlawyer_party_style: \clist_use:cn { l__latexlawyer_##1_clist } {} \par } { \latexlawyer_label_style:n { \tl_if_exist:cTF { l__latexlawyer_ ##1 _label_tl } { \tl_use:c { l__latexlawyer_ ##1 _label_tl } } { ##1 } } \par } } } } { \clist_map_inline:cn { l__latexlawyer_##1_clist } { \int_incr:N \l__latexlawyer_tmpa_int \clist_put_right:Ne \l__latexlawyer_tmpa_clist { ( \int_to_arabic:n { \l__latexlawyer_tmpa_int } ) ~ ####1 } } \tl_set:ce { l__latexlawyer_##1_tl } { { \centering \latexlawyer_party_style: \clist_use:Nn \l__latexlawyer_tmpa_clist { \\ } \par } { \latexlawyer_label_style:n { \tl_if_exist:cTF { l__latexlawyer_ ##1s _label_tl } { \tl_use:c { l__latexlawyer_ ##1s _label_tl } } { \tl_if_exist:cTF { l__latexlawyer_ ##1 _label_tl } { \tl_use:c { l__latexlawyer_ ##1 _label_tl } s } { ##1 s } } } \par } } } \tl_if_empty:cF { l__latexlawyer_##1_tl } { \seq_put_right:Nv \l__latexlawyer_parties_seq { l__latexlawyer_##1_tl } } } \clist_clear:N \l__latexlawyer_tmpa_clist \seq_use:Nn \l__latexlawyer_parties_seq { \bigskip \par { \centering \l__latexlawyer_and_tl \bigskip \par } } } \ExplSyntaxOff \begin{document} \llset{% parties = {% claimant = {Bagpuss,Emily,the Clangers}, defendant = {Black-and-White Cat}, interestedparty = {Postman Pat}, intervenor = {Wombles of Wimbledon}, commentator = {Commoners, Council of Trumpton}, }, label style={\raggedleft\normalsize\textmd{\MakeTitlecase{#1}}}, labels={% interestedparty=observer, }, } \llprintparties \end{document} 

sample output

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.