Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to define objects all over my document and later evaluate certain components from these objects.

Example:

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

How can I generate a table of all \requirements where each given argument of the requirement generates one column? How can I generate an list of all persons.

Background: I'd like to use LaTeX to write Business Requirements Documents, where I need to define objects such as stakeholders, business requirements and functional requirements that are connected to each other. I might be able to parse the document with Perl/Python etc. but I'd like to develop a TeX-only solution.

share|improve this question
    
I'd suggest looking at Nicola Talbot's datatool package, which I think will help you with almost all the heavy lifting required to do this. –  Brent.Longborough Oct 12 '13 at 10:53
    
Do you (1) need to externalize the data (e.g., as CSV) or do you (2) just want to collect them for some LaTeX tables within the document. Are these tables (a) printed behind all data acquisition commands in the document or may they (b) also have to be printed beforehand? Inside the tables, shall the data be sorted (I) in the order of definition or (II) by some other sorting criteria (e.g., alphabetically)? –  Daniel Oct 12 '13 at 18:30
    
My intention at this stage is just to collect them in the document, it should be sufficient to print them after the aquisition. Following Brent's advice I managed to put something together that I'll post tomorrow as an update to my question. Looks pretty promising at the moment. Sorting is definitely a requirement, I guess I can easily add this to my code. –  Uwe Ziegenhagen Oct 12 '13 at 18:44
add comment

1 Answer

Based on Brent's hint here is what I have come up so far.

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

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.