2

I want to use the csvsimple package to turn a CSV file into a set of paragraphs, using the value of column 1 as a subsubsection header.

I can't see from the documentation any way to do an action only on first occurrence of a value. Is this possible with csvsimple?

COUNTRY,INST,ADDR,PHONE
US,Dept of Justice,Washington DC,123-456/7890
US,Dept of Education,Seattle WA,234-567/8910
UK,Minitrue,London WC,123 456 7890
UK,Miniluv,London EC,234 567 8910

This should generate something like:

\subsubsection{US}
Dept of Justice: Washington DC\\Phone 123-456/7890\par
Dept of Education: Seattle WA\\Phone 234-567/8910\par
\subsubsection{UK}
Minitrue: London WC\\Phone 123 456 7890\par
Miniluv: London EC\\Phone 234 567 8910\par

Is this possible? I was hoping to avoid the complexity of the datatool package, wonderful though it is.

5

When processing the data you can test whether \COUNTRY has changed, e.g. with the ifthen package. address.csv is your sample data.

\documentclass{article}
\usepackage{ifthen}
\usepackage{csvsimple}
\newcommand\COUNTRYlast{}
\newcommand\doaddress%
  {\ifthenelse{\equal{\COUNTRY}{\COUNTRYlast}}%
     {}%
     {\subsubsection{\COUNTRY}%
      \edef\COUNTRYlast{\COUNTRY}%
     }%
   \INST: \ADDR\\Phone \PHONE\par
  }

\parindent0ex
\parskip3pt plus1pt minus 1pt

\begin{document}
\csvreader[head to column names]{address.csv}{}{\doaddress}
\end{document}

results in

enter image description here

  • Indeed I can; many thanks for the example. This mechanism would be a good enhancement... – Peter Flynn Oct 31 '16 at 15:54

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.