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.

Frederik
  • 193

1 Answers1

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

Werner
  • 603,163
  • Thanks for explaining this. Why didn't you get bullet points in your itemize list? –  Aug 12 '14 at 23:48
  • @Andrew: The OP uses \item[] which nullifies the bullet. – Werner Aug 13 '14 at 00:11
  • Yeah, thanks, I realised this when I was getting a coffee... Clearly needed it:) –  Aug 13 '14 at 00: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 Aug 13 '14 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 Aug 13 '14 at 17:05
  • @Werner - I have tried the exact code in your answer, and that gives the error above – Frederik Aug 13 '14 at 17:32
  • @FrederikNielsen: I've added my full code to the answer, which includes the use of filecontents for portability. If that doesn't compile for you, then clear all your auxiliary files and try again. If that doesn't work, include \listfiles in your preamble and report back on the file list displayed in your .log - you may have outdated versions of packages. – Werner Aug 13 '14 at 17:39
  • @Werner - File list: http://pastebin.com/uq1Hiyke - It works with the exact example you give, but it does not work when passing through my own CSV file. I get these two errors before it starts going crazy: Missing character: There is no ø in font cmr10! and Missing character: There is no å in font cmr10! – Frederik Aug 13 '14 at 20:26
  • @Werner - Seems like I found the issue. The issue is there when the CSV entry is empty. Is there any way to work around this? – Frederik Aug 13 '14 at 20:43
  • @FrederikNielsen: I don't know what you mean when you say "CSV entry". – Werner Aug 13 '14 at 20:46
  • @Werner - by "CSV Entry" i mean a line in the CSV file like test,This is|A test and test22, where it is the last one that will make this thing fail. – Frederik Aug 13 '14 at 20:52
  • @FrederikNielsen: Ah. An empty list. This means that you're trying to set an itemize without an \item, which is the problem. One would need to test whether the list is empty and condition on typesetting an itemize based on that. I'll write something up (later). – Werner Aug 13 '14 at 20:59