0

I'm trying to make a comma separated list, but have noticed some strange things occurring. Here's an example:

\documentclass{article}

\usepackage{expl3}

\newcommand{\assignment}{1, 2, 7, 8}

\ExplSyntaxOn

\newcommand{\getitem}[2]
{\clist_item:nn {#1}{#2}}

\ExplSyntaxOff

\begin{document}

\getitem{\assignment}{1}

\getitem{1, 2, 7, 8}{1}

\end{document}

What ends up being outputted is "1, 2, 7, 8" on the first line and "1" on the second. I want to "contain" the comma list within a variable to make it easier to change, as I'm using this for a template.

But, it seems that by putting the list in a variable, clist loses its ability to separate the list by commas.

0

1 Answer 1

1

With your definition, you are executing

\clist_item:nn { \assignment } { 1 }

which of course delivers \assignment.

You want

\clist_item:Nn \assignment { 1 }
2
  • Wow that was an easy fix. In general, what's the difference between "Nn" and "nn" after the colon?
    – eeen
    Sep 6, 2020 at 16:27
  • @LaTeXereXeTaL Yes. But there is a fundamental difference between the two call in the code above, because in the first case the comma list consists of a single item, in the second case of four.
    – egreg
    Sep 6, 2020 at 19:31

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.