4

I need to create a comma (or any other) separated list of words for further usage and assign it to variable (macro). The words in list should be placed in separate lines. When I use for this purposes \def of \newcommand it is necessary to add percent sign % to the end of lines.

How can one avoid usage the % sign?

My idea, is to create list with expl3:

\NewDocumentCommand{\makelist}{ m m}
{
  \tl_set:Nx \l_ty_tl {#1}
  \csc_new:nn {#2}{\tl_use:N \l_ty_tl}

}

and use it like

\makelist{
Elstat, 
Magstat, 
Current
}{\mylist}

\multiinclude{\mylist}

An MWE below

\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn

\NewDocumentCommand{\multiinclude}{ mO{} }
 {
  \tl_set:Nx \l_ty_tl {#2}
  %\clist_map_inline:Nn #1 { \include{##1\l_ty_tl}} <= real usage
  \clist_map_inline:Nn #1 { ##1\l_ty_tl} %<= for MWE
 }

\ExplSyntaxOff

\begin{document}

\newcommand\mylist{%
Elstat,% 
Magstat,% 
Current}
\chapter{Problems}
\multiinclude{\mylist}[]

\chapter{Answers}
\multiinclude{\mylist}[-AnswersFile]

\end{document}
6

You have to “normalize” the list:

\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn

\NewDocumentCommand{\multiinclude}{ mO{} }
 {
  \clist_set:Nx \l_sergio_mi_clist { #1 }
  \clist_map_inline:Nn \l_sergio_mi_clist { \noindent ##1 #2 \par }
 }
\ExplSyntaxOff

\begin{document}

\newcommand\mylist{
  Elstat,
  Magstat,
  Current
}

\section{Problems}
\multiinclude{\mylist}[]

\section{Answers}
\multiinclude{\mylist}[-AnswersFile]

\end{document}

enter image description here

On the other hand, I'd avoid \newcommand and call lists by name:

\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn

\NewDocumentCommand{\multiinclude}{ m O{} }
 {
  \clist_map_inline:cn { l_sergio_list_#1_clist } { \noindent ##1 #2 \par }
 }
\NewDocumentCommand{\makelist}{ mm }
 {
  \clist_set:cn { l_sergio_list_#1_clist } { #2 }
 }
\ExplSyntaxOff

\begin{document}

\makelist{mylist}{
  Elstat,
  Magstat, 
  Current
}

\section{Problems}
\multiinclude{mylist}[]

\section{Answers}
\multiinclude{mylist}[-AnswersFile]

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.