% \iffalse meta-comment
% A class for preparing FP7 proposals for collaborative projects
%
% Copyright (c) 2007 Michael Kohlhase, all rights reserved
%
% This file is distributed under the terms of the LaTeX Project Public
% License from CTAN archives in directory  macros/latex/base/lppl.txt.
% Either version 1.0 or, at your option, any later version.
%
% The development version of this file can be found at
% $HeadURL: https://svn.kwarc.info/repos/kwarc/doc/macros/euproposal/euproposal.dtx $
% \fi
% 
% \iffalse
%<cls>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<cls>\ProvidesClass{euproposal}[2007/06/04 v0.3 EU Proposal]
%<*driver>
\documentclass[twoside]{ltxdoc}
\DoNotIndex{\def,\long,\edef,\xdef,\gdef,\let,\global}
\DoNotIndex{\begin,\AtEndDocument,\newcommand,\newcounter,\stepcounter}
\DoNotIndex{\immediate,\openout,\closeout,\message,\typeout}
\DoNotIndex{\section,\scshape,\arabic}
\EnableCrossrefs
%\CodelineIndex
%\OnlyDescription
\RecordChanges
\usepackage{textcomp,url,float,a4wide}
\usepackage[show]{ed}
\usepackage[fancyhdr,today,draft]{svninfo}
\pagestyle{fancyplain}\fancyhead[RE,LO]{\leftmark}\fancyhead[LE,RO]{\thepage}
\makeindex
\floatstyle{boxed}
\newfloat{exfig}{thp}{lop}
\floatname{exfig}{Example}
\def\subversion{\sc{Subversion}}
\begin{document}
\svnInfo $Id: euproposal.dtx 13984 2007-11-04 14:50:45Z kohlhase $
\svnKeyword $HeadURL: https://svn.kwarc.info/repos/kwarc/doc/macros/euproposal/euproposal.dtx $
\DocInput{euproposal.dtx}
\end{document}
%</driver>
% \fi
% 
%\iffalse\CheckSum{181}\fi
% 
% \changes{v0.3}{2007/06/04}{staff effort table finally works}
% \changes{v0.2}{2007/05/09}{First Version with Documentation}
% \changes{v0.1}{2007/05/07}{used in the SciML proposal}
% 
% \GetFileInfo{euproposal.cls}
% 
% \MakeShortVerb{\|}
% \title{Preparing FP7 Proposals in {\LaTeX} with 
%   {\tt{eurpoposal.cls}}\thanks{Version {\fileversion} 
%     (last revised {\filedate})}} 
%    \author{Michael Kohlhase\\
%      Computer Science, Jacobs University Bremen\\
%      \url{http://kwarc.info/kohlhase}}
% \maketitle
%
% \begin{abstract}
%   The |euproposal| class supports many of the specific elements of a Framework 7
%   Proposal. It is optimized towards collaborative projects. The package comes with an
%   extensive example (a fake EU proposal) that shows all elements in action. 
% \end{abstract}
%
% \section{Introduction}\label{sec:intro}
%
%   Writing grant proposals is a collaborative effort that requires the integration of
%   contributions from many individuals. The use of an ASCII-based format like {\LaTeX}
%   allows to coordinate the process via a source code control system like
%   {\sc{Subversion}}, allowing the proposal writing team to concentrate on the contents
%   rather than the mechanics of wrangling with text fragments and revisions. 
% 
%   The |euproposal| class supports many of the specific elements of Part B of a Framework
%   7 Proposal. It comes with an example proposal |euproposal-propB.tex|, which shows the
%   usage of the class in action, it is intended as a template for your proposal. 
% 
% \section{The User Interface}\label{sec:user-interface}
% 
% \subsection{Package Options}\label{sec:options}
%
% As usual in {\LaTeX}, the package is loaded by
% |\documentclass[|\meta{options}|]{euproposal}|, where |[|\meta{options}|]| is optional
% and gives a comma separated list of options.  Currently the |euproposal| package only
% takes three options |submit|, |public|, and |eudraft| where |submit| is the default
% case, so that |\documentclass{euproposal}|, is equivalent to
% |\documentclass[submit]{euproposal}|.\ednote{continue}
%
% \subsection{Proposal Metadata and Title page}\label{sec:metadata}
% 
% The metadata of the proposal can be specified in the {\LaTeX} preamble using the macros
% described below. All of these take one argument: the value. A typical preamble is given
% in Figure~\ref{fig:preamble}.
% \begin{exfig}
%   \begin{verbatim}
% \documentclass[11pt,eudraft]{euproposal}
%
% \def\ipower{{\sc{iPoWr}}}
% \ProposalAcronym\ipower
% \ProposalTitle{{\underline{I}ntellitent} {\underline{P}r\underline{o}sal} 
%                {\underline{Wr}iting}}
% \ProposalCall{ICT Call 1: FP7-???-200?-?}
% \ProposalInstrument{Large-scale Integrating Project (IP) Proposal}
% \ProposalTopics{???-200?.?.? Intelligent Proposal Writing}
% \ProposalCoordinatorName{Prof. Dr. Michael Kohlhase}
% \ProposalCoordinatorEmail{m.kohlhase@jacobs-university.de}
% \ProposalCoordinatorTelFax{(+49) 421 200-3140/-493140}

% \ProposalCoordinator{JACU}{Jacobs University Bremen}{D}
% \ProposalPartner{EFO}{European Future Office}{NL}
% \ProposalPartner{BAR}{Universit\`e de BAR}{F}
% \ProposalPartner{BAZ}{BAZ International Ltd}{UK}
% \end{verbatim}
%   \caption{A typical proposal preamble}\label{fig:preamble} 
% \end{exfig}
%
% \DescribeMacro{\Proposal*} The |ProposalAcronym| is used to specify the acronym, this
% will appear in the headings and the title page.  |ProposalTitle| specifies the title of
% the proposal, and |ProposalCall| is used to identify the call the proposal addresses. It
% is usuall a string of the form |ICT Call 1: FP7-???-200?-?|. An overview over open calls
% can be found at \url{http://cordis.europa.eu/fp7/dc/index.cfm}. |ProposalInstrument| It
% is either ``Large-scale Integrating Project (IP) Proposal'', or\ednote{find out the
%   others} |ProposalTopics| specifies the specific objectives in the call this proposal
% addresses. These are specified in the ``call fiche'' that can be obtained from the URL
% above. They usually have a form like |???-200?.?.? Intelligent Proposal Writing|.
% Finally, |ProposalCoordinatorName|, |ProposalCoordinatorEmail|, and
% |ProposalCoordinatorTelFax| are used to specify the contact details of the project
% coordinator. 
% 
% \DescribeEnv{titlepageabstract} The metadata is used to assemble the title page of the
% proposal, using the abstract which occupies the body of the |titlepageabstract|
% environment.\ednote{can we count letters in the abstract and put out a warning if it is
%   too long?} 
% 
% \DescribeMacro{\svnInfo}\DescribeMacro{\svnKeyword} If we are using {\subversion} for
% collaborating on the proposal, we should add the two lines immediately below the
% |\begin{document}| (they must be after). The |$ID| and |$HeadURL| keywords are expanded
%   by {\subversion} whenever the document is updated or committed, if the relevant
%   properties are set. To set the properties use |svn propset svn:keywords "URL Id"| on
%   the command line or the appropriate clicks in your subversion client. The information
%   will be displayed in the footer line (if the |eudraft| option is set). All dependent
%   files in the proposal can have their own |svninfo| declarations, leading to per-file
%   information in the footer line. 
% 
% Finally, the last two lines set up the table of contents and the 
% 
% \begin{exfig}
% \begin{verbatim}
% \begin{document}
% \svnInfo $Id: euproposal.dtx 13984 2007-11-04 14:50:45Z kohlhase $
% \svnKeyword $HeadURL: https://svn.kwarc.info/repos/kwarc/doc/macros/euproposal/euproposal.dtx $
% \begin{titlepageabstract}
%   Writing grant proposals is a collaborative effort that requires the integration of
%   contributions from many individuals. The use of an ASCII-based format like {\LaTeX}
%   allows to coordinate the process via a source code control system like
%   {\sc{Subversion}}, allowing the proposal writing team to concentrate on the contents
%   rather than the mechanics of wrangling with text fragments and revisions.
% \end{titlepageabstract}
% \setcounter{tocdepth}{1}{\small\tableofcontents}
% \end{verbatim}
% \caption{Typical Front Matter of a Proposal}\label{fig:frontmatter}
% \end{exfig}
%
% \subsection{Work Packages and Work Groups}
% 
% \DescribeEnv{workplan}
% 
% The |workplan| environment groups the work package and work group descriptions and
% handles the accounting. In particular, the environment writes the file
% {\meta{proposal}.delivs} file which is used to generate the delivrables
% table.\ednote{say something about sorting}
% 
% \DescribeEnv{workpackage}\DescribeEnv{workgroup}
% The |workpakcage| and |workgroup| environments are closely related, so we will describe
% them together. 
%
% \DescribeMacro{id} The |id| key is used to specify a label for crossreferencing the work
% package or work group, it must be document-unique.
%
% \DescribeMacro{title}\DescribeMacro{short} The |title| and |short| keys are used for the
% work package/group title. The short title is used in tables and should not be longer
% than 15 characters.
%
% \DescribeMacro{type} The |type| key specifies the activity type of the work package:
% |RTD| = Research and technological development (including any activities to prepare for
% the dissemination and/or exploitation of project results, and coordination activities);
% |DEM| = Demonstration; |MGT| = Management of the consortium; |OTHER| = Other specific
% activities, if applicable in this call.
% 
% \DescribeMacro{\meta{partner}} For each partner, the |euproposal| package generates a
% key that is identical to the short name of the partner. This can be used to specify the
% person months that the partner spends on this work package (the value for work groups is
% automatically computed (remember to run {\LaTeX} twice for this)).
% 
% \DescribeMacro{lead} The |lead| key specifies the work package or work group lead, the
% value of this feature should be the short name of the respective partner.
%
% \DescribeMacro{start}\DescribeMacro{duration} The |start| and |duration| keys are used
% to specify the start month and duration (in months) of the work package
%
% \StopEventually{\newpage\PrintIndex\newpage\PrintChanges\ednotemessage}
%
% \section{The Implementation} 
%
% We first set up the options for the package. 
% 
% \subsection{Package Options}\label{impl:options}
% 
%<*cls>
%    \begin{macrocode}
\newif\ifsubmit\submittrue
\newif\ifpublic\publicfalse
\DeclareOption{eudraft}{\submitfalse\PassOptionsToPackage{draft}{svninfo}}
\DeclareOption{submit}{\submittrue\PassOptionsToPackage{hide}{ed}}
\DeclareOption{public}{\publictrue}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{report}}
\ProcessOptions
%    \end{macrocode}
% 
%    Then we load the packages we make use of
% 
%    \begin{macrocode}
\LoadClass[a4paper]{report}
\RequirePackage{textcomp}
\RequirePackage{amssymb}
\RequirePackage{url}
\RequirePackage{lscape}
\RequirePackage{longtable}
\RequirePackage{graphicx}
\RequirePackage{calc}
\RequirePackage{colortbl}
\RequirePackage{xcolor}
\RequirePackage[show]{ed}
\RequirePackage[today,fancyhdr]{svninfo}
\RequirePackage{keyval}
\RequirePackage{array}
\RequirePackage{eurosym}
\RequirePackage{hyperref}
%    \end{macrocode}
%    
%    And we set up the appearance of the proposal. We use the |\part| mechanism to show
%    that we are in part B of the proposal.
% 
%    \begin{macrocode}
\def\thepart{\Alph{part}}
\setcounter{part}{2}
\def\thechapter{\thepart.\arabic{chapter}}
\def\tableofcontents{%
    \chapter*{\contentsname
        \@mkboth{\MakeUppercase{\contentsname}}%
                {\MakeUppercase{\contentsname}}}%
    \@starttoc{toc}}
%    \end{macrocode}
%
%    \begin{macrocode}
\newenvironment{titlepageabstract}
{\begin{center}
  {\LARGE \eu@instrument}\\[.2cm]
  {\large \eu@call}\\[.4cm]
  {\LARGE\bf\eu@title}\\[.3cm]
  {\LARGE Acronym: {\eu@acro}}\\[.2cm]
\end{center}
{\large\bf{Date of Preparation: \today}}\\[1em]
\PartnerTable\\[.5cm]
\begin{large}
  \begin{description}
  \item[Work program topics  addressed:] \eu@topics
  \item[Coordinator:] \euc@name
  \item[e-mail:] {\url{\euc@email}}
  \item[tel/fax:] \euc@telfax
  \item [Proposal Abstract:]\small\sf}
{\end{description}\end{large}\newpage}
%
% \subsection{Proposal Metadata}
%  
% we define the metadata declaration macros
%    \begin{macrocode}
\def\ProposalAcronym#1{\def\eu@acro{#1}}
\def\ProposalTitle#1{\def\eu@title{#1}}
\def\ProposalCall#1{\def\eu@call{#1}}
\def\ProposalTopics#1{\def\eu@topics{#1}}
\def\ProposalInstrument#1{\def\eu@instrument{#1}}
\def\ProposalCoordinatorName#1{\def\euc@name{#1}}
\def\ProposalCoordinatorEmail#1{\def\euc@email{#1}}
\def\ProposalCoordinatorTelFax#1{\def\euc@telfax{#1}}
%    \end{macrocode}
% and the default values
%    \begin{macrocode}
\def\eu@acro{ACRONYM} 
\def\eu@title{Proposal Title} 
\def\eu@call{ICT Call ?: FP7-???-200?-?}
\def\eu@instrument{Proposal Instrument (e.g. IP)} 
\def\eu@topics{???-200?.?.? Topic1, ???-200?.?.? Topic2} 
\def\euc@name{Dr. Great Coordinatorn}
\def\euc@email{g.coordinator@jacobs-university.de}
\def\euc@telfax{(+??) ??? ???? ???/-???}
%    \end{macrocode}
%
%    \begin{macrocode}
\fancyhead[RE,LO]{\eu@acro}\fancyhead[LE,RO]{page~\thepage~of~\thelastpage}
\pagestyle{fancyplain}
%    \end{macrocode}
%    
% we want numbered subsubsections
%    \begin{macrocode}
\setcounter{secnumdepth}{3}
%    \end{macrocode}
%    
%    \begin{macrocode}
\AtEndDocument{%
  \clearpage
  \count@\c@page
  \advance\count@\m@ne
  \edef\@tempa{\the\count@}%
  \ifx\@tempa\thelastpage
  \else
    \ClassWarningNoLine{euproposal}{Last page changed: Rerun LaTeX}%
  \fi
  \immediate\write\@auxout{%
    \gdef\string\thelastpage{\the\count@}}}
\def\thelastpage{??}
%    \end{macrocode}
%
% \subsection{Work Packages and Work Groups}
%    
% \begin{macro}{\eu@write@...}
%    This macro writes an |\eu@def| commands to the current aux and delivrables file. 
%    \begin{macrocode}
\def\eu@write@aux#1#2#3#4{\protected@write\@auxout{}{\string\eu@def{#1}{#2}{#3}{#4}}}
\def\eu@write@delivs#1#2#3#4{\protected@write\@auxout{}{\string\eu@def{#1}{#2}{#3}{#4}}}
%    \end{macrocode}
% \end{macro}
% We first define keys for  work groups. 
%    \begin{macrocode}
\define@key{wg}{id}{\def\wg@id{#1}}
\define@key{wg}{title}{\def\wg@title{#1}}
\define@key{wg}{lead}{\def\wg@lead{#1}}
\define@key{wg}{short}{\def\wg@short{#1}}
%    \end{macrocode}
% work packages have similar ones. 
%    \begin{macrocode}
\define@key{wp}{id}{\def\wp@id{#1}}
\define@key{wp}{duration}{\def\wp@duration{#1}}
\define@key{wp}{start}{\def\wp@start{#1}}
\define@key{wp}{title}{\def\wp@title{#1}}
\define@key{wp}{type}{\def\wp@type{#1}}
\define@key{wp}{lead}{\def\wp@lead{#1}}
\define@key{wp}{short}{\def\wp@short{#1}}
%    \end{macrocode}
%    Then we introduce the partner declarations; first we initialize the partner counter
%    and some accumulator macros for the partners table, and the first two lines in the
%    WP/WG descriptions.
%    \begin{macrocode}
\newcounter{partner}
\def\wpg@partners{}\def\wp@pms{}\def\wg@pms{}\def\eu@partner@table{}
%    \end{macrocode}
%    The next macro is an internal one that can be specialized for the coordinator
%    \begin{macrocode}
\def\proposal@partner#1#2#3{% short, long, nationality
\stepcounter{partner}
\newcounter{wg@#1@effort}[wg]
\newcounter{total@#1@effort}
\eu@write@aux{partner}{#1}{number}{\thepartner}
\eu@write@aux{partner}{#1}{short}{#1}
\eu@write@aux{partner}{#1}{long}{#2}
\eu@write@aux{partner}{#1}{nationality}{#3}
\define@key{wp}{#1}{\expandafter\def\csname wp@#1\endcsname{##1}}
\g@addto@macro\eu@partner@table{\euref{partner}{#1}{number} & {\euref{partner}{#1}{short}} & #2 & #3\\\hline}}
%    \end{macrocode}
%    With this, the declarations for the partners are very simple. The one for the
%    coordinator initializes the relevant lists
%    \begin{macrocode}
\def\ProposalCoordinator#1#2#3{\proposal@partner{#1}{#2 (coordinator)}{#3}
\gdef\eu@partners{#1}
\g@addto@macro\wpg@partners{\euref{partner}{#1}{number}: \euRef{partner}{#1}{short}}
\g@addto@macro\wp@pms{\wp@pm{#1}}\g@addto@macro\wg@pms{\wg@pm{#1}}}
%    \end{macrocode}
%    while the one for the partners adds commas.
%    \begin{macrocode}
\def\ProposalPartner#1#2#3{\proposal@partner{#1}{#2}{#3}
\g@addto@macro\eu@partners{,#1}
\g@addto@macro\wpg@partners{&\euref{partner}{#1}{number}: \euRef{partner}{#1}{short}}
\g@addto@macro\wp@pms{&\wp@pm{#1}}\g@addto@macro\wg@pms{&\wg@pm{#1}}}
%    \end{macrocode}
%    One of the side effects is that we can generate the partner table from the material
%    accumulated in the |\eu@partners| macro.
%    \begin{macrocode}
\def\PartnerTable{\begin{tabular}{|l|l|p{11cm}|l|}\hline
\# & Abbr. & Name &  Country\\\hline\hline
\eu@partner@table
\end{tabular}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\wg@label#1{WG {#1}}
\def\wp@label#1{WP {#1}}
\def\wg@mk@title#1{Work Group {#1}}
\def\wp@mk@title#1{Work Package {#1}}
%    \end{macrocode}
% 
%    \begin{macrocode}
\newcounter{wg}
\newcounter{wp}[wg]
\newcounter{deliv}[wp]
\newcounter{wpgno}
%    \end{macrocode}
% The next macro sets up the counters for the effort tables and writes the efforts to the
% aux file 
%    \begin{macrocode}
\def\wp@efforts{\@for\@I:=\eu@partners\do{
    \def\@effort{\@ifundefined{wp@\@I}{0}{\csname wp@\@I\endcsname}}
  \addtocounter{wg@\@I @effort}{\@effort}
  \addtocounter{total@\@I @effort}{\@effort}
  \eu@write@aux{\wp@id}{\@I}{effort}{\@effort}}}
%    \end{macrocode}
% write the workpackage/group-specific metadata to the aux file
%    \begin{macrocode}
\def\wpg@write@md#1{%
\eu@write@aux{#1}{\csname #1@id\endcsname}{label}{\csname #1@label\endcsname\thewg}
\eu@write@aux{#1}{\csname #1@id\endcsname}{number}{\csname the#1\endcsname}
\eu@write@aux{#1}{\csname #1@id\endcsname}{title}{\csname #1@title\endcsname}
\eu@write@aux{#1}{\csname #1@id\endcsname}{lead}{\csname #1@lead\endcsname}
\eu@write@aux{#1}{\csname #1@id\endcsname}{short}{\csname #1@short\endcsname}}
%    \end{macrocode}
% write the workpackage-specific metadata to the aux file
%    \begin{macrocode}
\def\wp@write@md{%
\eu@write@aux{wp}{\wp@id}{duration}{\wp@duration}
\eu@write@aux{wp}{\wp@id}{start}{\wp@start}
\eu@write@aux{wp}{\wp@id}{type}{\wp@type}}
%    \end{macrocode}
% show the line with all the efforts in the work package
%    \begin{macrocode}
\def\wpg@efforts@line#1{\renewcommand{\tabcolsep}{.2em}
  \begin{tabular}{|*{\thepartner}{c|}}
    \wpg@partners\\\hline
    \csname #1@pms\endcsname\end{tabular}}
%    \end{macrocode}
% update the list of the work packages and groups for the staff efforts table
%    \begin{macrocode}
\def\update@wps#1{\@ifundefined{wg@wps}{\xdef\wg@wps{#1}}{\xdef\wg@wps{\wg@wps,#1}}}
\def\update@wgs#1{\@ifundefined{eu@wgs}{\xdef\eu@wgs{#1}}{\xdef\eu@wgs{\eu@wgs,#1}}}
%    \end{macrocode}
% with these it is now relatively simple to define the interface macros
% \begin{environment}{wpd}
%    \begin{macrocode}
\newenvironment{wpd}[1][]
{\setkeys{wp}{#1}\stepcounter{wp}\stepcounter{wpgno}
\wpg@write@md{wp}\wp@write@md\wp@efforts\update@wps{\wp@id}
\xdef\wp@nums{\wp@nums &\thewg.\thewp}
\begin{center}
\begin{tabular}{||p{\textwidth-15pt}||}\hline\hline
  {\large\textbf\wp@mk@title{\thewg.\thewp}}: {\eu@target{wp}{\wp@id}{\wp@title}}\\\hline
  \wpg@efforts@line{wp}\\\hline}
{\end{tabular}\end{center}}
%    \end{macrocode}
%  \end{environment}
%  the environment for work groups is even simpler, since we have less to do 
% \begin{environment}{wgd}
%    \begin{macrocode}
\newenvironment{wgd}[1][]
{\begin{center}
\begin{tabular}{||p{\textwidth-15pt}||}\hline\hline
  {\large\textbf\wg@mk@title\thewg}: {\eu@target{wg}{\wg@id}{\wg@title}}\\\hline
  \wpg@efforts@line{wg}\\\hline}
{\end{tabular}\end{center}}
%    \end{macrocode}
% \end{environment}
%
% \begin{environment}{wgd}
%    \begin{macrocode}
\newenvironment{workgroup}[1][]
{\setkeys{wg}{#1}\stepcounter{wg}\stepcounter{wpgno}\wpg@write@md{wg}\def\wp@nums{}
\let\wg@wps=\relax\update@wgs{\wg@id}\def\wp@nums{}
\eu@write@aux{wg}{\wg@id}{num}{\thewg}}
{\eu@write@aux{wg}{\wg@id}{wps}{\wg@wps}
 \eu@write@aux{wg}{\wg@id}{wpnums}{\wp@nums}
 \@for\@I:=\eu@partners\do{
    \eu@write@aux{\wg@id}{\@I}{effort}{\csname thewg@\@I @effort\endcsname}}}
%    \end{macrocode}
% \end{environment}
% The following macro displays the effort of a partner
%    \begin{macrocode}
\def\p@pm#1{\@ifundefined{wp@#1}{}{\csname wp@#1\endcsname}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\wpg@gray#1{\def\@test{#1}\ifx\@test\wpg@lead\cellcolor{lightgray}{#1}\else{#1}\fi}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\wp@pm#1{\wpg@gray{\p@pm{#1}}}
\def\wg@pm#1{\wpg@gray{\euref{\wg@id}{#1}{effort}}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\wpg@pa#1{\wpg@gray{\euRef{partner}{#1}{short}}}
%    \end{macrocode}
%
% \subsection{Hyperinking} 
%
% \begin{macro}{\eu@target}
%    
%    \begin{macrocode}
\def\eu@target#1#2#3{\hypertarget{#1@#2@target}{#3}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\eu@def}
%    
%    \begin{macrocode}
\def\eu@def#1#2#3#4{\expandafter\gdef\csname #1@#2@#3\endcsname{#4}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\euref}
%    
%    \begin{macrocode}
\def\euref#1#2#3{\@ifundefined{#1@#2@#3}%
{\protect\G@refundefinedtrue\@latex@warning{#3 for #1 #2 undefined}??}%
{\csname #1@#2@#3\endcsname}}%
\def\euref@aux#1#2#3{\@ifundefined{#1@#2@#3}{??}{\csname #1@#2@#3\endcsname}}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\euref}
%    
%    \begin{macrocode}
\def\euRef#1#2#3{\@ifundefined{#1@#2@#3}%
{\protect\G@refundefinedtrue\@latex@warning{#3 for #1 #2 undefined}??}%
{\hyperlink{#1@#2@target}{\csname #1@#2@#3\endcsname}}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\eu@lead}
%    
%    \begin{macrocode}
\def\eu@lead#1{\@ifundefined{wp@#1@lead}%
{\protect\G@refundefinedtrue\@latex@warning{lead for WP #1 undefined}??}%
{\edef\@partner{\csname wp@#1@lead\endcsname}\euRef{partner}{\@partner}{short}}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\wpline}
%    
%    \begin{macrocode}
\def\wpline#1{\euRef{wp}{#1}{label} & 
              \euref{wp}{#1}{title} & 
              \eu@lead{#1} & 
              \euref{wp}{#1}{start} & 
              \euref{wp}{#1}{duration} &
              \euref{wp}{#1}{type} \\\hline} 
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\wgline}
%    
%    \begin{macrocode}
\def\wgline#1{\cellcolor{lightgray}{\euRef{wg}{#1}{label}} & 
  \multicolumn{5}{c|}{\cellcolor{lightgray}{\euref{wg}{#1}{title}}}  \\\hline} 
%    \end{macrocode}
% \end{macro}
% 
% \begin{environment}{wptable}
%    
%    \begin{macrocode}
\newenvironment{wptable}{\begin{footnotesize}\begin{tabular}{|c|l|l|l|l|l|}\hline
  \textbf{WG/WP}&
  \textbf{Title}& 
  \textbf{Lead}&
  \textbf{Start}&
  \textbf{Dur.}& 
  \textbf{Type}\\\hline\hline}
{\end{tabular}\end{footnotesize}}
%    \end{macrocode}
% \end{environment}
% 
% \begin{macro}{\wpobjectives}
%    
%    \begin{macrocode}
\def\wpobjectives{\textbf{Objectives:} }
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\wpdescription}
%    
%    \begin{macrocode}
\def\wpdescription{\textbf{Description of Work:} }
%    \end{macrocode}
% \end{macro}
% \begin{environment}{wpdelivs}
%    
%    \begin{macrocode}
\newenvironment{wpdelivs}{\vspace*{-1em}\begin{description}}
{\end{description}}
%    \end{macrocode}
% \end{environment}
% 
% \begin{macro}{\wgdelivs}
%    
%    \begin{macrocode}
\newenvironment{wgdelivs}{\setcounter{deliv}{0}\vspace*{-1em}\begin{description}}
{\end{description}}
%    \end{macrocode}
% \end{macro}
% The next macro is generally useful to put a comment at the end of the line, possibly
% making a new one if there is not enough space.
% \begin{macro}{\lec}
%    \begin{macrocode}
\def\lec#1{\strut\hfil\strut\null\nobreak\hfill\hbox{$\leadsto$#1}\par}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\wpdeliv}
%    We first define the keys
%    \begin{macrocode}
\define@key{deliv}{id}{\def\deliv@id{#1}}
\define@key{deliv}{due}{\def\deliv@due{#1}}
\define@key{deliv}{dissem}{\def\deliv@dissem{#1}}
\define@key{deliv}{type}{\def\deliv@type{#1}}
\define@key{deliv}{miles}{\def\deliv@miles{#1}}
%    \end{macrocode}
%    The |\wpdeliv| macro cycles over the due dates and generates the relevant entries
%    into the delivrables file\ednote{also generate the makefile} 
%    \begin{macrocode}
\newcommand{\wpg@deliv}[3]{% keys, title, type
\let\deliv@miles=\relax% clean state
\def\@type{#3}\def\@wp{wp}% set up ifx
\def\wpg@id{\csname #3@id\endcsname}
\setkeys{deliv}{#1}\stepcounter{deliv}% set state
\ifx\@type\@wp\def\current@label{D\thewg.\thewp.\thedeliv}
\else\def\current@label{D\thewg.\thedeliv}\fi
\eu@write@aux{deliv}{\wpg@id\deliv@id}{label}{\current@label}
\eu@write@aux{deliv}{\wpg@id\deliv@id}{title}{#2}
\@ifundefined{deliv@due}{}{%
\@for\@I:=\deliv@due\do{\protected@write\wpg@delivs{}{\string\delivrable% 
{\@I}% due date
{\current@label}% label
{\@ifundefined{deliv@id}{\protect\G@refundefinedtrue\@latex@warning{key 'id' for Deliv #1
      undefined}??}{\wpg@id:\deliv@id}}% id
{\@ifundefined{deliv@dissem}{\protect\G@refundefinedtrue\@latex@warning{key 'dissem' for
      Deliv #1 undefined}??}{\deliv@dissem}}% dissemination level
{\@ifundefined{deliv@type}{\protect\G@refundefinedtrue\@latex@warning{key 'type' for Deliv
      #1 undefined}??}{\deliv@type}}% type
{#2}}}}%
\item[\current@label: (Month \deliv@due)]\eu@target{deliv}{\wpg@id\deliv@id}{#2}
\@ifundefined{deliv@miles}{}{% print the milestones and update their delivrables
\let\m@sep=\relax% do not print the separator the first time round
\lec{\@for\@I:=\deliv@miles\do{% Iterate over the milestones mentioned
\m@sep\euRef{mile}{\@I}{label}% print the milestone reference
\let\m@sep=,}}%set the separator for the next times
\def\d@sep{,}
 \@for\@I:=\deliv@miles\do{% Iterate over the milestones mentioned
 \expandafter\ifx\csname\@I delivs\endcsname\relax% Check that the miles@delivs is empty
  {\expandafter\xdef\csname\@I delivs\endcsname{\wpg@id\deliv@id}}% if so, skip the separator
   \else\expandafter\xdef\csname\@I delivs\endcsname{\csname\@I delivs\endcsname\d@sep\wpg@id\deliv@id}\fi%if not add it
}
}}
%    \end{macrocode}
%    \ednote{in the last three lines, I would like to extend all the milestones it
%      references by this delivrable, but somehow it does not work yet (leads to a
%      circular definition of <mile>@delivs)}
% \end{macro}
%
% Now, we only need to instantiate
% 
% \begin{macro}{\wgdeliv}
%    \begin{macrocode}
\newcommand{\wgdeliv}[2][]{\wpg@deliv{#1}{#2}{wg}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\wpdeliv}
%    \begin{macrocode}
\newcommand{\wpdeliv}[2][]{\wpg@deliv{#1}{#2}{wp}}
%    \end{macrocode}
% \end{macro}
% 
% \begin{environment}{workplan}
%    the macros above should actually only be defined in the |workplan|
%    environment\ednote{use the envisioned two-stop refactoring to make the actual
%    definitions short enough to put into the environment}
%    \begin{macrocode}
\newwrite\wpg@delivs
\newenvironment{workplan}%
{\immediate\openout\wpg@delivs=\jobname.delivs\setcounter{wg}{-1}}%
{\closeout\wpg@delivs%
\@for\@I:=\mile@stones\do{\eu@write@aux{mile}{\@I}{delivs}{\csname\@I delivs\endcsname}}
\@for\@I:=\eu@partners\do{
    \eu@write@aux{eu}{\@I}{totaleffort}{\csname thetotal@\@I @effort\endcsname}}
\eu@write@aux{eu}{workplan}{wgs}{\eu@wgs}}
%    \end{macrocode}
% \end{environment}
%
% \begin{macro}{\milestone}
%    \begin{macrocode}
%    create a new milestone, initialize its delivrables accumulator macro, set up
%    hyperlinking, and extend the milestones list. 
\newcounter{milestone}
\def\milestone#1{\stepcounter{milestone}
\eu@write@aux{mile}{#1}{label}{M\themilestone}
\eu@target{mile}{#1}{M\themilestone}
\@ifundefined{mile@stones}{\gdef\mile@stones{#1}}{\g@addto@macro\mile@stones{,#1}}}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\milesfor}
%    the due date is the first argument to facilitate sorting
%    \begin{macrocode}
\def\milesfor#1{\edef\@delivs{\euref{mile}{#1}{delivs}}
\let\m@sep=\relax
\@for\@I:=\@delivs\do{\m@sep\ \euRef{deliv}{\@I}{label}\let\m@sep=,}}
%
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\Ed@note}
%    the due date is the first argument to facilitate sorting
%    \begin{macrocode}
\newcommand{\delivrable}[6]{#2&#1&#6&#4&#5\\\hline}%due,label,id,title,type,level
%    \end{macrocode}
% \end{macro}
% 
% \begin{environment}{delivrables}
%    
%    \begin{macrocode}
\newenvironment{delivrables}[1]{\begin{longtable}{|l|l|p{#1}|l|l|}\hline
\#&due&title&dissem& type\\\hline\hline}{\\\hline\end{longtable}}
%    \end{macrocode}
% \end{environment}
% 
% \begin{macro}{\inputdelivs}
%    
%    \begin{macrocode}
\newcommand{\inputdelivs}[1]{\begin{delivrables}{#1}
\IfFileExists{\jobname.delivrables}%
{\input{\jobname.delivrables}}%
{\input{\jobname.delivs}}
\end{delivrables}}
%    \end{macrocode}
% \end{macro}
% 
% \section{The Staff Effort Table}\label{impl:staffefforttable}
%
% \begin{macro}{\staffefforttable}
%    
%    \begin{macrocode}
\def\zero@blank#1{\edef\@test{#1}\def\@zero{0}\ifx\@test\@zero\else#1\fi}
\def\staffefforttable{%
\edef\@wgs{\euref@aux{eu}{workplan}{wgs}}\message{wgs: \@wgs}
{\gdef\staff@efforts{}\def\@zero{0}% initialize
 \let\tabularnewline\relax\let\hline\relax% so they do not bother us
 \@for\@I:=\eu@partners\do{%iterate over partners for the lines
   \xdef\@line{\euref@aux{partner}{\@I}{number}& \euref@aux{partner}{\@I}{short}}% first two columns
   \@for\@J:=\@wgs\do{%iterate over the work groups
     \edef\@wps{\euref@aux{wg}{\@J}{wps}}\message{wps of \@J: \@wps}% define the list of work packages
     \edef\@wgeffort{\euref@aux{\@J}{\@I}{effort}}\message{wgeffort: \@wgeffort}% 
     \@for\@K:=\@wps\do{% iterate over wps
       \edef\@wpeffort{\euref@aux\@K\@I{effort}}
       \xdef\@line{\@line&\ifx\@wpeffort\@zero\else\@wpeffort\fi}}
     \xdef\@line{\@line&\ifx\@wgeffort\@zero\else\@wgeffort\fi}}
   \message{line: \@line}
    \xdef\staff@efforts{\staff@efforts\@line&
      \euref@aux{eu}{\@I}{totaleffort}\tabularnewline\hline}}
  \gdef\wpg@nums{} %initialize
  \@for\@I:=\@wgs\do{%iterate over the work groups
    \xdef\wpg@nums{\wpg@nums\euref@aux{wg}{\@I}{wpnums}&T\euref@aux{wg}{\@I}{num}}}}
\message{wpgnums: \wpg@nums}
\begin{tabular}{|l|l|*{\thewpgno}{c|}l|}\hline
\# & Short \wpg@nums & Total \\\hline
\staff@efforts
\end{tabular}}
%    \end{macrocode}
% \end{macro}
% 
% \begin{environment}{partnerdesc}
%    
%    \begin{macrocode}
\newenvironment{partnerdesc}[1]{%number, short, long, 
\eu@target{partner}{#1}{}
\section*{\euref{partner}{#1}{number}. #1: {\sc \euref{partner}{#1}{long}}  (\euref{partner}{#1}{nationality})}}
{}
%    \end{macrocode}
% \end{environment}
% 
% \begin{macro}{\act}
%    for the activity table
%    \begin{macrocode}
\def\act#1#2{\multicolumn{#1}{l|}{\cellcolor{lightgray}{#2}}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\pause}
%    for the activity table
%    \begin{macrocode}
\def\pause#1{\multicolumn{#1}{l|}{}}
%    \end{macrocode}
% \end{macro}
%</cls>
% \Finale
\endinput

%%% Local Variables: 
%%% mode: latex
%%% TeX-master: t
%%% End: 

