I have tried solving this for some time now but can´t seem to find the solution. I have a document that loads data from a CSV-file using Datatool and I have been trying to combine comma separated information from two cells in the CSV-file. The file itself uses ";" as separator and the comma separated information in a single cell uses "," as separator. I have a MWE below to demonstrate what I try to do. I have two problems, the first can be seen with the example using a,b,c and 1,2,3 where I get a "," where I would like to only have a " " separating the items and only \newline separating the lines.
The other problem is that when I try to load the separated list using Datatool all is treated as one item.
The result I want is:
1.2.3 Some data
2.3.4 More data
3.4.5 Even more data
The output from the two examples right now are:
a1
,b2
,c3
1.2.3 Some data
2.3.4,3.4.5 More data,Even more data
This is going to be part of a much bigger document about 650 lines and about 30 packages so if you need a list of packages I use to avoid compability problems I can list them too. I use XeLaTeX for processing tool.
I have been looking at these solutions but still can´t get it right:
Pairing items from two comma-separated lists into a single list
How to iterate over a comma separated list passed through the datatool interface
\begin{filecontents*}{data.csv}
A;B
1.2.3;Some data
2.3.4,3.4.5;More data,Even more data
\end{filecontents*}
\documentclass{article}
\usepackage{expl3}
\usepackage{xparse}
\usepackage{datatool}
\DTLsetseparator{;}%
\ExplSyntaxOn
\clist_new:N \l_doc_tmpa_clist
\clist_new:N \l_doc_tmpb_clist
\seq_new:N \l_doc_tmpa_seq
\msg_new:nnn {doc} {difflen} {two~comma~separated~lists~have~different~length}
\cs_set:Npn \doc_pair_items:nnn #1#2#3 {
\clist_set:Nn \l_doc_tmpa_clist {#2}
\clist_set:Nn \l_doc_tmpb_clist {#3}
\seq_clear:N \l_doc_tmpa_seq
\int_compare:nNnF {\clist_count:N \l_doc_tmpa_clist} = {\clist_count:N \l_doc_tmpb_clist} {
\msg_error:nn {doc} {difflen}
}
\int_step_inline:nn {\clist_count:N \l_doc_tmpa_clist} {
\seq_put_right:Nn \l_doc_tmpa_seq {
\clist_item:Nn \l_doc_tmpa_clist {##1}
#1
\clist_item:Nn \l_doc_tmpb_clist {##1}\newline
}
}
\seq_use:Nn \l_doc_tmpa_seq {,~}
}
\newcommand{\pairitems}[3][=]{
\doc_pair_items:nnn {#1} {#2} {#3}
}
\ExplSyntaxOff
\begin{document}
\pairitems[ ]{a,b,c}{1,2,3}
\DTLloadrawdb{data}{data.csv}
\DTLforeach{data}
{\A=A,
\B=B}{
\pairitems[ ]{\A}{\B}
}
\end{document}
Best Answer
Does this what you need?
Another example, providing two a little bit more generic routines:
and