# Datatool CSV file with column having multiple rows of a table

I'm using datatool package to load a CSV file and then print the data in it in several parts of a document.

I include a few rows of the CSV file:

"mnemonic"|"args"|"shortdescription"|"description"|"type"|"subtype"|"subdivision"|"family"|"familysubdivision"|"coding"|"operation"|"flags"|"notes"|"assemblertranslationsandvalidations"|"cpuvalidations"
"j"|"$LABEL$"|"Jump"|"Jump to $PC \enspace + \enspace 1 \enspace + \enspace displacement$"|"0"||"0"|"Control"|"0"||"$pc \longleftarrow_{30} pc + 1 + sx_{30}(dis_{26})$"|"None"|"Label is translated to displacement from PC."||
"trap"||"Trap"|"Generate software exception"|"0"||"1"|"Control"|"1"||"$cr[31] \longleftarrow_{1} 1$"|"$cr[31]$"|"Trap will be detected in next fetch step. Being the lowest priority exception cannot be used inside a handler."||
"rfe"||"Return from exception"|"Return from exception to user mode"|"0"||"2"|"Control"|"1"||"$esp \longleftarrow_{5} esp - 1$ \tabularnewline & & $pc \longleftarrow_{30} l_{esp}[29:0]$ \tabularnewline & & $cfg[0] \longleftarrow_{1} 0$"|"$cfg[0]$"|"None"||
"jr"|"$r_{src}$"|"Jump register"|"Jump to address stored in $GPR$"|"1"|"A-1"|"0"|"Control"|"0"||"$pc \longleftarrow_{30} r_{x}[31:2]$"|"None"|"The two LSB's of $r_{x}$ are discarded. These bits should be zero, but no checking is done."||


I'm having problem with the operation field, because, in this field, I want to have a "multiline cell" that I can print in the following way:

...
\section{Listings}
\subsection{Testing}

\DTLforeach*[\DTLiseq{\type}{0}]{isa}{\type=type,\mnemonic=mnemonic,\args=args,\shortdescription=shortdescription,\description=description,\coding=coding,\operation=operation,\flags=flags,\notes=notes}{%
\subsubsection{\mnemonic - \shortdescription}
\label{sssec:\mnemonic}
\begin{tabular}{lcl}
Mnemonic             & : & \texttt{\mnemonic \args} \\
Coding               & : & \texttt{\coding} \\
Operation            & : & \operation \\
Affected flags       & : & \flags \\
Notes                & : & \notes \\
\end{tabular}
}\\
...


Problem is that I get the "&" escaped from that cell, so I cannot print the "operation" correctly. Taking row 3 as an example, the code I need to be outputed would look like this:

...
\subsubsection{rfe - Return from exception}
\label{sssec:rfe}
\begin{tabular}{lcl}
Mnemonic             & : & \texttt{rfe} \\
Coding               & : &  \\
Operation            & : & $esp \longleftarrow_{5} esp - 1$ \\
&   & $pc \longleftarrow_{30} l_{esp}[29:0]$ \\
&   & $cfg[0] \longleftarrow_{1} 0$ \\
Affected flags       & : & $cfg[0]$ \\
Notes                & : & None \\
\end{tabular}
...


Any help on how to achieve this will be appreciated!

• Would you be open to supplying the input in a different way? That is, perhaps only supplying stuff \\ stuff \\ stuff for items that have multiple rows? Also, could you rewrite your code snippets into a single compilable format that we can copy-and-paste-and-compile? It would help if you provide the means with which you set up your database... – Werner Dec 22 '15 at 20:10
• Using your input, I get the expected output... – Werner Dec 22 '15 at 20:18
• Ok! That's it! I replaced \tabularnewline with \\ and it worked!!! I've been doing a lot of testing and replaced it backwards but it seems that I had other erros! – Luciano César Natale Dec 22 '15 at 20:26

The following produces the expected output (for row 3):

\documentclass{article}

\usepackage{datatool,filecontents}

\begin{filecontents*}{inputdata.csv}
"mnemonic"|"args"|"shortdescription"|"description"|"type"|"subtype"|"subdivision"|"family"|"familysubdivision"|"coding"|"operation"|"flags"|"notes"|"assemblertranslationsandvalidations"|"cpuvalidations"
"j"|"$LABEL$"|"Jump"|"Jump to $PC \enspace + \enspace 1 \enspace + \enspace displacement$"|"0"||"0"|"Control"|"0"||"$pc \longleftarrow_{30} pc + 1 + sx_{30}(dis_{26})$"|"None"|"Label is translated to displacement from PC."||
"trap"||"Trap"|"Generate software exception"|"0"||"1"|"Control"|"1"||"$cr[31] \longleftarrow_{1} 1$"|"$cr[31]$"|"Trap will be detected in next fetch step. Being the lowest priority exception cannot be used inside a handler."||
"rfe"||"Return from exception"|"Return from exception to user mode"|"0"||"2"|"Control"|"1"||"$esp \longleftarrow_{5} esp - 1$ \\ $pc \longleftarrow_{30} l_{esp}[29:0]$ \\ $cfg[0] \longleftarrow_{1} 0$"|"$cfg[0]$"|"None"||
"jr"|"$r_{src}$"|"Jump register"|"Jump to address stored in $GPR$"|"1"|"A-1"|"0"|"Control"|"0"||"$pc \longleftarrow_{30} r_{x}[31:2]$"|"None"|"The two LSB's of $r_{x}$ are discarded. These bits should be zero, but no checking is done."||
\end{filecontents*}

\begin{document}

\DTLsetseparator{|}

\section{Listings}
\subsection{Testing}

\DTLforeach*[\DTLiseq{\type}{0}]{isa}{
\type=type,
\mnemonic=mnemonic,
\args=args,
\shortdescription=shortdescription,
\longdescription=description,
\coding=coding,
\operation=operation,
\flags=flags,
\notes=notes}{%
\subsubsection{\mnemonic - \shortdescription}
\label{sssec:\mnemonic}
\begin{tabular}{lcl}
Mnemonic             & : & \texttt{\mnemonic \args} \\
Coding               & : & \texttt{\coding} \\
Operation            & : & \begin{tabular}[t]{@{}l@{}} \operation \end{tabular} \\
Affected flags       & : & \flags \\
Notes                & : & \notes \\
\end{tabular}
}

\end{document}


Note that I've placed the \operation in a [t]op-aligned tabular (without column separation), which allows for the removal of the embedded & & inside your inputdata.csv. Also, you should be able to use \\ and \tabularnewline interchangeably.