4

I had help making a macro to process a list of arguments separated by ; into an itemize environment. To achieve this, xparse was used.

When I tried to wrap the lists of arguments in a macro, nothing happened though. How may I fix this?

MWE:

\documentclass{article}
\usepackage{xparse}
\newcommand\insertitem[1]{\item #1}

% xparse-command I had help with
\NewDocumentCommand\myList{>{\SplitList{;}}m}
  {\vspace*{-\baselineskip}
    \begin{itemize}
      \ProcessList{#1}{ \insertitem }
    \end{itemize}
  }

\newcommand\someStuff{One; two; three}

\begin{document}

\myList{One; two; three}

Now trying to expand macro content

\myList{\someStuff}

\end{document}

In \myList{One; two; three} the result is as desired, an itemized list. The latter example, \myList{\someStuff} is not working. I believe the solution to my problem probably lies somewhere in the question Passing multiple arguments from ProcessList (xparse) to a macro. Result to be used in tabular, but I'm not currently able to understand where...

EDIT: the intended use for the storing of arguments in a macro is basically to make my life a bit easier. I have made a template structure to a progression plan in the subjects I teach, where I need to print for instance the desired main competences my students should have achieved during the planned period. As those competences (and more) are wrapped into a messy longtable environment, and I am planning to make the template into a class when I have time to learn how to do just that, it would be very convenient for me to have a block in the beginning of the document looking a bit like this:

\maincompetences{Competence one; competence two, etc.}
\learninggoals{Main goal one; main goal two; etc.}
4

TeX doesn't expand arguments when it's absorbing them. So in the second case the argument that's passed to \SplitArgument is \someStuff that doesn't contain semicolons.

One might force the expansion of the first token in the argument, but this might create other problems.

A lower level solution.

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\myList}{sm}
 {
  \begin{itemize}
  \IfBooleanTF{#1}
   {
    \holene_mylist:o { #2 } % expand the argument (once)
   }
   {
    \holene_mylist:n { #2 }
   }
   \end{itemize}
 }

\seq_new:N \l_holene_mylist_input_seq

\cs_new_protected:Npn \holene_mylist:n #1
 {
  \seq_set_split:Nnn \l_holene_mylist_input_seq { ; } { #1 }
  \seq_map_inline:Nn \l_holene_mylist_input_seq
   {
    \item ##1
   }
 }
\cs_generate_variant:Nn \holene_mylist:n { o }

\ExplSyntaxOff

\newcommand\someStuff{One; two; three}

\begin{document}

\myList{One; two; three}

Now trying to expand macro content

\myList*{\someStuff}

\end{document}

enter image description here

You are deciding when expanding the argument or not, with the *-variant.

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.