数据工具 CSV 文件,其中的列包含表格的多行

数据工具 CSV 文件,其中的列包含表格的多行

我正在使用datatool包加载 CSV 文件,然后在文档的几个部分打印其中的数据。

我包含了 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 $ \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."||

我在操作字段方面遇到了问题,因为在这个字段中,我想要一个“多行单元格”,可以按以下方式打印:

...
\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}
}\\
...

问题是我从该单元格中转义了“&”,因此无法正确打印“操作”。以第 3 行为例,我需要输出的代码如下所示:

...
\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}
...

任何有关如何实现这一目标的帮助都将不胜感激!

答案1

以下产生预期的输出(对于第 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{|}
\DTLloaddb{isa}{inputdata.csv}

\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}

请注意,我已将 放置在op-aligned\operation中(没有列分隔),这样可以删除内部嵌入的。此外,您应该能够互换使用和。[t]tabular& &inputdata.csv\\\tabularnewline

相关内容