Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
2  
Have you tried datatool package? –  Harish Kumar Feb 20 '12 at 10:15
add comment

1 Answer

up vote 5 down vote accepted

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}
share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.