根据文档中的命令生成项目列表和表格

根据文档中的命令生成项目列表和表格

我想在我的整个文档中定义对象,然后从这些对象中评估某些组件。

例子:

\documentclass{minimal}
\newcommand{\requirement}[3]{#1, #2, #3}
\begin{document}

\requirement{Uwe}{2013-10-12}{Remove window}

\requirement{John}{2013-10-13}{Clean window}


\end{document}

我如何生成一个包含所有\requirements需求的表格,其中每个给定的参数都会生成一列?我如何生成所有人的列表。

背景:我想使用 LaTeX 编写业务需求文档,其中需要定义相互关联的对象,例如利益相关者、业务需求和功能需求。我可能能够使用 Perl/Python 等解析文档,但我想开发仅使用 TeX 的解决方案。

答案1

根据布伦特的提示,以下是我目前想到的。

\documentclass{article}
\usepackage{datatool}

\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc} 
\usepackage{booktabs} 
\usepackage{longtable}

\DTLnewdb{stakeholders}

\newcommand{\stakeholder}[2]{%
    \DTLnewrow{stakeholders}
    \DTLnewdbentry{stakeholders}{ID}{#1}
    \DTLnewdbentry{stakeholders}{Name}{#2}
    \par Stakeholder #2 defined!
}

\DTLnewdb{businessreq}

\newcommand{\breq}[5]{%
    \DTLnewrow{businessreq}%
    \DTLnewdbentry{businessreq}{ID}{#1}%
    \DTLnewdbentry{businessreq}{Initiator}{#2}% 
    \DTLnewdbentry{businessreq}{Name}{#3}%
    \DTLnewdbentry{businessreq}{Description}{#4}%   
    \DTLnewdbentry{businessreq}{Priority}{#5}%
    \par BR #3 defined  
}

% http://tex.stackexchange.com/questions/40901/datatool-getting-a-specific-value-given-the-value-of-another-column
\newcommand*{\thestakeholder}{}
\newcommand*{\getstakeholder}[1]{%
  \DTLgetvalueforkey{\thestakeholder}{Name}{stakeholders}{ID}{#1}%
  \thestakeholder
}

\begin{document}

\section{Stakeholder Definition}

\stakeholder{dag}{Dagobert Duck}

\stakeholder{don}{Donald Duck}

\stakeholder{mic}{Mickey Mouse}


\section{Definition of Business Requirements}

\breq{seca}{dag}{Security}{The system must be secured against internal attacks.}{high}

\breq{secb}{don}{Security}{The system must be secured against external attacks.}{medium}

\breq{secc}{mic}{Security}{The system must be secured against internal and external attacks.}{low}

\section{Query the databases}

The stakeholders DB contains \DTLrowcount{stakeholders} stakeholders.

\DTLdisplaydb{stakeholders}\vspace*{1cm}

The Business Requirements database contains \DTLrowcount{businessreq} BRs.

\DTLdisplaydb{businessreq}\vspace*{1cm}

\DTLdisplaylongdb{businessreq}

\section{For-loop with query ID$\rightarrow$Name}

\begin{tabular}{cllp{8cm}l} \toprule
 ID &  Initiator &  Name &  Description &  Priority \\ \midrule
\DTLforeach{businessreq}{%
\ID=ID,\Initiator=Initiator,\Name=Name,\Description=Description,\Priority=Priority}{%
\\
\ID & \getstakeholder{\Initiator} & \Name & \Description & \Priority } \\ \bottomrule
\end{tabular}

\end{document}

在此处输入图片描述

相关内容