2

This is a follow-up on this question: Creating bullet-list from string with delimiters

I have a CSV file where I genereate some tables from. Some of those table cells will have items that should be itemized.

MWE:

\documentclass{scrreprt}
\usepackage{csvsimple}
\usepackage{etoolbox}
\DeclareListParser{\ListParser}{|}
\newcommand{\listItems}[1]{
    \parbox{10cm}{
        \begin{itemize}
            \newcommand*{\do}[1]{\item[] ##1}
            \expandafter\ListParser\expandafter{#1}
            \ListParser{#1}
        \end{itemize}
    }
}
\begin{document}
  \csvreader[head to column names]{content/usecases.csv}{}{%
    \begin{table}
      \begin{tabular}{|l|l|}
        \hline
        Name     & \ucname \\ \hline
        Trigger  & \listItems{\trigger} \\ \hline
      \end{tabular}
    \end{table}
  }
\end{document}

CSV Example:

ucname,trigger
test,This is|A test
test2,Barely
test3,No List
test4,List|Again|Here

However, this current code gives me the output of the whole string of \trigger twice, and not delimited.

1 Answer 1

4

You need to expand the list you process twice and only process the list once:

\documentclass{scrreprt}
\usepackage{filecontents}
\begin{filecontents*}{usecases.csv}
ucname,trigger
test,This is|A test
test2,Barely
test3,No List
test4,List|Again|Here
\end{filecontents*}

\usepackage{csvsimple}
\usepackage{etoolbox}
\DeclareListParser{\ListParser}{|}
\newcommand{\listItems}[1]{%
  \parbox{10cm}{%
    \begin{itemize}%
      \renewcommand{\do}[1]{\item[] ##1}
      \expandafter\expandafter\expandafter\ListParser\expandafter\expandafter\expandafter{#1}
    \end{itemize}%
  }%
}
\begin{document}
\csvreader[head to column names]{usecases.csv}{}{%
  \begin{table}
    \begin{tabular}{|l|l|}
      \hline
      Name     & \ucname \\ \hline
      Trigger  & \listItems{\trigger} \\ \hline
    \end{tabular}
  \end{table}
}
\end{document}

enter image description here

12
  • Thanks for explaining this. Why didn't you get bullet points in your itemize list?
    – user30471
    Commented Aug 12, 2014 at 23:48
  • @Andrew: The OP uses \item[] which nullifies the bullet.
    – Werner
    Commented Aug 13, 2014 at 0:11
  • Yeah, thanks, I realised this when I was getting a coffee... Clearly needed it:)
    – user30471
    Commented Aug 13, 2014 at 0:53
  • Hmm, I can't really get it to work properly.. If I type exactly what you posted I get this error: Something's wrong--perhaps a missing \item. }.. Adding back in \ListParser{#1} makes it compile and spit it out both right and wrong at the same time.. (Both the separated string and the complete string as separate bulletpoints)
    – Frederik
    Commented Aug 13, 2014 at 17:00
  • @FrederikNielsen: First of all, you only need one \ListParser command. You probably have two. Make sure that this is the case. I see two in your code snippet in the post.
    – Werner
    Commented Aug 13, 2014 at 17:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .