%%
%% This is file `modules.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% modules.dtx  (with options: `package')
%% 
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{modules}[2012/01/28 v1.1 Semantic Markup]
\DeclareOption{showmeta}{\PassOptionsToPackage{\CurrentOption}{metakeys}}
\newif\ifmod@show\mod@showfalse
\DeclareOption{showmods}{\mod@showtrue}
\newif\ifmod@qualified\mod@qualifiedfalse
\DeclareOption{qualifiedimports}{\mod@qualifiedtrue}
\ProcessOptions
\RequirePackage{sref}
\RequirePackage{xspace}
\RequirePackage{xcomment}
\addmetakey{module}{cd}
\addmetakey{module}{title}
\define@key{module}{id}{%
\edef\this@module{\expandafter\noexpand\csname module@defs@#1\endcsname}%
\global\@namedef{module@defs@#1}{}%
\ifmod@qualified
\edef\this@qualified@module{\expandafter\noexpand\csname module@defs@qualified@#1\endcsname}%
\global\@namedef{module@defs@qualified@#1}{}%
\fi
\def\mod@id{#1}%
\expandafter\edef\csname #1@cd@file@base\endcsname{\mod@path}%
\expandafter\g@addto@macro\csname module@defs@#1\expandafter\endcsname\expandafter%
{\expandafter\def\csname #1@cd@file@base\expandafter\endcsname\expandafter{\mod@path}}}
\newcounter{module}[section]
\newcommand\module@heading{\stepcounter{module}%
\noindent{\textbf{Module} \thesection.\themodule [\mod@id]}%
\sref@label@id{Module \thesection.\themodule [\mod@id]}%
\ifx\module@title\@empty :\quad\else\quad(\module@title)\hfill\\\fi}
\newcommand\module@footer{\noindent{\textbf{EndModule} \thesection.\themodule}}
\newenvironment{module}[1][]%
{\metasetkeys{module}{#1}\ifmod@show\module@heading\fi}
{\ifmod@show\module@footer\fi}
\def\activate@defs#1{\csname module@defs@#1\endcsname}
\def\export@defs#1{\@ifundefined{mod@id}{}%
{\expandafter\expandafter\expandafter\g@addto@macro\expandafter%
\this@module\expandafter{\csname module@defs@#1\endcsname}}}
\def\coolurion{}
\def\coolurioff{}
\newcommand{\importmodule}[2][]{{\def\mod@path{#1}%
\ifx\mod@path\@empty\else\requiremodules{#1}\fi}%
\activate@defs{#2}\export@defs{#2}}
\newenvironment{importmodulevia}[2][]{\gdef\@@doit{\importmodule[#1]{#2}}%
\ifmod@show\par\noindent importing module #2 via \@@doit\fi}
{\aftergroup\@@doit\ifmod@show end import\fi}
\newcommand\vassign[2]{\ifmod@show\ensuremath{#1\mapsto #2}, \fi}
\newcommand\tassign[3][]{\ifmod@show #2\ensuremath{\mapsto} #3, \fi}
\newcommand\ttassign[3][]{\ifmod@show #1\ensuremath{\mapsto} ``#2'', \fi}
\newcommand{\importOMDocmodule}[3][]{\importmodule[#1]{#3}}
\let\metalanguage=\importmodule
\def\mod@newcommand{\@star@or@long\mod@new@command}
\def\mod@new@command#1{\@testopt{\@mod@newcommand#1}0}
\def\@mod@newcommand#1[#2]{\kernel@ifnextchar [{\mod@xargdef#1[#2]}{\mod@argdef#1[#2]}}
\long\def\mod@argdef#1[#2]#3{\@yargdef#1\@ne{#2}{#3}}
\long\def\mod@xargdef#1[#2][#3]#4{\expandafter\def\expandafter#1\expandafter{%
\expandafter\@protected@testopt\expandafter #1\csname\string#1\endcsname{#3}}%
\expandafter\@yargdef\csname\string#1\endcsname\tw@{#2}{#4}}
\newif\if@symdeflocal
\define@key{symdef}{local}[true]{\@symdeflocaltrue}
\define@key{symdef}{name}{}
\define@key{symdef}{assocarg}{}
\define@key{symdef}{bvars}{}
\define@key{symdef}{bvar}{}
\define@key{symdef}{bindargs}{}
\def\symdef{\@ifnextchar[{\@symdef}{\@symdef[]}}
\def\@symdef[#1]#2{\@ifnextchar[{\@@symdef[#1]{#2}}{\@@symdef[#1]{#2}[0]}}
\def\@mod@nc#1{\mod@newcommand{#1}[1]}
\def\@@symdef[#1]#2[#3]#4{%
\@symdeflocalfalse\setkeys{symdef}{#1}%
\expandafter\mod@newcommand\csname modules@#2@pres@\endcsname[#3]{#4}%
\expandafter\def\csname #2\endcsname%
{\@ifnextchar[{\csname modules@#2\endcsname}{\csname modules@#2\endcsname[]}}%
\expandafter\def\csname modules@#2\endcsname[##1]%
{\csname modules@#2@pres@##1\endcsname}%
\expandafter\@mod@nc\csname mod@symref@#2\expandafter\endcsname\expandafter%
{\expandafter\mod@termref\expandafter{\mod@id}{#2}{##1}}%
\if@symdeflocal\else%
\@ifundefined{mod@id}{}{%
\expandafter\g@addto@macro\this@module%
{\expandafter\mod@newcommand\csname modules@#2@pres@\endcsname[#3]{#4}}%
\expandafter\g@addto@macro\this@module%
{\expandafter\def\csname#2\endcsname%
{\@ifnextchar[{\csname modules@#2\endcsname}{\csname modules@#2\endcsname[]}}}%
\expandafter\g@addto@macro\this@module%
{\expandafter\def\csname modules@#2\endcsname[##1]%
{\csname modules@#2@pres@##1\endcsname}}%
\expandafter\g@addto@macro\csname  module@defs@\mod@id\expandafter\endcsname\expandafter%
{\expandafter\@mod@nc\csname mod@symref@#2\expandafter\endcsname\expandafter%
{\expandafter\mod@termref\expandafter{\mod@id}{#2}{##1}}}%
\ifmod@qualified%
\expandafter\g@addto@macro\this@qualified@module%
{\expandafter\mod@newcommand\csname modules@#2@pres@qualified\endcsname[#3]{#4}}%
\expandafter\g@addto@macro\this@qualified@module%
{\expandafter\def\csname#2atqualified\endcsname{\csname modules@#2@pres@qualified\endcsname}}%
\fi%
}\fi}
\define@key{DefMathOp}{name}{\def\defmathop@name{#1}}
\newcommand\DefMathOp[2][]{%
\setkeys{DefMathOp}{#1}%
\symdef[#1]{\defmathop@name}{#2}}
\def\symvariant#1{\@ifnextchar[{\@symvariant{#1}}{\@symvariant{#1}[0]}}
\def\@symvariant#1[#2]#3#4{%
\expandafter\mod@newcommand\csname modules@#1@pres@#3\endcsname[#2]{#4}%
\@ifundefined{mod@id}{}{%
\expandafter\g@addto@macro\this@module%
{\expandafter\mod@newcommand\csname modules@#1@pres@#3\endcsname[#2]{#4}}}}%
\def\resymdef{\@ifnextchar[{\@resymdef}{\@resymdef[]}}
\def\@resymdef[#1]#2{\@ifnextchar[{\@@resymdef[#1]{#2}}{\@@resymdef[#1]{#2}[0]}}
\def\@@resymdef[#1]#2[#3]#4{\PackageError{modules}
  {The \protect\resymdef macro is deprecated,\MessageBreak
    use the \protect\symvariant instead!}}
\let\abbrdef\symdef
\def\mod@path{}
\def\mod@true{true}
\addmetakey[false]{termdef}{local}
\addmetakey{termdef}{name}
\newcommand{\termdef}[3][]{\metasetkeys{termdef}{#1}%
\expandafter\mod@newcommand\csname#2\endcsname[0]{#3\xspace}%
\ifx\termdef@local\mod@true\else%
\@ifundefined{mod@id}{}{\expandafter\g@addto@macro\this@module%
{\expandafter\mod@newcommand\csname#2\endcsname[0]{#3\xspace}}}%
\fi}
\def\@captitalize#1{\uppercase{#1}}
\newcommand\capitalize[1]{\expandafter\@captitalize #1}
\def\mod@termref#1#2#3{\def\@test{#3}
\@ifundefined{#1@cd@file@base}
    {\protect\G@refundefinedtrue
      \@latex@warning{\protect\termref with unidentified cd "#1": the cd key must
        reference an active module}
      \def\@label{sref@#2 @target}}
  {\def\@label{sref@#2@#1@target}}%
\expandafter\ifx\csname #1@cd@file@base\endcsname\@empty% local reference
\sref@hlink@ifh{\@label}{\ifx\@test\@empty #2\else #3\fi}\else%
\def\@uri{\csname #1@cd@file@base\endcsname.pdf\#\@label}%
\sref@href@ifh{\@uri}{\ifx\@test\@empty #2\else #3\fi}\fi}
\def\mod@simplify#1{\expandafter\mod@simpl#1/\relax}
\def\mod@simpl#1/#2\relax{\def\@second{#2}%
\ifx\mod@blaaaa\@empty\edef\mod@savedprefix{}\def\mod@blaaaa{aaa}\else\fi%
\ifx\@second\@empty\edef\mod@savedprefix{\mod@savedprefix#1}%
\else\mod@simplhelp#1/#2\relax\fi}
\def\mod@updir{..}
\def\mod@simplhelp#1/#2/#3\relax{\def\@first{#1}\def\@second{#2}\def\@third{#3}%
\ifx\@third\@empty% base case
\ifx\@second\mod@updir\else%

\ifx\mod@second\@empty\edef\mod@savedprefix{\mod@savedprefix#1}%
\else\edef\mod@savedprefix{\mod@savedprefix#1/#2}%
\fi%
\fi%
\else%
\ifx\@first\mod@updir%
\edef\mod@savedprefix{\mod@savedprefix#1/}\mod@simplhelp#2/#3\relax%
\else%
\ifx\@second\mod@updir\mod@simpl#3\relax%
\else\edef\mod@savedprefix{\mod@savedprefix#1/}\mod@simplhelp#2/#3\relax%
\fi%
\fi%
\fi}%
\newcommand{\defpath}[2]{\expandafter\newcommand\csname #1\endcsname[1]{#2/##1}}
\newif\ifmodules
\gdef\mod@reg{}
\def\mod@update#1{\ifx\mod@reg\@empty\xdef\mod@reg{#1}\else\xdef\mod@reg{#1@\mod@reg}\fi}
\def\mod@check#1@#2///#3\relax{%
\def\mod@one{#1}\def\mod@two{#2}\def\mod@three{#3}%
\expandafter%
\ifx\mod@three\mod@one\modulestrue%
\else%
\ifx\mod@two\@empty\modulesfalse\else\mod@check#2///#3\relax\fi%
\fi}
\def\mod@search#1{%
\modulesfalse\expandafter\mod@check\mod@reg @///#1\relax%
\ifmodules\else\mod@update{#1}\fi}
\def\mod@reguse#1{\modulesfalse\expandafter\mod@check\mod@reg @///#1\relax}
\def\mod@prefix{}
\def\mod@updatedpre#1{%
\edef\mod@prefix{\mod@prefix\mod@pathprefix@check#1/\relax}}
\def\mod@pathprefix@check#1/#2\relax{%
\ifx\\#2\\% no slash in string
\else\mod@ReturnAfterFi{#1/\mod@pathprefix@help#2\relax}%
\fi}
\def\mod@pathprefix@help#1/#2\relax{%
\ifx\\#2\\% end of recursion
\else\mod@ReturnAfterFi{#1/\mod@pathprefix@help#2\relax}%
\fi}
\long\def\mod@ReturnAfterFi#1\fi{\fi#1}
\def\mod@pathpostfix@check#1/#2\relax{% slash
\ifx\\#2\\%no slash in string
#1\else\mod@ReturnAfterFi{\mod@pathpostfix@help#2\relax}%
\fi}
\def\mod@pathpostfix@help#1/#2\relax{%
\ifx\\#2\\%
#1\else\mod@ReturnAfterFi{\mod@pathpostfix@help#2\relax}%
\fi}
\def\mod@updatedpost#1{%
\edef\mod@savedprefix{\mod@savedprefix\mod@pathpostfix@check#1/\relax}}
\def\mod@updatesms{\edef\mod@savedprefix{\mod@savedprefix.sms}}
\newcommand\requiremodules[1]{%
{\mod@showfalse% save state and ensure silence while reading sms
\mod@updatedpre{#1}% add the new file to the already existing path
\let\mod@savedprefix\mod@prefix% add the path to the new file to the prefix
\mod@updatedpost{#1}%
\def\mod@blaaaa{}% macro used in the simplify function (remove .. from the prefix)
\mod@simplify{\mod@savedprefix}% remove |xxx/..| from the path (in case it exists)
\mod@reguse{\mod@savedprefix}%
\ifmodules\else%
\mod@updatesms% update the file to contain the .sms extension
\let\newreg\mod@reg% use to compare, in case the .sms file was loaded before
\mod@search{\mod@savedprefix}% update registry
\ifx\newreg\mod@reg\else\input{\mod@savedprefix}\fi% check if the registry was updated and load if necessary
\fi}}
\def\sinput#1{
{\mod@updatedpre{#1}% add the new file to the already existing path
\let\mod@savedprefix\mod@prefix% add the path to the new file to the prefix
\mod@updatedpost{#1}%
\def\mod@blaaaa{}% macro used in the simplify function (remove .. from the prefix)
\mod@simplify{\mod@savedprefix}% remove |xxx/..| from the path (in case it exists)
\mod@reguse{\mod@savedprefix}%
\let\newreg\mod@reg% use to compare, in case the .sms file was loaded before
\mod@search{\mod@savedprefix}% update registry
\ifx\newreg\mod@reg%\message{This file has been previously introduced}
\else\input{\mod@savedprefix}%
\fi}}
\let\sinputref=\sinput
\let\inputref=\input
\def\requirepackage#1#2{\makeatletter\input{#1.sty}\makeatother}
\srefaddidkey{view}
\addmetakey*{view}{title}
\define@key{view}{load}{\requiremodules{#1}}
\newcounter{view}[section]
\newcommand\view@heading[2]{\stepcounter{view}%
{\textbf{View} \thesection.\theview: from #1 to #2}%
\sref@label@id{View \thesection.\theview}%
\ifx\view@title\@empty :\quad\else\quad(\view@title)\hfill\\\fi}
\ifmod@show\newsavebox{\viewbox}
\newenvironment{view}[3][]{\metasetkeys{view}{#1}\sref@target\stepcounter{view}
\begin{lrbox}{\viewbox}\begin{minipage}{.9\textwidth}
\importmodule{#1}\importmodule{#2}\gdef\view@@heading{\view@heading{#2}{#3}}}
{\end{minipage}\end{lrbox}
\setbox0=\hbox{\begin{minipage}{.9\textwidth}%
\noindent\view@@heading\rm%
\end{minipage}}
\smallskip\noindent\fbox{\vbox{\box0\vspace*{.2em}\usebox\viewbox}}\smallskip}
\else\newxcomment[]{view}\fi%ifmod@show
\define@key{module}{uses}{%
\@for\module@tmp:=#1\do{\activate@defs\module@tmp\export@defs\module@tmp}}
\define@key{module}{usesqualified}{%
\@for\module@tmp:=#1\do{\activate@defs{qualified@\module@tmp}\export@defs\module@tmp}}
\def\csymdef{\@ifnextchar[{\@csymdef}{\@csymdef[]}}
\def\@csymdef[#1]#2{\@ifnextchar[{\@@csymdef[#1]{#2}}{\@@csymdef[#1]{#2}[0]}}
\def\@@csymdef[#1]#2[#3]#4#5{\@@symdef[#1]{#2}[#3]{#4}}
\def\notationdef[#1]#2#3{}
\endinput
%%
%% End of file `modules.sty'.
