3

I am looking at etoolbox and not able to find why it gives this error. I am going over an example in the manual, which works. But when I made small change, I am getting an error.

This works:

\documentclass[10pt]{book}
\usepackage{etoolbox}    
\begin{document}
\begin{enumerate}
  \renewcommand*{\do}[1]{\item #1}
  \docsvlist{{item1, 1},{item2, 2},{item3, 3}}
\end{enumerate}
\end{document}

But the above example has the list right there inline. I wanted to first create the list outside, and then process it separately. I found the command listadd

Mathematica graphics

So used it to make a list and then run the \begin{enumerate} on the list, I get an error:

\documentclass[10pt]{book}    
\usepackage{etoolbox}    
\begin{document}    
\forcsvlist{\listadd\mylist}{ {item1, 1},{item2, 2},{item3, 3}}    
\begin{enumerate}
  \renewcommand*{\do}[1]{\item #1}
  \docsvlist{\mylist}
\end{enumerate}    
\end{document}

Error is

    Command \end{enumerate} invalid in math mode. \end{enumerate}

Here is the example I was trying

Mathematica graphics

Question is: How can one create a list using listadd and process it separately using \docsvlist{\mylist} ?

4

You have to use \dolistloop to loop over the element of \mylist, not \docsvlist. After you create it, \mylist is an internal list and no longer a comma separated list. The manual specifies that

These lists use a special character as internal list separator.

and footnote 3 specifies:

The character | with category code 3. Note that you may not typeset a list by saying \listname. Use \show instead to inspect the list.

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.