4

I read in xparse's documentation that \l__xparse_current_arg_int referred to "the number of the current argument being set up". I'm having trouble understanding how to access and use it, however. For example, how would you rely on that variable to produce ordered lists (i.e., exactly what replacing itemize with enumerate would yield) in the following example?

\documentclass{article}
\usepackage{xparse}
\NewDocumentCommand\mylist{>{\SplitList{;}}m}
    {
    \begin{itemize}
        \ProcessList{#1}{ \insertitem }
    \end{itemize}
    }
\newcommand\insertitem[1]{\item #1}

\begin{document}

Here's a list: \mylist{a;b;c;d;e;f;g}

\end{document}

I was hoping that a simple \item[\l__xparse_current_arg_int] would work, but it doesn't.

  • 1
    \l__xparse_current_arg_int is used in a very different context, to take care of what argument position is being examined. There is no integer available for the bits split by \SplitList, as far as I know. But using enumerate would solve the issue, wouldn't it? – egreg Apr 11 '13 at 16:39
  • In addition to what @egreg says, \l__xparse_current_arg_int is marked as internal (two underscores) and is not described in the 'user' part of the documents: we'd hope this would mark it as not for general use! – Joseph Wright Apr 11 '13 at 17:10
  • @JosephWright: then I suppose my question shows you how shallow my knowledge of the inner workings of a LaTeX package is ;-) – Anthony Labarre Apr 14 '13 at 8:42
5

There is no integer associated to the bits split by \SplitList: a recursion is started which ends with the list.

You can define a counter yourself:

\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\int_new:N \l_anthony_list_int
\NewDocumentCommand\mylist{>{\SplitList{;}}m}
 {
  \begin{itemize}
  \int_zero:N \l_anthony_list_int
  \ProcessList{#1}{ \insertitem }
  \end{itemize}
 }
\NewDocumentCommand\insertitem{m}
 {
  \int_incr:N \l_anthony_list_int
  \item[\int_to_arabic:n {\l_anthony_list_int}] #1
 }
\ExplSyntaxOff

\begin{document}

Here's a list: \mylist{a;b;c;d;e;f;g}

\end{document}

A LaTeX counter could be used as well.

\documentclass{article}
\usepackage{xparse}

\newcounter{anthonylist}
\NewDocumentCommand\mylist{>{\SplitList{;}}m}
 {
  \begin{itemize}
  \setcounter{anthonylist}{0}
  \ProcessList{#1}{ \insertitem }
  \end{itemize}
 }
\NewDocumentCommand\insertitem{m}
 {
  \stepcounter{anthonylist}
  \item[\theanthonylist}] #1
 }

\begin{document}

Here's a list: \mylist{a;b;c;d;e;f;g}

\end{document}

Of course it would be easier to use enumerate instead of itemize.

  • Thanks, I'll try using that. Of course, if I were really interested in a list, I'd use enumerate (and would actually have no use for xparse), but I just wanted a simple example to work on. I actually need this feature to draw things using TikZ. – Anthony Labarre Apr 11 '13 at 19:01

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.