2

I want to insert some information from a csv text file or from a mdb (MS data base) base into a latex document. For example I have a document with math exercises and I would like to insert the first and the second element (i.e. exercise) of the base into \begin{enumerate} \end{enumerate}. How could this achieved in LaTeX?

N.N.
  • 36,163
kornaros
  • 1,095

1 Answers1

5

The etoolbox has \docsvlist and \forcsvlist. The documentation for the \docsvlist gives the following example:

\begin{itemize}
\renewcommand*{\do}[1]{\item #1}
\docsvlist{item1, item2, {item3a, item3b}, item4}
\end{itemize}

If you wanted to stop the list at 2 items, you could use a counter

\documentclass{article}
\usepackage{etoolbox}
\begin{document}
    \begin{itemize}
      \newcounter{item}
      \renewcommand*{\do}[1]{%
        \ifnumless{\arabic{item}}{2}{\item #1}{}
        \stepcounter{item}}%
      \docsvlist{item1, item2, {item3a, item3b}, item4}
    \end{itemize}
\end{document}
StrongBad
  • 20,495
  • I think \docsvist is a good idea. One more question: Let us suppose we have the \docsvlist{item1, item2, {item3a, item3b,item3c, item3d}, item4} and someone wants to take only the item3b and item3d for use with \do command(see Daniels Shub' answer). How this could be achieved?? – kornaros Feb 20 '12 at 15:37
  • @kornaros This is really a new question, and I think it should be asked as such. I think you will need to provide additional information to get an answer. Specifically, what do you know in advance and what do you expect the user to input. – StrongBad Feb 20 '12 at 16:32