% \iffalse meta-comment
% An Infrastructure for managing addresses and affiliations in LaTeX
% Copyright (c) 2011 Michael Kohlhase, all rights reserved
%               this file is released under the
%               LaTeX Project Public License (LPPL)
% The original of this file is in the public repository at 
% http://github.com/KWARC/sTeX/
% \fi
% 
% \iffalse
%<*package>
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{workaddress}[2016/04/07 v0.4 WorkAddress]
%</package>
%<*driver>
\documentclass{ltxdoc}
\usepackage{workaddress,sref,url,array,float}
\usepackage[show]{ed}
\usepackage[hyperref=auto,style=alphabetic]{biblatex}
\addbibresource{kwarcpubs.bib}
\addbibresource{extpubs.bib}
\addbibresource{kwarccrossrefs.bib}
\addbibresource{extcrossrefs.bib}
\usepackage{ctangit}
\usepackage{hyperref}
\usepackage{stex-logo}
\makeindex
\floatstyle{boxed}
\newfloat{exfig}{thp}{lop}
\floatname{exfig}{Example}
\WAperson[id=jdoe,affiliation=dfki,department=skss,
           url=http://dfki.de/jdoe]
          {John Doe}
\WAperson[id=miko,affiliation=jacu,department=case,
           url=http://kwarc.info/kohlhase]
          {Michael Kohlhase}
\WAinstitution[id=case,acronym=CASE,
                url=http://jacobs-university.de/ses/case,partof=jacu]
               {Center for Advanced Systems Engineering}
\WAinstitution[id=jacu,url=http://jacobs-university.de,shortname=Jacobs University,acronym=JU]
               {Jacobs University Bremen}
\WAinstitution[id=skss,url=http://dfki.de/sks,partof=dfki,acronym=SKS,]
               {Safe and Secure Cognitive Systems}
\WAinstitution[id=dfki,url=http://dfki.de,acronym=DFKI,shortname=DFKI]
               {German Research Center for Artificial Intelligence}
\def\tracissue#1{\cite{sTeX:online}, \hyperlink{http://trac.kwarc.info/sTeX/ticket/#1}{issue #1}}
\begin{document}\DocInput{workaddress.dtx}\end{document}
%</driver>
% \fi
%
%\CheckSum{334}
%
% \changes{v0.4}{2011/11/04}{Extracting from dcm.sty}
% \changes{v0.4}{2012/01/18}{new functionality for logos}
% 
% \GetFileInfo{workaddress.sty}
% 
% \MakeShortVerb{\|}
% \def\scsys#1{{{\sc #1}}\index{#1@{\sc #1}}}
% \def\latexml{\scsys{LaTeXML}}
%
%   \title{{\texttt{workaddress.sty}}: An Infrastructure for managing Addresses and
%   Affiliations in {\LaTeX}\thanks{Version {\fileversion} (last revised {\filedate})}}
%   \author{\WAauthorblock[aff,url]{miko,jdoe}}
%   \maketitle
%   \begin{abstract}The |workaddress| package allows manage addresses and Affiliations in
%     a bib\TeX-like manner.\ednote{continue}
%   \end{abstract}
%
% \setcounter{tocdepth}{2}\tableofcontents\newpage
%
% \section{Introduction}\label{sec:intro}
%
% The |workaddress| package allows manage Addresses and affiliations of persons in a
% bib\TeX-like manner.\ednote{continue}
% 
% \section{The User Interface}\label{sec:user}
% 
% \subsection{Package Options}\label{sec:user.options}
% 
% The |workaddress| package takes a single option: \DescribeMacro{showmeta}|showmeta|. If
% this is set, then the metadata keys are shown (see~\cite{Kohlhase:metakeys:ctan} for
% details and customization options).
%
% \subsection{Database Entries for Persons}
% 
% The |workaddress| package recognizes that from a metadata perspective, persons are complex
% entities. In particular, specifying metadata is a tedious and repetitive task that leads
% to embarrassing errors. Therefore the |workaddress| package takes a hint from bibTeX and allows
% to specify personal metadata in a database and use it by a database key.
% \begin{exfig}[ht]
% \begin{verbatim}
% \WAperson[id=jdoe,affiliation=dfki,department=skss,
%            url=http://dfki.de/jdoe]
%           {John Doe}
% \WAperson[id=miko,affiliation=jacu,department=case,
%            url=http://kwarc.info/kohlhase]
%           {Michael Kohlhase}
% \end{verbatim}
% \caption{A small database of Persons}
% \label{fig:persons}
% \end{exfig}
% The \DescribeMacro{\WAperson}|\WAperson| macro allows to specify personal metadata\ednote{This
% should be synchronized with the FOAF specification~\cite{FOAF:spec}} with the following
% keys: 
% \begin{center}
% \begin{tabular}{|l|l|l|}\hline
% key & value & comment\\\hline\hline
% id & string & identifier of this person\\\hline
% birthdate & date & birthdate \\\hline
% email & & the primary e-mail address\\\hline
% url & URI & primary home page \\\hline
% affiliation & Inst. identifier & the primary professional affiliation\\\hline
% personaltitle & string & the personal title e.g. {\texttt{King}}\\\hline
% academictitle & string & the academic title e.g. {\texttt{Prof. Dr.}}\\\hline
% department & Inst. identifier & the department specified in the work address\\\hline
% workaddress & long string & the work address \\\hline
% privaddress & long string & the private address \\\hline
% worktel & string & work telephone number \\\hline
% privtel & string & private telephone number\\\hline
% workfax & string & work fax number \\\hline
% privfax & string & private fax number \\\hline
% worktelfax & string & if the phone and fax share a prefix, give this as well \\\hline
% privtelfax & string & dito\\\hline
% \end{tabular}
% \end{center}
% In Figure~\ref{fig:persons} we have specified (minimal) metadata for the authors of the
% |workaddress| package. The metadata can be accessed by specifying the identifiers (given by the
% |id| key) in the |workaddress| macros defined below, see for instance the |\WAcreators| macro
% in Figure~\ref{fig:workaddressblock}, which leads to the title block of this note.
% 
% Like in bibTeX~\cite{Patashnik:b88}, it is a good idea to collect the metadata in a separate
% file that is input in the document. In practice it may be possible to generate these
% files from conventional address databases.
% 
% \subsection{Institutions}
% 
% Institutions are treated analogously to persons.
% \begin{exfig}[ht]
% \begin{verbatim}
% \WAinstitution[id=case,partof=jacu,acronym=CASE,
%                 url=http://jacobs-university.de/ses/case]
%                {Center for Advanced Systems Engineering}
% \WAinstitution[id=jacu,url=http://jacobs-university.de]
%                {Jacobs University Bremen}
% \WAinstitution[id=skss,partof=dfki,url=http://dfki.de/sks,acronym=SKS]
%                {Safe and Secure Cognitive Systems}
% \WAinstitution[id=dfki,url=http://dfki.de,shortname=DFKI,acronym=DFKI]
%                {German Research Center for Artificial Intelligence}
% \end{verbatim}
% \caption{A small Database of Institutions and their Parts}
% \label{fig:institutions}
% \end{exfig}
% The \DescribeMacro{\WAinstitution}|\WAinstitution| macro allows to specify personal
% metadata\ednote{This should be synchronized with the FOAF
% specification~\cite{FOAF:spec}} with the following keys:
% \begin{center}
% \begin{tabular}{|l|l|l|}\hline
% key & value & comment\\\hline\hline
% id & string & identifier of this person\\\hline
% url & URI & primary home page \\\hline
% partof & Inst. identifier & parent institution\\\hline
% \end{tabular}
% \end{center}
% 
% \subsection{Applications}\label{sec:user.appl}
% 
% The data from the address database can be used in various ways. For instance, the
% \DescribeMacro{\WAauthorblock}|\WAauthorblock| macro creates a block of users and their
% affiliations. In the context of the database from Figures~\ref{fig:persons}
% and~\ref{fig:institutions}, |\WAauthorblock{miko,jdoe}| creates
% \begin{center}\WAauthorblock{miko,jdoe}\end{center}
%
% \DescribeMacro{\wa@institution@logo}|\wa@institution@logo| creates the logo of an
% institution from the database, and (if that is not there create a box and a message
% instead.)
% 
% \section{Limitations}\label{sec:limitations}
% 
% In this section we document known limitations. If you want to help alleviate them,
% please feel free to contact the package author. Some of them are currently discussed in
% the \sTeX GitHub repository~\cite{sTeX:github:on}. 
% \begin{compactenum}
% \item none reported yet
% \end{compactenum}
% 
% \StopEventually{\printbibliography}
% 
% \section{The Implementation}\label{sec:impl}
%
% \subsection{Package Options}\label{sec:impl.options}
% The first step is to declare (a few) package options that handle whether certain
% information is printed or not. They all come with their own conditionals that are set by
% the options.
%
%    \begin{macrocode}
%<*package>
\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{sref}}
\ProcessOptions
%    \end{macrocode}
%
% The first measure is to ensure that the |KeyVal| package is loaded (in the right
% version). For {\latexml} we also initialize the package inclusions. 
%    \begin{macrocode}
\RequirePackage{sref}
%    \end{macrocode}
%
% \subsection{Persons}
% 
% To implement the |\WAperson| macro, we need to implement its keywords.
%
%    \begin{macrocode}
\addmetakey*{wa@person}{id}
\addmetakey*{wa@person}{birthdate}
\addmetakey*{wa@person}{email}
\addmetakey*{wa@person}{url}
\addmetakey*{wa@person}{affiliation}
\addmetakey*{wa@person}{personaltitle}
\addmetakey*{wa@person}{academictitle}
\addmetakey*{wa@person}{department}
\addmetakey*{wa@person}{workaddress}
\addmetakey*{wa@person}{privaddress}
\addmetakey*{wa@person}{worktel}
\addmetakey*{wa@person}{privtel}
\addmetakey*{wa@person}{workfax}
\addmetakey*{wa@person}{privfax}
\addmetakey*{wa@person}{worktelfax}
\addmetakey*{wa@person}{privtelfax}
%    \end{macrocode}
% 
% \begin{macro}{\wa@def}
%   The next macro is an auxiliary one that puts the value into an appropriate token
%   register. 
%    \begin{macrocode}
\def\wa@def#1#2#3#4{\expandafter\xdef\csname wa@#1@#2@#3\endcsname{#4}}
%    \end{macrocode}
% \end{macro}
% 
% 
% \begin{macro}{\wa@ref@test}
%   This macro tests whether the information specified is defined, and gives an error
%   message else.
%    \begin{macrocode}
\def\wa@ref@test#1#2#3{%
  \@ifundefined{wa@#1@#2@#3}{%
    \PackageError{workaddress}{reference to undefined #3 of #1 #2}%
    {you must define a #1 with #2=#3\MessageBreak% 
     via the macro \protect\WA#1, before you can use it!}
  }{}%
}%
%    \end{macrocode}
% \end{macro}
%
% With this, referencing is simple
%
% \begin{macro}{\wa@ref}
%    \begin{macrocode}
\def\wa@ref#1#2#3{%
  \wa@ref@test{#1}{#2}{#3}%
  \csname wa@#1@#2@#3\endcsname%
}%
%    \end{macrocode}
% \end{macro}
% 
% With this we can define the |\WAperson| macro, it just clears the keys, sets them
% again, and stores them in token registers. If course only if a |id| attribute is given,
% else we raise an error.
% 
% \begin{macro}{WAperson}
%    \begin{macrocode}
\let\wa@persons=\relax
\newcommand\WAperson[2][]{%
  \metasetkeys{wa@person}{#1}%
  \ifx\wa@person@id\@empty%
    \@latex@warning{key 'id' undefined in WAperson}%
  \else%
    \wa@def{person}\wa@person@id{id}{\wa@person@id}% redundant, but useful for checking
    \wa@def{person}\wa@person@id{name}{#2}
    \wa@def{person}\wa@person@id{email}{\wa@person@email}
    \wa@def{person}\wa@person@id{birthdate}{\wa@person@birthdate}
    \wa@def{person}\wa@person@id{url}{\wa@person@url}
    \wa@def{person}\wa@person@id{affiliation}{\wa@person@affiliation}
    \wa@def{person}\wa@person@id{workaddress}{\wa@person@workaddress}
    \wa@def{person}\wa@person@id{privaddress}{\wa@person@privaddress}
    \wa@def{person}\wa@person@id{personaltitle}{\wa@person@personaltitle}
    \wa@def{person}\wa@person@id{academictitle}{\wa@person@academictitle}
    \wa@def{person}\wa@person@id{department}{\wa@person@department}
    \wa@def{person}\wa@person@id{workaddress}{\wa@person@workaddress}
    \wa@def{person}\wa@person@id{privaddress}{\wa@person@privaddress}
    \wa@def{person}\wa@person@id{worktel}{\wa@person@worktel}
    \wa@def{person}\wa@person@id{privtel}{\wa@person@privtel}
    \wa@def{person}\wa@person@id{workfax}{\wa@person@workfax}
    \wa@def{person}\wa@person@id{privfax}{\wa@person@privfax}
    \wa@def{person}\wa@person@id{worktelfax}{\wa@person@worktelfax}
    \wa@def{person}\wa@person@id{privtelfax}{\wa@person@privtelfax}
    \@ifundefined{wa@persons}{%
      \xdef\wa@persons{\wa@person@id}%
    }{%
      \xdef\wa@persons{\wa@persons,\wa@person@id}%
    }%
  \fi%
}%
\newcommand\DCMperson[2][]{%
  \WAperson[#1]{#2}%
  \PackageWarning{workaddress}{\protect\DCMperson\space is deprecated, use \protect\WAperson\space instead}
}%
%    \end{macrocode}
% \end{macro}
%
% \subsection{Institutions}
% 
% To implement the |\WAinstitution| macro, we need to implement its keywords first.
%
%    \begin{macrocode}
\addmetakey*{wa@institution}{id}
\addmetakey*{wa@institution}{shortname}
\addmetakey*{wa@institution}{acronym}
\addmetakey*{wa@institution}{url}
\addmetakey*{wa@institution}{partof}
\addmetakey*{wa@institution}{countryshort}
\addmetakey*{wa@institution}{logo}
\addmetakey*{wa@institution}{streetaddress}
\addmetakey*{wa@institution}{townzip}
\addmetakey*{wa@institution}{type}
\addmetakey*{wa@institution}{country}
%    \end{macrocode}
% and we proceed as for |\WAperson|, 
%    \begin{macrocode}
\let\wa@institutions=\relax
%    \end{macrocode}
%
% \begin{macro}{WAinstitution}
%    \begin{macrocode}
\newcommand\WAinstitution[2][]{%
  \metasetkeys{wa@institution}{#1}%
  \ifx\wa@institution@id\@empty%
    \@latex@warning{key 'id' undefined in WAinstitution}%
  \else%
    \wa@def{institution}\wa@institution@id{id}{\wa@institution@id}% redundant, but useful for checking
    \wa@def{institution}\wa@institution@id{name}{#2}
    \wa@def{institution}\wa@institution@id{shortname}{\wa@institution@shortname}
    \wa@def{institution}\wa@institution@id{acronym}{\wa@institution@acronym}
    \wa@def{institution}\wa@institution@id{url}{\wa@institution@url}
    \wa@def{institution}\wa@institution@id{partof}{\wa@institution@partof}
    \wa@def{institution}\wa@institution@id{countryshort}{\wa@institution@countryshort}
    \wa@def{institution}\wa@institution@id{logo}{\wa@institution@logo}
    \wa@def{institution}\wa@institution@id{townzip}{\wa@institution@townzip}
    \wa@def{institution}\wa@institution@id{streetaddress}{\wa@institution@streetaddress}
    \wa@def{institution}\wa@institution@id{country}{\wa@institution@country}
    \wa@def{institution}\wa@institution@id{type}{\wa@institution@type}
    \@ifundefined{wa@institutions}{%
      \xdef\wa@institutions{\wa@institution@id}%
    }{%
      \xdef\wa@institutions{\wa@institutions,\wa@institution@id}%
    }%
  \fi%
}%
\newcommand\DCMinstitution[2][]{%
  \WAinstitution[#1]{#2}%
  \PackageWarning{workaddress}{\protect\DCMinstitution\space is deprecated, use \protect\WAinstitution\space instead}%
}%
%    \end{macrocode}
% \end{macro}
% 
%\subsection{Applications}\label{sec:impl.appl}
%
% \begin{macro}{\WAauthorblock}
%   This internal macro builds an author block from a list of |\WAperson| labels in
%   |\wa@creators|.
%    \begin{macrocode}
\addmetakey[false]{WAauthorblock}{dept}[true]
\addmetakey[false]{WAauthorblock}{aff}[true]
\addmetakey[false]{WAauthorblock}{url}[true]
\def\@true{true}
\newcounter{authors}
\newcommand\WAauthorblock[2][]{%
  \metasetkeys{WAauthorblock}{#1}
  {\let\tabularnewline\relax
   \@for\@I:=#2\do{\stepcounter{authors}}
   \def\@authors{}%
   \def\@affs{}%
   \def\@depts{}%
   \def\@urls{}%
   \@for\@I:=#2\do{%
     \xdef\@authors{\@authors&\wa@ref{person}\@I{name}}
     \xdef\@@dept{\wa@ref{person}\@I{department}}
     \xdef\@shortname{\csname wa@institution@\@@dept @shortname\endcsname}
     \xdef\@dept{\ifx\@shortname\@empty\wa@ref{institution}\@@dept{name}\else\@shortname\fi}
     \xdef\@depts{\@depts&\@dept}
     \xdef\@@aff{\wa@ref{person}\@I{affiliation}}
     \xdef\@shortname{\csname wa@institution@\@@aff @shortname\endcsname}
     \xdef\@aff{\ifx\@shortname\@empty\wa@ref{institution}\@@aff{name}\else\@shortname\fi}
     \xdef\@affs{\@affs&\@aff}
     \xdef\@urls{\@urls&\wa@ref{person}\@I{url}}
   }%
   \message{\theauthors authors: \@authors}%
  }%
  \begin{tabular}[t]{l*{\theauthors}{c}}
    \@authors\\
    \ifx\WAauthorblock@dept\@true\@depts\\\fi
    \ifx\WAauthorblock@aff\@true\@affs\\\fi
    \ifx\WAauthorblock@url\@true\@urls\\\fi
  \end{tabular}
}%
%    \begin{macrocode}
% \end{macro}
%
% \begin{macro}{\wapname}
%    \begin{macrocode}
\newcommand\wapname[1]{\wa@ref{person}{#1}{name}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\waptname}
%    \begin{macrocode}
\newcommand\waptname[1]{\wa@ref{person}{#1}{personaltitle} \wa@ref{person}{#1}{name}}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\wa@institution@logo}
%    \begin{macrocode}
\newcommand\wa@institution@logo[2][]{%
  \IfFileExists{\wa@ref{institution}{#2}{logo}}{%
    \includegraphics{\wa@ref{institution}{#2}{logo}}%
  }{%
    \fbox{#2 logo}\message{still need logo for #2}%
  }%
}%
%</package>
%    \end{macrocode}
% \end{macro}
%
% \Finale
\endinput
% \iffalse
%%% Local Variables: 
%%% mode: doctex
%%% TeX-master: t
%%% End: 
% \fi

% LocalWords:  RequirePackage birthdate personaltitle academictitle workaddress
% LocalWords:  privaddress worktel privtel workfax privfax worktelfax noDelim
% LocalWords:  privtelfax getKeyValue valuelist ToString getValue affill STDERR
% LocalWords:  ExportMetadata AssignValue WAperson DefConstructor afterDigest
% LocalWords:  getArg setValue FishOutMetadata keyvals foreach idlist tabline
% LocalWords:  LookupValue insertElement atabline bitabline shorttitle nc args
% LocalWords:  sharealike noderivativeworks DefMacro authorblock subsubsection
% LocalWords:  contribs OptionalKeyVals omgroup omdoc srcref xml RawTeX partof
% LocalWords:  openElement iffalse kohlhase Thu scsys sc sc latexml 
% LocalWords:  maketitle WAtitle texttt fileversion WAcreators miko jdoe impl
% LocalWords:  WAabstract setcounter tocdepth tableofcontents newpage dmt03
% LocalWords:  WAsection ednote WAsubsection exfig hline dcmblock Patashnik
% LocalWords:  DescribeEnv WAcontributors WAshorttitle WAshorttitle WAdate
% LocalWords:  WAsubject WAsubject WAdescription WAdescription WApublisher
% LocalWords:  WApublisher WAdate WAtype WAtype WAidentifier WAidentifier
% LocalWords:  WAsource WAsource WAlanguage WAlanguage WArelation ctancite
% LocalWords:  WArelation WArights WArights WAlicense WAlicense titlepage
% LocalWords:  WAlicensenotice WAlicensenotice WAcopyrightnotice titlepage
% LocalWords:  WAcopyrightnotice WAcclicense WAcclicense user.blockstyles
% LocalWords:  WAchapter WAchatper WAsubsubsection WAsubsubsection ltxml
% LocalWords:  user.conig makeatletter printbibliography expandafter showmeta
% LocalWords:  xdef csname endcsname newcommand ifx ifundefined affs showmeta
% LocalWords:  Semiverbatim whatsit newenvironment mtabline providecommand vfil
% LocalWords:  WAsubtitle cclicense defdcm impl.blockstyles newcounter vskip
% LocalWords:  stepcounter tabularnewline theauthors lineskip textbf noindent
% LocalWords:  omd omd srefaddidkey thechapter autoclose thesection ifnum ifnum
% LocalWords:  thesubsection thesubsubsection WAparagraph ISOtimestamp doctex
% LocalWords:  WAinstitution WAinstitution compactenum textsf langle textsf
% LocalWords:  langle metakeys addmetakey metasetkeys countryshort townzip aff
% LocalWords:  streetaddress depts
