% \iffalse meta-comment
% A class for preparing DFG proposals
%
% Copyright (c) 2009 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/forCTAN/dfgproposal/dfgproposal.dtx $
% \fi
%
% \iffalse 
%<cls>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<cls>\ProvidesClass{dfgproposal}[2009/06/27 v0.6 DFG Proposal]
%<*driver>
\documentclass{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,paralist,a4wide}
\usepackage[show]{ed}
\usepackage[eso-foot,today,draft]{svninfo}
\usepackage[hyperref=auto,style=alphabetic]{biblatex}
\bibliography{kwarc}
\usepackage[a4paper=true,bookmarks=true,linkcolor=blue,
 citecolor=blue,urlcolor=blue,colorlinks=true,
 breaklinks=true, bookmarksopen=true]{hyperref}
\makeindex
\floatstyle{boxed}
\newfloat{exfig}{thp}{lop}
\floatname{exfig}{Example}
\def\subversion{\sc{Subversion}}
\begin{document}
\svnInfo $Id: dfgproposal.dtx 20454 2010-11-03 15:26:51Z kohlhase $
\svnKeyword $URL: https://svn.kwarc.info/repos/kwarc/doc/macros/forCTAN/dfgproposal/dfgproposal.dtx $
\DocInput{dfgproposal.dtx}
\end{document}
%</driver>
% \fi
% 
%\iffalse\CheckSum{1472}\fi
% 
% \changes{v0.4}{2009/05/12}{copied over from eustrep.dtx}
% \changes{v0.5}{2009/05/27}{added gantt charts}
% \changes{v0.6}{2009/06/27}{added task referencing system}
% \changes{v0.7}{2010/09/22}{added final report infrastructure}
% \changes{v0.7}{2010/10/29}{added noRAM option}
% \changes{v0.7}{2010/11/01}{added paper list infrastructure}
% \changes{v1.0}{2010/11/03}{this works well, releasing to CTAN}
% 
% \GetFileInfo{dfgproposal.cls}
% 
% \MakeShortVerb{\|} 
% \title{Preparing DFG Proposals in {\LaTeX} with {\tt{dfgproposal.cls}}}
% \author{Michael Kohlhase\\
%   Computer Science, Jacobs University Bremen\\
%   \url{http://kwarc.info/kohlhase}} 
% \maketitle
%
% \begin{abstract}
%   The |dfgproposal| class supports many of the specific elements of a DFG Proposal. It
%   is optimized towards collaborative projects. The package comes with an extensive
%   example (a fake DFG proposal) that shows all elements in action.
% \end{abstract}
% 
% \tableofcontents\newpage
%
% \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 |dfgproposal| class supports many of the specific elements of a DFG Proposal. The
% package documentation is still preliminary, fragmented and incomplete. Please consult
% the example proposal |proposal.tex|, which comes with the package and shows the usage of
% the class in action. It is intended as a template for your proposal, but please bear in
% mind that the DFG guidelines may change, if in doubt, please consult the DFG guide for
% proposers~\cite{DFG:102e}.
%
% The |dfgproposal| class 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 CTAN archive always contains the latest
% stable version, the development version can be found at
% {\url{https://svn.kwarc.info/repos/kwarc/doc/macros/forCTAN/dfgproposal}} For bug
% reports please use the sTeX trac at {\url{https://trac.kwarc.info/sTeX/}} with component
% |dfgproposal|.
%
% \section{The User Interface}\label{sec:user-interface}
% 
% In this section we will describe the functionality offered by the |dfgproposal| class
% along the lines of the macros and environments the class provides. Much of the
% functionality can better be understood by studying the functional example |proposal.tex|
% (and its dependents) that comes with the |dfgproposal| package in conjunction with the
% proposer's leaflet of the DFG~\cite{DFG:102e} (we have included it as |1_02e.pdf| for
% convenience into the package distribution).
% 
% \subsection{Package Options}\label{sec:user:options}
%
% As usual in {\LaTeX}, the package is loaded by
% |\documentclass[|\meta{options}|]{dfgproposal}|, where |[|\meta{options}|]| is optional
% and gives a comma separated list of options. The |dfgproposal| package takes the options
% |submit|, |noworkareas|, |public|,  and |keys|.
% 
% The \DescribeMacro{submit}|submit| will disable various proposal management decorations
% which are enabled by default for submission.
%
% The \DescribeMacro{noworkareas}|noworkareas| specifies that we do not want to structure
% our work plan into work areas (see section~\ref{sec:user:wpwa}).
% 
% The \DescribeMacro{noRAM}|noRAM| specifies that we do not specify research assistant
% months in the effort tallies (see section~\ref{sec:user:wpwa}).
% 
% Finally, the \DescribeMacro{public}|public| option allows to hide certain sensitive
% (e.g. financial) parts of the proposal. For this, the |dfgproposal| provides the
% \DescribeEnv{private} environment. If the option |public| is set, the parts of the
% document between |\begin{private}| and |\end{private}| do not produce output. This is
% useful for producing public versions of the proposal that hide confidential parts. Note
% that both |\begin{private}| and |\end{private}| {\emph{have to be on lines of their own
%     may not have any leading whitespace}} otherwise an error occurs and {\LaTeX} gives
% error messages that are difficult to comprehend. An alternative way to distinguish
% private and public sections are to use the \DescribeMacro{\ifpublic}|\ifpublic|
% conditional: |\ifpublic{3}\else{5}\fi| will result in ``5'' in the submitted draft and
% ``3'' in the public document.
%
% The \DescribeMacro{keys}|keys| specifies that we want to see the values of various
% keyval arguments in the margin.
% 
% \subsection{Proposal Metadata and Title page}\label{sec:user:metadata}
% 
% The metadata of the proposal is specified in the \DescribeEnv{proposal}|proposal|
% environment, which also generates the title page and the first section of the proposal
% as well as the last pages of the proposal with the signatures, enclosures, and
% references. The |proposal| environment should contain all the mandatory parts of the
% proposal text. The |proposal| environment uses the following keys to specify metadata.
% \begin{compactitem}
% \item \DescribeMacro{title}|title| for the proposal title (used on the title page),
% \item \DescribeMacro{instrument}|instrument| for the instrument of funding
%   that you would like to apply for,
% \item \DescribeMacro{thema}|thema| for a concise (up to 140 characters) description of
%   the topic of the proposal. This has to be in German and will be used by the DFG in
%   internal communications and publications.
% \item \DescribeMacro{acronym}|acronym| for the proposal acronym, possibly accompanied
%   \DescribeMacro{acrolong}|acrolong| that explains it. The acronym will also be used in
%   the page headings.
% \item \DescribeMacro{start}|start| for the start date, and
%   \DescribeMacro{months}|months| for the length of the proposal in months. Both have to
%   be specified to for the |dfgproposal| class to work.
% \item \DescribeMacro{discipline}|discipline| for the academic discipline and |areas| for
%   the research areas in that discipline.
% \item \DescribeMacro{PI}|PI| to declare the principal investigator. For collaborative
%   proposals we can use the |PI| key multiple times. The |dfgproposal| package uses the
%   |dcm| package for representation of personal metadata, see~\cite{Kohlhase:dcm:ctan}
%   or the file |proposal.tex| for details.
% \item Many collaborative proposals are shared between two institutions, which we can
%   declare with the \DescribeMacro{site}|site| key. As this changes the interface this
%   should not be used for single-institution proposals. We will describe the setup for a
%   single-site proposal below and point out the differences. The example |proposal.tex|
%   is a two-site proposal.
% \item The \DescribeMacro{pubspage}|pubspage| key can be used to give URIs of publication
%   pages that are mentioned in the references sections as sources of publications of the
%   proposers. Use one |pubspage| key per URI. 
% \end{compactitem}
% 
% The Metadata section of the proposal concludes with a summary for academic laypeople,
% which will be used by DFG e.g. on their web sites. For Proposals written in English (as
% we assume in this documentation) most proposers also provide an English summary using
% the \DescribeEnv{Summary}|Summary| environment.
%
% \subsection{Work Areas, Work Packages, and Tasks}\label{sec:user:wpwa}
% 
% DFG proposals have another part that is often highly stylized; the work plan. This is
% usually structured into ``work packages'' --- i.e. work items that address a cohesive
% aspect of the proposed work. These work packages are usually consecutively numbered, have
% a title, and an associated effort estimation. As work packages are the ``atomic''
% planning units, they are usually heavily cross-referenced. A well-written proposal
% usually contains a table giving an overview over the work packages and their efforts and
% a Gantt chart showing the temporal distribution of the proposed work to allow the
% reviewers to get a clear picture of the feasibility of the research and development
% proposed. But this picture is also essential during the development of a proposal (which
% the |dfgproposal| package aims to support), when the work packages (and their estimated
% efforts) usually change considerably. Therefore the |dfgproposal| class standardizes
% markup for work packages and automatically computes the work package table (which can be
% inserted into the table via the \DescribeMacro{\wpfig}|\wpfig| macro) and the Gantt
% Chart (see Section~\ref{sec:user:gantt}).
%
% To achieve the automation, work plan is marked up by the
% \DescribeEnv{workplan}|workplan| environment, which setsup various internal counters and
% bookeeping macros. It contains texts and |workpackage| environments for the work
% packages.
%
% The purpose of the \DescribeEnv{workpackage}|workpackage| environment is to mark up a
% fragment of text as a work package description and specify the metadata so that it can
% be used in the work package table and Gantt chart generation. The metadata is specified
% by the following keys:
% \begin{compactitem}
% \item The \DescribeMacro{id}|id| key is used to specify a label for cross-referencing the
%   work package or work group, it must be document-unique.
% \item The \DescribeMacro{title}|title| and \DescribeMacro{short}|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.
% \item In single-site proposals, the \DescribeMacro{RM}|RM| and \DescribeMacro{RAM}|RAM|
%   keys are used to specify the estimated efforts to be expended on research and
%   development in this work package. Both are specified in person months. |RM| is used
%   for ``researcher months'' (Wissenschaftlicher Mitarbeiter) and |RAM| for ``research
%   assistant months'' (wissenchaftliche Hilfskraft).
% \item In multi-site proposals, the |dfgproposal| package generates the keys
%   \DescribeMacro{*RM}\meta{site}|RM| and \DescribeMacro{*RAM}\meta{site}|RAM| where
%   \meta{site} is any site label declared via the |site| key in the top-level |proposal|
%   environment. This can be used to specify the person months that the site spends on
%   this work package (the value for work groups is automatically computed (remember to
%   run {\LaTeX} twice for this)).
% \item In multi-site proposals the \DescribeMacro{lead} |lead| key specifies the work
%   package or work group lead, the value of this feature should be the short name of the
%   respective partner.
% \end{compactitem}
% 
% It is often useful to group the work packages in a proposal further (especially for
% larger, collaborative proposals). This can be done via the
% \DescribeEnv{workarea}|workarea| environment, which groups work packages. This
% environment takes the same keys as the |workpackage| environment, except for the
% efforts, which can be computed automatically from the work packages it groups.
% 
% As the author of the |dfgproposal| class likes more structured proposals, using work
% areas is the default, but the |dfgproposal| class can also be used with the
% |noworkareas| option for less structured (smaller) proposals.
% 
% \subsection{Tasks}\label{sec:user:task}
%
% In the work packages we can list tasks that need to be undertaken with the
% \DescribeEnv{tasklist}|tasklist| environment. The individual tasks are marked up with
% the \DescribeEnv{task}|task| environment.  This takes a keyval argument with the keys
% |id| for identification, |start| for the start month (a natural number) of the task, and
% |len| for the length of the work phase.  The |force| key that specifies the work
% intensity (this should be a real number between 0 and 1 to prevent overlaps). The main
% reason for specifying this metadata for tasks is to generate a Gantt chart (see
% Section~\ref{sec:user:gantt}). The |requires| key can be used to mark, up dependencies
% between tasks. If |requires=\taskin{|\meta{rid}|}{|\meta{wp}|}| is given in a task with
% |id=|\meta{t}, then task \meta{rid} in work package \meta{wp} must be completed for task
% \meta{t} to become possible. This key will draw an arrow into the gantt chart from the
% end of task \meta{rid} to \meta{t}. Note that dependencies should always point forward
% in time. Furthermore, note that the fact that dependencies always go from the end of the
% source to the beginning of the target work phase is intentional, if this does not meet
% your needs, then you should probably break a work phase into pieces that can be
% addressed separately.
% 
% Tasks can be referenced by the \DescribeMacro{\taskref}|\taskref| macro that takes two
% arguments: the work package identifier and the task identifier. As for work packages and
% work areas, there is a long reference variant with work package title:
% \DescribeMacro{\tasktref}|\tasktref|. Finally,
% \DescribeMacro{\localtaskref}|\localtaskref| references a task in the local work package
% by the identifier in its argument.
% 
% If the work packages are not structured into tasks or the task structure is not adequate
% for structuring the work phases in a work package, then we can use the |\workphase|
% macro for this. The use of the |\workphase| package is deprecated. 
% 
% 
% \subsection{Gantt Charts}\label{sec:user:gantt}
%
% Gantt charts are used in proposals to show the distribution of activities in work
% packages over time. A gantt chart is represented by the \DescribeEnv{gantt}|gantt|
% environment that takes a on optional keyval argument. The keys
% \DescribeMacro{xscale}|xscale| and \DescribeMacro{yscale}|yscale| are used to specify a
% scale factors for the chart so that it fits on the page. The \DescribeMacro{step}|step|
% key allows to specify the steps (in months) of the vertical auxiliary lines.  Finally,
% the \DescribeMacro{draft}|draft| key specifies that plausibility checks (that can be
% expensive to run) are carried out. Note that the value does not have to be given, so
% |\begin{gantt}{draft,yscale=.5,step=3}| is a perfectly good invocation.
%
% Usually, the |gant| environment is not used however, since it is part of the
% \DescribeMacro{\ganttchart} macro that takes the same keys. This generates a whole
% Gantt chart automatically from the work phase specifications in the work packages. As
% above we have to run {\LaTeX} two times for the work phases to show up.
% 
% \subsection{Project-Related Papers}\label{sec:user:papers}
% 
% Since August 2010, DFG requests list of ``project-related papers'' as section 2.2. We
% use the |biblatex| package to automate this. We only need to use
% \DescribeMacro{\dfgprojpapers}|\dfgprojpapers{|\meta{keys}|}|, where \meta{keys} ist a
% comma-separated list of keys from the bibTeX database used in the proposal. Note that
% you will have to run |bibtex proposal1-blx.aux| to generate file |proposal1.bbl| that
% generates the bibliography list.\ednote{automate this some more}.
% 
% \subsection{Referencing and Hyperinking}\label{sec:user:hyperinking} 
% 
% The |dfgproposal| package extends the hyperlinking provided by the |hyperref| package it
% includes to work packages, work groups, \ldots. Whenever these are defined using the
% |dfgproposal| infrastructure, the class saves the relevant information in the auxiliary
% file \meta{proposal}|.aux|. This information can be referenced via the
% \DescribeMacro{\euref} macro, which takes three arguments.
% 
% In a reference |\euref{|\meta{type}|}{|\meta{id}|}{|\meta{aspect}|}| the first argument
% \meta{type} specifies the type of the object (currently one of |wp|, |wa|, and
% |partner|) to be referenced, \meta{id} specifies the identifier of the referenced object
% (it matches the identifier given in the |id| key of the object), and \meta{aspect}
% specifies the aspect of the saved information that is referenced. 
% 
% For a partner \meta{aspect} can be one of |number| (partner number), |short| (partner
% acronym), |long| (official partner name), |nationality| (partner nationality). 
% 
% For a work package \meta{aspect} can be |number|, (the work package number), |label|
% (the label {\bf{WP$n$}} where $n$ is the work package number for referencing), |title|
% (the work package title), |lead| the work package leader, |short| (a short version of
% the WP title for tables). For work groups we have the same aspects with analogous
% meanings. In all cases, the referenced information carries a hyperlink to the referenced
% object.
% 
% The \DescribeMacro{\euRef} |\euRef| macro is a variant of |\euref| that also carries a
% hyperlink (if the |hyperref| package is loaded).
% 
% Note that since the referencable information is written into the \meta{proposal}|.aux|
% file, it is available for forward references. However, it will only become available when
% the auxiliary file is read, so the proposal has to be formatted twice for references to
% be correct. \ednote{need to document all the kinds of metadata that can be referenced!}
% 
% Finally, the |dfgproposal| package supplies specialized reference macros for work
% packages and areas. The \DescribeMacro{\WPref}|\WPref| macro takes a work package
% identifier as an argument and makes a reference: |\WPref{|\meta{id}|}| abbreviates
% |\euRef{wp}{|\meta{id}|}{label}|. The \DescribeMacro{\WPtref}|\WPtref| macro is similar,
% but also prints out the title: |\WPref{|\meta{id}|}| abbreviates
% |\euRef{wp}{|\meta{id}|}{label}: \euRef{wp}{|\meta{id}|}{title}|. Unless the
% |noworkareas| macro is set, we also have the variants \DescribeMacro{\WAref}|\WAref| and
% \DescribeMacro{\WAtref}|\WAtref| for work areas.
%
% \subsection{Final Report Infrastructure}\label{sec:user:report}
% 
% The |dfgproposal| package also gives an infrastructure for writing final reports of
% completed projects (see the file |finalreport.tex| in the package distribution). The
% \DescribeEnv{finalreport}|finalreport| environment has functionality analogous to the
% |proposal| environment. It takes the same metadata keys --- making it easy to generate
% by copy/paste from the proposal --- but adds the keys
% \DescribeMacro{fundedperiod}|fundedperiod| for specifying the funded period and
% \DescribeMacro{reportperiod}|reportperiod| for the project period reported on (they can
% differ from each other). Furthermore, the key \DescribeMacro{key}|key| can be used to
% specify the reference key (something like \texttt{KO 2428 47-11}) given to the project
% by DFG. Note that in the case of multiple proposers, you can use multiple instances of
% |key| to specify more than one reference key.
%
% \section{Limitations and Enhancements}\label{sec:limitations}
% 
% The |dfgproposal| is relatively early in its development, and many enhancements are
% conceivable. We will list them here.
% \begin{enumerate}
% \item macros cannot be used work package and work area titles. They really mess up our
%   |\wpfig| automation. The problem is that they are evaluated too early, and our trick
%   with making them undefined while collecting the parts of the table-rows only works if
%   we know which macros we may expect. We might specify all ``allowable'' macros in an
%   optional key |protectmacro|, which is defined via\vspace*{-.7em}
% \begin{verbatim}
% \define@key{wpfig}{protectmacro}{\epandafter\let\csname #1\endcsname=\relax}
% \end{verbatim}
%  \vspace*{-2em} But I am not sure that this will work.
% \item It would be great, if in the Gantt Charts, we could include some plausibility
%   checks (for draft = not |submit| mode). I can see two at the moment:
%   \begin{itemize}
%   \item calculating the effort (i.e. the weight of the black area) and visualizing
%     it. Then we could check whether that is larger than the effort declared for the work
%     package.
%   \item calculating (and visualizing) the monthly effort. That should be kind of even
%     (or it has to be explained in the positions requested).
%   \end{itemize}
% \item we currently do not have a way to relate |PI|s to |site|s, but we do not really
%   need to.
% \item it would be nice if we could count the characters in the places where lengths are
%   restricted (|Abriss|, and |thema|). Then we could warn the authors.
% \end{enumerate}
% If you have other enhancements to propose or feel you can alleviate some limitation,
% please feel free to contact the author. 
%
% \StopEventually{\newpage\PrintIndex\newpage\PrintChanges\newpage\printbibliography}\newpage
%
% \section{The Implementation}\label{sec:implementation}
%
% In this section we describe the implementation of the functionality of the |dfgproposal| package. 
% 
% \subsection{Package Options and Format Initialization}\label{sec:impl:options}
% 
% We first set up the options for the package. 
% 
%    \begin{macrocode}
%<*cls>
\newif\ifsubmit\submitfalse
\newif\ifpublic\publicfalse
\newif\ifkeys\keysfalse
\newif\ifwork@areas\work@areastrue
\newif\if@RAM\@RAMtrue
\DeclareOption{submit}{\submittrue}
\DeclareOption{public}{\publictrue\excludecomment{private}}
\DeclareOption{noworkareas}{\work@areasfalse}
\DeclareOption{noRAM}{\@RAMfalse}
\DeclareOption{keys}{\keystrue}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions
%    \end{macrocode}
% 
%    Then we load the packages we make use of
% 
%    \begin{macrocode}
\LoadClass[a4paper,twoside]{article}
\RequirePackage{dcm}
\RequirePackage{amssymb}
\RequirePackage{url}
\RequirePackage{graphicx}
\RequirePackage{colortbl}
\RequirePackage{xcolor}
\RequirePackage{rotating}
\RequirePackage{fancyhdr}
\RequirePackage{array}
\RequirePackage{xspace}
\RequirePackage{eurosym}
\RequirePackage{comment}
\RequirePackage{tikz}
\RequirePackage{paralist}
\RequirePackage{a4wide}
\renewcommand{\familydefault}{\sfdefault} 
\RequirePackage[scaled=.90]{helvet}
\RequirePackage{textcomp}
\RequirePackage[USenglish,ngerman]{babel}
\RequirePackage{biblatex}
\RequirePackage[a4paper=true,bookmarks=true,linkcolor=blue,
 citecolor=blue,urlcolor=blue,colorlinks=true,
 breaklinks=true, bookmarksopen=true]{hyperref}
%    \end{macrocode}
% 
% the |ed| package~\cite{Kohlhase:ed:ctan} is very useful for collaborative writing and
% passing messages between collaborators or simply reminding yourself of editing tasks, so
% we preload it in the class. However, we only want to show the information in draft
% mode. Furthermore, we adapt the options for the |svninfo| package.
%
%    \begin{macrocode}
\ifsubmit
\RequirePackage[hide]{ed}
\RequirePackage[final,today]{svninfo}
\else
\RequirePackage[show]{ed}
\RequirePackage[eso-foot,today]{svninfo}
\fi
%    \end{macrocode}
%    
% \begin{environment}{private}
%   We configure the |comment| package, so that it provides the |private| environment
%   depending on the status of the |public| option.
%    \begin{macrocode}
\ifpublic\excludecomment{private}\else\includecomment{private}\fi
%    \end{macrocode}
% \end{environment}
%
% And we set up the appearance of the proposal. We want numbered subsubsections.
%    \begin{macrocode}
\setcounter{secnumdepth}{3}
%    \end{macrocode}
% We specify the page headings. 
%    \begin{macrocode}
\newif\ifofpage\ofpagefalse
\fancyhead[RE,LO]{\dfg@gen@acronym}
\fancyhead[LE,RO]{page~\thepage\ifofpage~of~\euref@num{prop}{page}{last}\fi}
\pagestyle{fancyplain}
%    \end{macrocode}
%
% \subsection{Proposal Metadata and Title Page}\label{sec:impl:metadata}
%  
% We define the keys for metadata declarations in the |proposal| environment, they park
% their argument in an internal macro for use in the title page. The |site| key is the
% most complicated, so we take care of it first: We need a switch |\if@sites| that is set
% to true when the |site| key is used. Furthermore |site=|\meta{site} makes new keys
% \meta{site}|RM| and \meta{site}|RAM| (unless the |noRAM| option was set) for the
% |workpackage| environment and records the sites in the |\dfg@gen@sites| token register.
%    \begin{macrocode}
\newif\if@sites\@sitesfalse\let\dfg@gen@sites=\relax
\define@key{dfg@gen}{site}{\@sitestrue\@dmp{site=#1}%
\@ifundefined{dfg@gen@sites}{\xdef\dfg@gen@sites{#1}}{\xdef\dfg@gen@sites{\dfg@gen@sites,#1}}
\define@key{workpackage}{#1RM}{\dfg@def\wp@id{#1}{RM}{##1}}
\if@RAM\define@key{workpackage}{#1RAM}{\dfg@def\wp@id{#1}{RAM}{##1}}\fi}
%    \end{macrocode}
%  similarly, the |PI| keys  are registered in |\dfg@gen@PIs|.
%    \begin{macrocode}
\define@key{dfg@gen}{PI}{\@dmp{PI=#1}%
\@ifundefined{dfg@gen@PIs}{\xdef\dfg@gen@PIs{#1}}{\xdef\dfg@gen@PIs{\dfg@gen@PIs,#1}}}
%    \end{macrocode}
%  and the |pubspage| keys  in |\dfg@gen@pubspages|.
%    \begin{macrocode}
\define@key{dfg@gen}{pubspage}{\@ifundefined{dfg@gen@pubspages}%
{\xdef\dfg@gen@pubspages{#1}}{\xdef\dfg@gen@pubspages{\dfg@gen@pubspages,#1}}}
%    \end{macrocode}
%  The rest of the keys just store their value. 
%    \begin{macrocode}
\define@key{dfg@gen}{instrument}{\def\dfg@gen@instrument{#1}\@dmp{inst=#1}}
\define@key{dfg@gen}{title}{\def\dfg@gen@title{#1}}
\define@key{dfg@gen}{thema}{\def\dfg@gen@thema{#1}}
\define@key{dfg@gen}{acronym}{\gdef\dfg@gen@acronym{#1}\@dmp{acro=#1}}
\define@key{dfg@gen}{acrolong}{\def\dfg@gen@acrolong{#1}}
\define@key{dfg@gen}{discipline}{\def\dfg@gen@discipline{#1}}
\define@key{dfg@gen}{areas}{\def\dfg@gen@areas{#1}}
\define@key{dfg@gen}{start}{\def\dfg@gen@start{#1}}
\define@key{dfg@gen}{months}{\def\dfg@gen@months{#1}}
%    \end{macrocode}
% and now the ones for the final report 
%    \begin{macrocode}
\define@key{dfg@gen}{fundedperiod}{\def\dfg@gen@fundedperiod{#1}}
\define@key{dfg@gen}{reportperiod}{\def\dfg@gen@reportperiod{#1}}
\define@key{dfg@gen}{key}{\@dmp{key=#1}%
\@ifundefined{dfg@gen@keys}{\xdef\dfg@gen@keys{#1}}{\xdef\dfg@gen@keys{\dfg@gen@keys,#1}}}
%    \end{macrocode}
% 
% and the default values, these will be used, if the author does not specify something
% better.
%
%    \begin{macrocode}
\def\dfg@gen@acro{ACRONYM}
\def\dfg@gen@months{???}
\def\dfg@gen@title{Proposal Title}
\def\dfg@gen@instrument{Neuantrag auf Sachbeihilfe}
\def\dfg@gen@thema{??? Thema ???}
\long\def\deu#1{#1}
%    \end{macrocode}
% Now, we can build the title page and general information, we first start with the
% applicants table:
%    \begin{macrocode}
\def\dfg@applicants@table%
{\begin{tabular}{|l|*{\the@PIs}{l|}}\hline
  \dcm@bitabline\dfg@gen@PIs{personaltitle}{ }{name}\\
  \dcm@tabline\dfg@gen@PIs{academictitle}\\
  \dcm@tabline\dfg@gen@PIs{birthdate}\\\hline
  &\multicolumn{\the@PIs}{|l|}{\textbf{Work Address\deu{ (Dienstanschrift)}:}}\\\hline
  \dcm@tabline\dfg@gen@PIs{affiliation}\\
  \dcm@tabline\dfg@gen@PIs{workaddress}\\
  \dcm@atabline\dfg@gen@PIs{Tel: }{worktel}\\
  \dcm@atabline\dfg@gen@PIs{Fax: }{workfax}\\
  \dcm@tabline\dfg@gen@PIs{email}\\\hline
  &\multicolumn{\the@PIs}{|l|}{\textbf{Private Address\deu{ (Privatanschrift)}:}} \\\hline
  \dcm@tabline\dfg@gen@PIs{privaddress}\\
  \dcm@atabline\dfg@gen@PIs{Tel: }{privtel}\\\hline
\end{tabular}}
%    \end{macrocode}
% 
%    \begin{macrocode}
\def\dfg@applicants{\subsection{Applicants \deu{(Antragsteller)}}
\dfg@applicants@table}
%    \end{macrocode}
% 
%    \begin{macrocode}
\def\dfg@topic{\deu{\subsection{Topic (Thema)}\dfg@gen@thema}}
%    \end{macrocode}
% 
%    \begin{macrocode}
\def\dfg@area@field{%
\subsection{Research area and field of work \deu{(Fachgebiet und Arbeitsrichtung)}}
Scientific discipline:  \dfg@gen@discipline\\
Fields of work:  \dfg@gen@areas}
%    \end{macrocode}
% 
%    \begin{macrocode}
\newenvironment{dfg@titlepage}
{\thispagestyle{empty}\setcounter{page}{0}%
\begin{center}}
{\newcounter{@PIs}\@for\@I:=\dfg@gen@PIs\do{\stepcounter{@PIs}}
  \newcounter{@sites}\@for\@I:=\dfg@gen@sites\do{\stepcounter{@sites}}
\begin{tabular}{c*{\the@PIs}{c}}
\dcm@tabline\dfg@gen@PIs{name}\\
\dcm@tabline\dfg@gen@PIs{affiliation}
\end{tabular}\\[2cm]
\end{center}
\setcounter{tocdepth}{1}\tableofcontents\newpage\setcounter{page}{1}}
%    \end{macrocode}
%
% \begin{environment}{proposal}
%   The |proposal| environment reads the metdata keys defined above, and if there were no
%   |site| keys, then it defines keys |RM| and |RAM| (unless the |noRAM| package option
%   was given) for the |workpackage| environment.
%    \begin{macrocode}
\newenvironment{proposal}[1][]
{\ofpagetrue\setkeys{dfg@gen}{#1}
\if@sites\else
\define@key{workpackage}{RM}{\dfg@def{wp}\wp@id{RM}{##1}\@dmp{RM=##1}}
\if@RAM\define@key{workpackage}{RAM}{\dfg@def{wp}\wp@id{RAM}{##1}\@dmp{RAM=##1}}\fi
\fi
\begin{dfg@titlepage}
  {\LARGE \dfg@gen@instrument}\\[.2cm]
  {\LARGE\textbf{\dfg@gen@title}}\\[.3cm]
  {\LARGE Acronym: {\dfg@gen@acronym}}\\[.2cm]
  {\large\today}\\[1em]
\end{dfg@titlepage}
\section{General Information \deu{(Allgemeine Angaben)}}
\dfg@applicants
\dfg@topic
\dfg@area@field
\subsection{Anticipated total duration \deu{(Voraussichtliche
    Gesamtdauer)}}\dfg@gen@months\quad Months
\subsection{Application period \deu{(Antragszeitraum)}}\dfg@gen@start
\selectlanguage{USenglish}}
%    \end{macrocode}
% Now we come to the end of the environment:
%    \begin{macrocode}
{\thispagestyle{empty}\signatures
\section{List of Attachments \deu{(Verzeichnis der Anlagen)}}
\begin{itemize}
\@for\@I:=\dfg@gen@PIs\do{%
\item Curriculum Vitae and list of publications for 
  \@nameuse{dcm@person@\@I @personaltitle}
  \@nameuse{dcm@person@\@I @name}
 (CD + printed version)}
\item Publications either cited in section~\ref{sec:ourpubs} or occurring in one of the
  curricula vitae (CD only)
\end{itemize}
\dfg@def{prop}{page}{last}{\thepage}\ofpagefalse
\newpage 
\printbibliography[heading=warnpubs]}
%    \end{macrocode}
% \end{environment}
% We only have to define the |warnpubs| heading constructor
%    \begin{macrocode}
\defbibheading{warnpubs}{\section*{References}%
  \@ifundefined{dfg@gen@pubspages}
  {\@latex@warning{No publication pages specified; 
                   use the pubspage key in the proposal environment!}}
  {Many of the proposers' publications are online at one of the following URIs:
 \@for\@I:=\dfg@gen@pubspages\do{\par\noindent\url{\@I}}}}
%    \end{macrocode}
%
% The |finalreport| is very similar. 
%
% \begin{environment}{finalreport}
%    \begin{macrocode}
\newenvironment{finalreport}[1][]
{\ofpagetrue\setkeys{dfg@gen}{#1}
\begin{dfg@titlepage}
  {\LARGE Final Project Report}\\[.2cm]
  {\LARGE\textbf{\dfg@gen@title}}\\[.3cm]
  {\LARGE Acronym: {\dfg@gen@acronym}}\\[.2cm]
  {\large Reference number(s): \@ifundefined{dfg@gen@keys}{??:???? ?/?}{\dfg@gen@keys}}\\[.2cm]
  {\large\today}\\[1em]
\end{dfg@titlepage} 
\section{General Information \deu{(Allgemeine Angaben)}}
\dfg@applicants
\dfg@topic
\subsection{Funding Period \deu{(F\"orderzeitraum)}}\dfg@gen@fundedperiod
\subsection{Report Period \deu{(Berichtszeitraum)}}\dfg@gen@reportperiod
\selectlanguage{USenglish}}
{\dfg@def{prop}{page}{last}{\thepage}\ofpagefalse}
%    \end{macrocode}
% \end{environment}
% 
%    \begin{macrocode}
\newenvironment{Summary}{\subsection{Summary \deu{(Zusammenfassung)}}}{}
\newenvironment{Abriss}%
{\selectlanguage{ngerman}\subsection*{Zusammenfassung (dt. Version)}}
{\selectlanguage{USenglish}}
%    \end{macrocode}
%
% \subsection{Work Packages and Work Groups}\label{sec:impl:wpwa}
%    
% \begin{macro}{\dfg@def}
%    This macro writes an |\@dfg@def| command to the current aux file and also executes it. 
%    \begin{macrocode}
\def\dfg@def#1#2#3#4{%\@dfg@def{#1}{#2}{#3}{#4}%
  \protected@write\@auxout{}{\string\@dfg@def{#1}{#2}{#3}{#4}}}
%    \end{macrocode}
% \end{macro}
% We first define keys for  work groups (if we are in an IP). 
%    \begin{macrocode}
\ifwork@areas
\define@key{workarea}{id}{\def\wa@id{#1}\@dmp{id=#1}}
\define@key{workarea}{title}{\dfg@def{wa}\wa@id{title}{#1}}
\define@key{workarea}{short}{\dfg@def{wa}\wa@id{short}{#1}}
\fi
%    \end{macrocode}
% work packages have similar ones. 
%    \begin{macrocode}
\define@key{workpackage}{id}{\def\wp@id{#1}\@dmp{id=#1}}
\define@key{workpackage}{title}{\dfg@def{wp}\wp@id{title}{#1}}
\define@key{workpackage}{lead}{\dfg@def{wp}\wp@id{lead}{#1}\def\wp@lead{#1}\@dmp{lead=#1}}
\define@key{workpackage}{short}{\dfg@def{wp}\wp@id{short}{#1}}
%    \end{macrocode}
% We define the constructors for the work package and work group labels and titles. 
%    \begin{macrocode}
\def\wp@mk@title#1{Work Package {#1}}
\def\wp@label#1{WP{#1}}
\ifwork@areas
\def\wa@label#1{WA{#1}}
\def\wa@mk@title#1{Work Area {#1}}
\fi
%    \end{macrocode}
% The |wa| and |wp| counters are for the work packages and work groups
%    \begin{macrocode}
\ifwork@areas\newcounter{wa}\newcounter{wp}[wa]\else\newcounter{wp}\fi
\newcounter{allwp}
%    \end{macrocode}
% 
% \begin{macro}{\update@*}
%   update the list |\@wps| of the work packages in the local group and the list |\@was|
%   work groups for the staff efforts table: if |\@wps| is undefined, then initialize the
%   comma-separated list, otherwise extend it.\ednote{with the current architecture, we
%   cannot have work areas that do not contain work packages, this leads to the error that
%   |\@wps| is undefined in |end{workplan}|}
%    \begin{macrocode}
\def\update@wps#1{\@ifundefined{@wps}{\xdef\@wps{#1}}{\xdef\@wps{\@wps,#1}}}
\def\update@tasks#1{\@ifundefined{@tasks}{\xdef\@tasks{#1}}{\xdef\@tasks{\@tasks,#1}}}
\def\update@deps#1{\@ifundefined{task@deps}{\xdef\task@deps{#1}}{\xdef\task@deps{\task@deps,#1}}}
\ifwork@areas\def\update@was#1{\@ifundefined{@was}{\xdef\@was{#1}}{\xdef\@was{\@was,#1}}}\fi
%    \end{macrocode}
% \end{macro}
%
% with these it is now relatively simple to define the interface macros. 
%
% \begin{environment}{workpackage}
%   The |workpackage| environment collects the keywords, steps the counters, writes the metadata
%   to the aux file, updates the work packages in the local group, generates the work
%   package number |\wp@num|.
%    \begin{macrocode}
\newcounter{wp@RM}
\if@RAM\newcounter{wp@RAM}\fi
\newenvironment{workpackage}[1][]%
{\setkeys{workpackage}{#1}\stepcounter{wp}\stepcounter{allwp}%
\let\@tasks=\relax%
\edef\wp@num{\ifwork@areas\thewa.\fi\thewp}%
\dfg@def{wp}\wp@id{label}{\wp@label\wp@num}%
\dfg@def{wp}\wp@id{number}{\thewp}%
\dfg@def{wp}\wp@id{page}{\thepage}%
\update@wps\wp@id%
\edef\wp@num{\ifwork@areas\thewa.\fi\thewp}%
\dfg@def{wp}{\wp@id}{num}{\thewp}%
%    \end{macrocode}
% Now we have to consider two cases, if we have sites, then we make a header table. 
%    \begin{macrocode}
\if@sites%
{\let\G@refundefinedtrue=\relax\let\@latex@warning=\relax%
\xdef\sites@line{Site}\xdef\efforts@line{Effort}%initialize lines
\setcounter{wp@RM}{0}%
\if@RAM\setcounter{wp@RAM}{0}\fi%
\@for\@site:=\dfg@gen@sites\do{%
\xdef\sites@line{\sites@line&\@site\ifx\@site\wp@lead~(lead)\fi}%
\xdef\efforts@line{\efforts@line&\euref\wp@id\@site{RM}\if@RAM+\euref\wp@id\@site{RAM}\fi}%
\edef\@RM{\euref@num\wp@id\@site{RM}}\addtocounter{wp@RM}{\@RM}%
\if@RAM\edef\@RAM{\euref@num\wp@id\@site{RAM}}\addtocounter{wp@RAM}{\@RAM}\fi}}%
\dfg@def{wp}\wp@id{RM}{\thewp@RM}%
\if@RAM\dfg@def{wp}\wp@id{RAM}{\thewp@RAM}\fi%
\bigskip\noindent\begin{tabular}{|l||l|*{\the@sites}{c|}}\hline%
\textbf{\wp@mk@title{\wp@num}}&\sites@line\\\hline%
\textsf{\dfg@target{wp}{\wp@id}{\euref{wp}\wp@id{title}}} &\efforts@line\\\hline%
\end{tabular}\smallskip\par\noindent\ignorespaces%
\else% if@sites
%    \end{macrocode}
% When we do not have sites, we can make things much simpler: we just generate a subsection
%    \begin{macrocode}
\subsubsection*{\wp@mk@title{\wp@num}: \dfg@target{wp}{\wp@id}{\euref{wp}\wp@id{title}}
(\euref@safe{wp}\wp@id{RM} RM\if@RAM+\euref{wp}\wp@id{RAM} RAM\fi)}%
\fi}%
{\@ifundefined{@tasks}{}{\dfg@def{\wp@id}{task}{ids}\@tasks}}
%    \end{macrocode}
%  \end{environment}
%
% \begin{environment}{workarea}
%   the |workarea| environment for work groups is almost the same, but we also have to
%   initialize the work package counters. Also, the efforts can be computed from the work
%   packages in this group via the |wa@effort| counter
%    \begin{macrocode}
\newcounter{dfg@RM}\if@RAM\newcounter{dfg@RAM}\fi
\ifwork@areas
\newcounter{wa@RM}\if@RAM\newcounter{wa@RAM}\fi\newcounter{wa@wps}
\newenvironment{workarea}[1][]
{\setkeys{workarea}{#1}
\let\@wps=\relax
\stepcounter{wa}
\dfg@def{wa}{\wa@id}{label}{\wa@label\thewa}
\dfg@def{wa}{\wa@id}{number}{\thewa}
\dfg@def{wa}{\wa@id}{page}{\thepage}
\update@was{\wa@id}
\dfg@def{wa}{\wa@id}{num}{\thewa}
\setcounter{wa@RM}{0}\if@RAM\setcounter{wa@RAM}{0}\fi\setcounter{wa@wps}{0}
\if@sites
\@for\@site:=\dfg@gen@sites\do{%
\edef\@@wps{\euref@aux\wa@id{wp}{ids}}
\@for\@wp:=\@@wps\do{%
   \edef\@RM{\euref@num\@wp\@site{RM}}
   \if@RAM\edef\@RAM{\euref@num\@wp\@site{RAM}}\fi
   \addtocounter{wa@RM}{\@RM}\addtocounter{dfg@RM}{\@RM}
   \if@RAM\addtocounter{wa@RAM}{\@RAM}\addtocounter{dfg@RAM}{\@RAM}\fi}}
\else
\edef\@@wps{\euref@aux\wa@id{wp}{ids}}
\@for\@wp:=\@@wps\do{%
  \edef\@RM{\euref@num{wp}\@wp{RM}}
 \if@RAM\edef\@RAM{\euref@num{wp}\@wp{RAM}}\fi
  \stepcounter{wa@wps}
  \addtocounter{wa@RM}{\@RM}\addtocounter{dfg@RM}{\@RM}
  \if@RAM\addtocounter{wa@RAM}{\@RAM}\addtocounter{dfg@RAM}{\@RAM}\fi}
\fi
\dfg@def{wa}\wa@id{RM}\thewa@RM
\dfg@def{dfg}{all}{RM}\thedfg@RM
\if@RAM
\dfg@def{wa}\wa@id{RAM}\thewa@RAM
\dfg@def{dfg}{all}{RAM}\thedfg@RAM
\fi
\subsection*{{\wa@mk@title\thewa}: {\dfg@target{wa}\wa@id{\euref{wa}\wa@id{title}}}}}
{\@ifundefined{@wps}{}{\dfg@def\wa@id{wp}{ids}\@wps}\dfg@def\wa@id{wp}{count}\thewa@wps}\fi
%    \end{macrocode}
% \end{environment}
% 
% \begin{environment}{workplan}
%   The |workplan| environment sets up the accumulator macros |\@wps|, |\@was|, for the
%   collecting the identifiers of work packages and work groups. At the end of the
%   workplan description it writes out their content to the aux file for reference.
%    \begin{macrocode}
\newenvironment{workplan}%
{\ifwork@areas\let\@was=\relax\else\let\@wps=\relax\fi}%
{\@ifundefined{task@deps}{}{\dfg@def{all}{task}{deps}{\task@deps}}
\ifwork@areas
\@ifundefined{@was}{}{\dfg@def{all}{wa}{ids}\@was}
\else
\@ifundefined{@wps}{}{\dfg@def{all}{wp}{ids}\@wps}
\fi
\ifwork@areas\dfg@def{all}{wa}{count}{\thewa}\fi
\ifwork@areas\dfg@def{all}{wp}{count}{\theallwp}\fi}
\def\dfg@target#1#2#3{\hypertarget{#1@#2@target}{#3}}
%    \end{macrocode}
% \end{environment}
%
% \subsection{Tasks and Work Phases}\label{sec:impl:tasks}
% 
% \begin{environment}{tasklist}
%    \begin{macrocode}
\newenvironment{tasklist}
{\begin{compactenum}}{\end{compactenum}}
%    \end{macrocode}
% \end{environment}
% The next step is to 
%    \begin{macrocode}
\def\task@label#1{T#1}
%    \end{macrocode}
% We define the keys for the task macro
%    \begin{macrocode}
\define@key{task}{id}{\def\task@id{#1}\@dmp{id=#1}}
\define@key{task}{start}{\def\task@start{#1}\@dmp{start=#1}}
\define@key{task}{len}{\def\task@len{#1}\@dmp{len=#1}}
\define@key{task}{force}{\def\task@force{#1}\@dmp{f=#1}}
\define@key{task}{requires}{\@requires\task@id{#1}\@dmp{req=#1}}
\define@key{task}{title}{\def\task@title{#1}\@dmp{title=#1}}
%    \end{macrocode}
% then we define an auxiliary function that gives them sensible defaults and sets the
% internal macros.
%    \begin{macrocode}
\def\task@set#1{\edef\task@id{task\thetask@all}
\def\task@force{1}
\let\task@start=\relax\let\task@len=\relax
\setkeys{task}{#1}}
%    \end{macrocode}
% 
% \begin{environment}{tasklist}
%    \begin{macrocode}
\newenvironment{task}[1][]
{\@task{#1}\item[\dfg@target{task}{\taskin\task@id\wp@id}{\task@label{\thetask@wp}}]%
\@ifundefined{task@title}{}{\textbf{\task@title}}}
{}
%    \end{macrocode}
% \end{environment}
%
% \begin{macro}{\@task}
%   The |\@task| macro is a internal macro which takes a bunch of keyword keys and writes
%   their values to the aux file.
%    \begin{macrocode}
\newcounter{task@all}\newcounter{task@wp}[wp]
\newcount\task@@end
\def\@task#1{\stepcounter{task@all}\stepcounter{task@wp}
  \task@set{#1}
  \@ifundefined{task@start}%
 {\protect\G@refundefinedtrue\@latex@warning{start of task #1 undefined}}%
  {\dfg@def{task}{\taskin\task@id\wp@id}{start}\task@start}
  \@ifundefined{task@len}%
 {\protect\G@refundefinedtrue\@latex@warning{length of task #1 undefined}}%
  {\dfg@def{task}{\taskin\task@id\wp@id}{len}\task@len}
  \dfg@def{task}{\taskin\task@id\wp@id}{force}\task@force
  \dfg@def{task}{\taskin\task@id\wp@id}{label}{\task@label\thetask@wp}%
  \dfg@def{task}{\taskin\task@id\wp@id}{number}{\thetask@wp}%
  \dfg@def{task}{\taskin\task@id\wp@id}{page}{\thepage}%
 \update@tasks{\taskin\task@id\wp@id}}
\def\workphase#1{\@task{#1}}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\localtaskref}
%    \begin{macrocode}
\def\localtaskref#1{\euRef{task}{\wp@id @#1}{label}}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\taskref}
%    \begin{macrocode}
\def\taskin#1#2{#2@#1}
\def\taskref#1#2{\WPref{#1}\euRef{task}{#1@#2}{label}}
\def\tasktref#1#2{\WPref{#1} (Task \euRef{task}{#1@#2}{number})}
\newcounter{gantt@deps}
\def\@requires#1#2{\stepcounter{gantt@deps}%
\edef\dep@id{taskdep\thegantt@deps}%
\dfg@def{taskdep}\dep@id{from}{\taskin{#1}\wp@id}%
\dfg@def{taskdep}\dep@id{to}{#2}%
\update@deps\dep@id}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Project-Related Papers}\label{sec:impl:papers}
% 
% \begin{macro}{\dfgprojpapers}
%   We first define a bibLaTeX bibliography heading that does not create headers, then we
%   generate a subsection with a |refsection| (this makes a separate bibliography for this
%   section) and activate the keys via |\nocite|. Then we just print the bibliography with
%   the empty header we created before.
%    \begin{macrocode}
\defbibheading{empty}{}
\def\dfgprojpapers#1{%
\subsection{Project-Related List of Publications}\label{sec:ourpubs}
\begin{refsection}
\nocite{#1}
\printbibliography[heading=empty]
\end{refsection}}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Referencing and Hyperinking}\label{sec:impl:hyperinking} 
% 
% \begin{macro}{\@dfg@def}
%   This macro stores the value of its last argument in a custom macro for reference.
%    \begin{macrocode}
\def\@dfg@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}}%
\def\euref@num#1#2#3{\@ifundefined{#1@#2@#3}{0}{\csname #1@#2@#3\endcsname}}%
\def\euref@safe#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}{\W*ref}
%    \begin{macrocode}
\def\WPref#1{\euRef{wp}{#1}{label}}
\def\WPtref#1{\euRef{wp}{#1}{label}: \euRef{wp}{#1}{title}}
\ifwork@areas
\def\WAref#1{\euRef{wa}{#1}{label}}
\def\WAtref#1{\euRef{wa}{#1}{label}: \euRef{wa}{#1}{title}}
\fi
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\dfgcount}
%    \begin{macrocode}
\def\@count #1{\ifcase #1 zero\or one\or two\or three\or four\or five\or six\or seven \or
  eight\or nine\or ten\or eleven \or twelve\else#1\fi}
\def\dfgcount#1#2{\@count{\euref@num{#1}{#2}{count}}}
%    \end{macrocode}
% \end{macro}
%
% \subsection{The Work Package Table}\label{sec:impl:wptable}
%
% \begin{macro}{\dfg@lead}
%    \begin{macrocode}
\def\dfg@lead#1{\@ifundefined{wp@#1@lead}%
{\protect\G@refundefinedtrue\@latex@warning{lead for WP #1 undefined}??}%
{\csname wp@#1@lead\endcsname}}
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
\def\wa@style#1{\cellcolor{lightgray}{\textbf{#1}}}
\def\wp@style#1{#1}
%    \end{macrocode}
% 
% \begin{environment}{wptable}
%    
%    \begin{macrocode}
\if@RAM
\newenvironment{wptable}%
{\begin{tabular}{|l|l|l|l|l|}\hline%
    \textbf{\ifwork@areas{WA/P}\else{WP}\fi}&
    \textbf{Title}&
    \textbf{p.}&
    \textbf{RM} &
    \textbf{RAM}\\\hline\hline}
{\end{tabular}}
\else
\newenvironment{wptable}%
{\begin{tabular}{|l|l|l|l|}\hline%
    \textbf{\ifwork@areas{WA/P}\else{WP}\fi}&
    \textbf{Title}&
    \textbf{p.}&
    \textbf{RM}\\\hline\hline}
{\end{tabular}}
\fi
%    \end{macrocode}
% \end{environment}
%
% \begin{macro}{\wpfig}
%   \ednote{The computation can be distributed much more efficiently (by intermingling the
%   counter advances with the row creation), but this works now}
%    \begin{macrocode}
\define@key{wpfig}{size}{\def\wpfig@size{#1}\@dmp{size=#1}}
\def\@sw#1{\begin{sideways}#1\end{sideways}}
\newcommand{\wpfig}[1][]{\setkeys{wpfig}{#1}
\newcount\@@@RM\if@RAM\newcount\@@@RAM\fi
{\gdef\@wp@lines{}%initialize
\let\tabularnewline\relax\let\hline\relax\let\cellcolor\relax% so they
\let\wa@style\relax\let\wp@style\relax \let\@sw\relax\let\textbf\relax% do not
\let\G@refundefinedtrue=\relax\let\@latex@warning=\relax\let\hyperlink=\relax% bother us
\gdef\wpfig@headline{\textbf{\ifwork@areas{WA/P}\else{WP}\fi}&\textbf{Title}&\textbf{p.}}
\if@sites
\@for\@site:=\dfg@gen@sites\do{\xdef\wpfig@headline{\wpfig@headline&\@sw{\@site\ RM}\if@RAM&\@sw{\@site\ RAM}\fi}}
\else
\xdef\wpfig@headline{\wpfig@headline &\@sw{RM}\if@RAM&\@sw{RAM}\fi}
\fi
\edef\@@was{\euref@safe{all}{wa}{ids}}%
\@for\@@wa:=\@@was\do{% iterate over the work areas
\xdef\@@wa@line{\wa@style{\euRef{wa}\@@wa{label}}&
\wa@style{\@ifundefined{wa@\@@wa @short}{\euref{wa}\@@wa{title}}{\euref{wa}\@@wa{short}}}&
\wa@style{\euref{wa}\@@wa{page}}}
\if@sites
\@for\@site:=\dfg@gen@sites\do{\@@@RM=0\if@RAM\@@@RAM=0\fi
\edef\@@wps{\euref@safe\@@wa{wp}{ids}}%
\@for\@@wp:=\@@wps\do{% compute the WA efforts
\advance\@@@RM by \euref@num\@@wp\@site{RM}%
\if@RAM\advance\@@@RAM by \euref@num\@@wp\@site{RAM}\fi}
\xdef\@@wa@line{\@@wa@line&\wa@style{\the\@@@RM}\if@RAM&\wa@style{\the\@@@RAM}\fi}}
\else
\@@@RM=0\if@RAM\@@@RAM=0\fi
\edef\@@wps{\euref@safe{all}{wp}{ids}}%
\@for\@@wp:=\@@wps\do{% compute the  efforts
\advance\@@@RM by \euref@num{wp}\@@wp{RM}%
\if@RAM\advance\@@@RAM by \euref@num{wp}\@@wp{RAM}\fi}
\xdef\@@wa@line{\@@wa@line&\wa@style{\euref{wa}\@@wa{RM}}
\if@RAM&\wa@style{\euref{wa}\@@wa{RAM}}\fi}%
\fi
\xdef\@wp@lines{\@wp@lines\@@wa@line\tabularnewline\hline}% add the line for the workarea
\edef\@@wps{\euref@safe\@@wa{wp}{ids}}%
\@for\@@wp:=\@@wps\do{% iterate over its work packages
\xdef\@@wp@line{\euRef{wp}\@@wp{label}&
\@ifundefined{wp@\@@wp @short}{\euref{wp}\@@wp{title}}{\euref{wp}\@@wp{short}}&
\euref{wp}\@@wp{page}}
\if@sites
\@for\@site:=\dfg@gen@sites\do{%
\xdef\@@wp@line{\@@wp@line&\wp@style{\euref\@@wp\@site{RM}}\if@RAM&\wp@style{\euref\@@wp\@site{RAM}}\fi}}%
\else
\xdef\@@wp@line{\@@wp@line&\wp@style{\euref{wp}\@@wp{RM}}\if@RAM&\wp@style{\euref{wp}\@@wp{RAM}}\fi}%
\fi
\xdef\@wp@lines{\@wp@lines\@@wp@line\tabularnewline\hline}}}
\gdef\@totals{}
\if@sites
\@for\@site:=\dfg@gen@sites\do{\@@@RM=0\if@RAM\@@@RAM=0\fi
\edef\@@was{\euref@safe{all}{wa}{ids}}%
\@for\@@wa:=\@@was\do{%
\edef\@@wps{\euref@safe\@@wa{wp}{ids}}%
\@for\@@wp:=\@@wps\do{% iterate over the work areas
\advance\@@@RM by \euref@num\@@wp\@site{RM}%
\if@RAM\advance\@@@RAM by \euref@num\@@wp\@site{RAM}\fi}}
\xdef\@totals{\@totals & \textbf{\the\@@@RM}\if@RAM& \textbf{\the\@@@RAM}\fi}}
\else
\@@@RM=0\if@RAM\@@@RAM=0\fi
\edef\@@was{\euref@safe{all}{wa}{ids}}%
\@for\@@wa:=\@@was\do{\edef\@@wps{\euref@safe\@@wa{wp}{ids}}%
\@for\@@wp:=\@@wps\do{% iterate over the work areas
\advance\@@@RM by \euref@num{wp}\@@wp{RM}%
\if@RAM\advance\@@@RAM by \euref@num{wp}\@@wp{RAM}\fi}}
\xdef\@totals{&\the\@@@RM\if@RAM &\the\@@@RAM\fi}
\fi}
\begin{figure}[ht]\centering%
\if@RAM
\begin{tabular}{|l|l|l|*{\the@sites}{|r|r|}}\hline
\else
\begin{tabular}{|l|l|l|*{\the@sites}{|r|}}\hline
\fi
\wpfig@headline\\\hline\hline
\@wp@lines\hline
\multicolumn{3}{|c|}{\textbf{totals}}\@totals\\\hline
\end{tabular}
\caption{Work Areas and Work Packages [R{\if@RAM(A)\fi}M $\widehat=$ Researcher \if@RAM(Assistant)\fi Months]}\label{fig:wplist}
\end{figure}}
%    \end{macrocode}
% \end{macro}
% 
% \subsection{Gantt Charts}\label{sec:impl:gantt}
%
% Gantt Charts are done with help of the the |tikz| package. The |gantt|
% environments pick up on the declared duration of the proposal in months stored in the
% |\dfg@gen@months| macro.
% 
% We define the keys for Gantt tables
%    \begin{macrocode}
\newif\ifgantt@draft
\define@key{gantt}{xscale}{\def\gantt@xscale{#1}}
\define@key{gantt}{yscale}{\def\gantt@yscale{#1}}
\define@key{gantt}{step}{\def\gantt@step{#1}}
\define@key{gantt}{size}{\def\gantt@size{#1}}
\define@key{gantt}{draft}[true]{\gantt@drafttrue}
\newif\ifgantt@RMdisclaimer\gantt@RMdisclaimerfalse
\define@key{gantt}{RMdisclaimer}[true]{\gantt@RMdisclaimertrue}
%    \end{macrocode}
% Then we define an auxiliary function that provides defaults for these keys and sets the
% internal macros.
%    \begin{macrocode}
\def\gantt@set#1{\gantt@draftfalse\def\gantt@xscale{1}\def\gantt@yscale{.35}\def\gantt@step{3}
\setkeys{gantt}{#1}}
%    \end{macrocode}
% Finally, the Gantt Chart environment itself.
% \begin{environment}{gantt}
%    \begin{macrocode}
\newenvironment{gantt}[1][]
{\gantt@set{#1}
\@ifundefined{gantt@size}{}{\csname\gantt@size\endcsname}
\def\gantt@wps{\euref@num{all}{wp}{count}}
\newdimen\gantt@ymonths
\gantt@ymonths=\gantt@wps cm
\advance\gantt@ymonths by .5cm
\begin{tikzpicture}[xscale=\gantt@xscale,yscale=\gantt@yscale]
\draw[xstep=\gantt@step,gray,very thin] (0,0) grid (\dfg@gen@months,\gantt@wps);
\foreach \x in {0,\gantt@step,...,\dfg@gen@months} \node at (\x,\gantt@ymonths) {\x};}
{\end{tikzpicture}}
%    \end{macrocode}
% \end{environment}
%
% In this we have used the macro that does the actual painting. 
%    \begin{macrocode}
\newdimen\gantt@ymid\newdimen\gantt@yinc\newdimen\gantt@xend
\newcommand{\@action}[5]{%\message{@action: id=#1, line=#2, start=#3, dur=#4, int=#5.}
\gantt@ymid=#2 cm\gantt@yinc=\gantt@yscale cm
\gantt@xend=#3 cm\advance\gantt@xend by #4 cm
\advance\gantt@ymid by \gantt@yinc
\fill (#3,#2) rectangle +(#4,#5);
\node (#1@left) at (#3,\gantt@ymid) {};
\node (#1@right) at (\gantt@xend,\gantt@ymid) {};}
%    \end{macrocode}
% 
%    \begin{macrocode}
\def\@dependency#1#2{\draw[->,line width=2pt,color=red] (#1@right) -- (#2@left);}
%    \end{macrocode}
% 
% \begin{macro}{\ganttchart}
%   This macro iterates over the work areas, their work packages, and finally their work
%   phases to use the internal macro |\@action|. All of this in the gantt setting.
%    \begin{macrocode}
\newcommand{\ganttchart}[1][]{\begin{figure}[ht]\centering
\begin{gantt}[#1]
 \newcounter{taskwps}\newcount\@@line
  \edef\@@was{\euref@safe{all}{wa}{ids}}
  \@for\@@wa:=\@@was\do{% iterate over work areas
    \edef\@@wps{\euref@safe\@@wa{wp}{ids}}
    \@for\@@wp:=\@@wps\do{% iterate over work packages
      \stepcounter{taskwps}
     \@@line=\gantt@wps\advance\@@line by -\thetaskwps
      \edef\@@tasks{\euref@safe\@@wp{task}{ids}}
      \node at (-1/\gantt@xscale,\@@line) [above=-2pt] {\euRef{wp}\@@wp{label}};
      \@for\@@task:=\@@tasks\do{% iterate over work phases
      \@action\@@task\@@line
          {\euref@num{task}\@@task{start}}
          {\euref@num{task}\@@task{len}}
          {\euref@num{task}\@@task{force}}}}}
    \edef\@@deps{\euref@safe{all}{task}{deps}}
    \@for\@@dep:=\@@deps\do{\@dependency{\euref@safe{taskdep}\@@dep{from}}{\euref@safe{taskdep}\@@dep{to}}}
 \ifgantt@draft
    \newcounter{gantt@month}
    \newcount\@@e\newdimen\gantt@effort\newdimen\gantt@plus
    \@whilenum\thegantt@month<\dfg@gen@months\do{% step over months
      \gantt@effort=0cm
      \edef\@@was{\euref@safe{all}{wa}{ids}}
      \@for\@@wa:=\@@was\do{% iterate over work areas
        \edef\@@wps{\euref@safe\@@wa{wp}{ids}}
        \@for\@@wp:=\@@wps\do{% iterate over work packages
          \edef\@@tasks{\euref@safe\@@wp{task}{ids}}
          \@for\@@task:=\@@tasks\do{% iterate over work phases
            \@@e=\euref@num{task}\@@task{start}
            \advance\@@e by \euref@num{task}\@@task{len}
            \ifnum\thegantt@month<\euref@num{task}\@@task{start}\else
            \ifnum\thegantt@month<\@@e
            \gantt@plus=\euref@num{task}\@@task{force}cm
            \advance\gantt@effort by \gantt@plus\fi\fi
            \fill  (\thegantt@month,-5) rectangle +(1,\gantt@effort);}}}
     \stepcounter{gantt@month}}\fi
  \end{gantt}
  \ifgantt@RMdisclaimer
  \caption{Overview Work Package Activities}
  \else
  \caption{Overview Work Package Activities \if@RAM(the table only shows efforts
    for the junior researchers (RM))\fi}
  \fi\label{fig:activities}
\end{figure}}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Miscellaneous}\label{sec:impl:misc}
% 
% 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}{\signatures}
%    \begin{macrocode}
\newcommand{\signatures}{\section{Signatures \deu{(Unterschriften)}}
\qquad\number\day. \number\month. \number\year\\[2ex]
\strut\qquad Date\hfill\@for\@p:=\dfg@gen@PIs\do{%
\dcm@pers@ref\@p{personaltitle}~\dcm@pers@ref\@p{name}\hfill}}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\@dmp}
%    \begin{macrocode}
\def\@dmp#1{\ifkeys\marginpar{#1}\fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\texteuro}
%    \begin{macrocode}
\def\texteuro{\officialeuro\xspace}
%    \end{macrocode}
% \end{macro}
% \Finale
\endinput
% LocalWords:  dfgproposal dtx kohlhase areastrue svninfo noworkareas twoside
% LocalWords:  areasfalse dcm textcomp amssymb url graphicx colortbl xcolor RO
% LocalWords:  fancyhdr keyval eurosym tikz calc USenglish ngerman linkcolor ne
% LocalWords:  citecolor urlcolor colorlinks pagecolor breaklinks bookmarksopen
% LocalWords:  hyperref LaTeX workpackage PIs thema acrolong anzungsantrag im
% LocalWords:  Einzelverfahren tabline Allgemeine Angaben Antragsteller worktel
% LocalWords:  bitabline personaltitle academictitle birthdate Dienstanschrift
% LocalWords:  workaddress atabline workfax Privatanschrift privaddress privtel
% LocalWords:  dt Kennwort Fachgebiet und Arbeitsrichtung Voraussichtliche wa
% LocalWords:  Gesamtdauer Antragszeitraum Zusammenfassung workarea wp wps num
% LocalWords:  refundefinedtrue lightgray gantt xstep Unterschriften Id areas
% LocalWords:  submit hide ed public article paper today array comment wide RE
% LocalWords:  babel true bookmarks blue LO LE page of prop sites key site RM
% LocalWords:  def id title acronym discipline start months Proposal Erg by cls
% LocalWords:  DFG empty em name affiliation Applicants Work Address email The
% LocalWords:  curriculum vita the applicants are enclosed appendix reference
% LocalWords:  Research area and field work Scientific Fields Anticipated write
% LocalWords:  duration Application period Summary short lead Package label task
% LocalWords:  tasks deps number line Effort target ids aux dfg count warning at
% LocalWords:  for undefined safe zero one two three four five six seven eight
% LocalWords:  nine ten eleven twelve style lines totals Packages xscale yscale
% LocalWords:  step set gray very thin grid workphase len force phase length to
% LocalWords:  taskdep from rectangle left right width pt color red above dep
% LocalWords:  Overview Activities Signatures Date paralist ymonths ymid yinc
% LocalWords:  xend effort month iffalse eustrep.dtx fileversion maketitle Antr
% LocalWords:  tableofcontents DescribeEnv ifpublic ifpublic compactitem wpfig
% LocalWords:  wpfig workplan workplan bookeeping wissenchaftliche tasklist dmp
% LocalWords:  tasklist taskin taskref taskref tasktref tasktref localtaskref
% LocalWords:  localtaskref ganttchart biblatex dfgprojpapers dfgprojpapers ifx
% LocalWords:  bibtex proposal1-blx.aux euref WPtref WPtref WAref WAref WAtref
% LocalWords:  WAtref protectmacro thebibliography bibitem newblock newif inst
% LocalWords:  ifsubmit submitfalse publicfalse ifkeys keysfalse ifwork RAMtrue
% LocalWords:  submittrue publictrue excludecomment RAMfalse keystrue sfdefault
% LocalWords:  renewcommand familydefault helvet includecomment subsubsections
% LocalWords:  setcounter secnumdepth ifofpage ofpagefalse fancyhead thepage sw
% LocalWords:  pagestyle fancyplain sitesfalse sitestrue ifundefined gdef allwp
% LocalWords:  fundedperiod reportperiod textbf newenvironment titlepage auxout
% LocalWords:  thispagestyle newcounter stepcounter tocdepth ofpagetrue setkeys
% LocalWords:  finalreport orderzeitraum thewa thewp addtocounter bigskip pws
% LocalWords:  textsf smallskip ignorespaces subsubsection thedfg theallwp req
% LocalWords:  compactenum compactenum thetask newcount thegantt refsection
% LocalWords:  nocite defbibheading ourpubs printbibliography expandafter ifnum
% LocalWords:  csname endcsname dfgcount ifcase cellcolor wptable widehat qquad
% LocalWords:  tabularnewline wplist ifgantt drafttrue RMdisclaimer draftfalse
% LocalWords:  RMdisclaimerfalse RMdisclaimertrue newdimen taskwps thetaskwps
% LocalWords:  whilenum hfill marginpar texteuro officialeuro texttt
