%\iffalse -*- doctex -*- \fi
%
%% \RCS$Id: pmn-vrs.sty,v 1.5 2004/10/15 22:45:51 turtle Exp $
%% \RCS$Revision: 1.5 $
%% \RCS$Date: 2004/10/15 22:45:51 $
%
%\iffalse metacomment
% -*- latex-mode -*-
%%  (C) 2004 Peter Møller Neergaard
%%  
%%   This program may be distributed and/or modified under the
%%   conditions of the LaTeX Project Public License, either version 1.2
%%   of this license or (at your option) any later version.
%%   The latest version of this license is in
%%     http://www.latex-project.org/lppl.txt
%%   and version 1.2 or later is part of all distributions of LaTeX 
%%   version 1999/12/01 or later.
%
% This program consists of the file pmn-vrs.sty.
% 
% To print the documentation (which for the moment is uninteresting)
% remove (or comment out) the line
%
%   \endinput
%
% occurring immediately after
%
%   %<*documentation>
% 
%\fi
%
% \CheckSum{13}
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \MakeShortVerb{\"}
%
% \title{The \package{pmn-vrs} package\thanks
%   {This file has CVS revision \RCSRevision, dated \RCSDate.}}
% \author{Peter Møller Neergaard}
% \maketitle
%
% \begin{abstract}
%   This an enhancement of the \package{optional} to allow arbitrary
%   pieces of sources to be skipped using \TeX-like
%   \cs{if\meta{version}}$...$\cs{fi} conditionals.  In particular,
%   this allow using different "\documentclass" for a document.
% \end{abstract}
%
% This package extends the \package{optional} package (loaded
% automatically).  The \package{optional} package allows you to
% produce different versions of the document based on the options set
% for the document.  You set the options to be used using
% "\def\UseOption{"$\ldots$"}". You can conditionally include part of
% the document with two \TeX-like conditionals
% \begin{quote}
% "\ifoptional{"\meta{option-list}"}"\meta{optional stuff}"\else"\meta{alternative stuff}"\fi"
% "\ifnotoptional{"\meta{option-list}"}"\meta{optional stuff}"\else"\meta{alternative stuff}"\fi"
% \end{quote}
% 
%  There is also a case construction on the form
% \begin{quote}
% "\caseoptional{{"\meta{option-list}"}{"\meta{optional stuff}"}"$\ldots$"{"\meta{option-list}"}{"\meta{optional stuff}"}}
% \end{quote}
% You can leave out the last \meta{option-list} to have default case.
%  
% You are encouraged to consult the documentation of
% \package{optional} for more available commands.
%
% This package can be loaded either using "\usepackage{pmn-vrs}" or
% with a "\input{pmn-vrs.sty}" occurring before the "\documentclass"
% command.  The latter option allows you to use different classes for
% a document.
%
% \section{Package identification}
% 
% We identify ourselves and load \package{optional}.
%    \begin{macrocode}
\makeatletter
\def\pvrs@filename{pmn-vrs}
\def\pvrs@ID{2004/10/15 v0.13 PMN Extended version control}
%    \end{macrocode}
%  We test whether we are loaded using the standard \cs{usepackage}
%  mechanism or through \cs{input} by testing whether \cs{@currname}
%  is set.
%    \begin{macrocode}
\ifx\pvrs@filename\@currname
  \NeedsTeXFormat{LaTeX2e}
  \edef\reserved@b{\noexpand\ProvidesPackage{pmn-vrs}[\pvrs@ID]}
  \reserved@b
  \def\UseOption{\@gobble}%
  \DeclareOption*{\edef\UseOption{\UseOption,\CurrentOption}}%
  \ProcessOptions*
  \edef\UseOption{\UseOption\@empty}                
  \RequirePackage{optional}
\else
  \typeout{\pvrs@ID}
  \def\@currname{optional}
  \def\@currext{sty}
  \input{optional.sty}
  \Opl@Setup
  \let\Opl@Setup\relax  
\fi
%    \end{macrocode}
% \changes{v0.13}{2003/10/15}{Fixed bug in building of \csname{UseOption}---it now handles an empty option list correctly.}
% \changes{v0.11}{2003/03/24}{Added call to \csname{Opl@Setup} so it works with older versions.}
% \changes{v0.12}{2003/07/01}{Passing options to \package{optional}.}
%
% We then define the \cs{ifoptional} command.
% \begin{macro}{\ifoptional}
% \begin{macro}{\ifnotoptional}
% \begin{macro}{\ifoptional@int}
%   \mcmd{\ifoptional@int}\cs{if\meta{in list}}\cs{if\meta{not in
%   list}}\marg{option list} tests whether any of the options in
%   \meta{option list} is chosen for the document.  If so it
%   corresponds uses the \cs{if} command in \cs{if\meta{in list}};
%   otherwise \cs{if\meta{not in list}}.
%    \begin{macrocode}
\newcommand{\ifoptional@int}[3]{%
  \if\Opl@notlisted{#3}%
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
  #2#1}
\newcommand{\ifoptional}{\ifoptional@int\iftrue\iffalse}
\newcommand{\ifnotoptional}{\ifoptional@int\iffalse\iftrue}
%    \end{macrocode}
%   The \cs{expandafter} ensures that the first \cs{if} has been
%   processed before expanding \cs{iffalse} or \cs{iftrue}.
%   \changes{2004/06/08}{Added}
% \end{macro} ^^A \ifoptional
%   \changes{2004/06/08}{Added}
% \end{macro} ^^A \ifoptional
%   \changes{2004/06/08}{Added}
% \end{macro} ^^A \ifoptional
%
% And we define a case construction \cs{caseoptional}.
% \begin{macro}{\caseoptional}
%   \mcmd{\caseoptional}\marg{clause list} search through the list of
%   clauses in \meta{clause list} until it finds the first clause with
%   a matching \meta{option list}.  Each clause has the form
%   "{"\meta{option list}"}{\meta{optional stuff}"}".
%    \begin{macrocode}
\newcommand{\caseoptional}[1]{\caseoptional@i#1\endcaseoptional}
\long\def\caseoptional@i#1#2#3\endcaseoptional{%
  \pvr@ifempty{#2}{\pvr@ifempty{#3}{\@secondoftwo}{\@firstoftwo}}%
    {\@firstoftwo}%
  {\ifoptional{#1}#2\else\pvr@ifempty{#3}{}{\caseoptional@i#3\endcaseoptional}\fi}%
  {#1}}
%    \end{macrocode}
%   The command goes through the clauses one by one.  In each case it
%   we test whether we are at the end (if so argument~2 and~3 will be
%   empty) and use \cs{\ifoptional} to test whether to use the clause.
%   \changes{2004/06/08}{Added}
% \end{macro} ^^A \ifoptional
%
% \begin{macro}{\pvr@ifempty}
%   \mcmd{\pvr@ifempty}\marg{stuff}\marg{consequent}\marg{alternative}
%   tests whether \meta{stuff} is the empty expansion.  If so,
%   \meta{consequent} is expanded, otherwise \meta{alternative} is chosen.
%    \begin{macrocode}
\newcommand{\pvr@ifempty}[1]{%
  \def\pvr@tmp{#1}%
  \ifx\pvr@tmp\empty%
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi}  
%    \end{macrocode}
%   \changes{2004/06/08}{Added}
% \end{macro} ^^A \pvr@ifempty
%
% \StopEventually{}
% 
% And the commands to typeset the documentation.  All enclosed in
% "<*documentation>"$\ldots$"</documentation>" so we exclude it if we
% ever make a docstrip file.  For now, we simply stop input with
% \cmd{\endinput} so the file can be used directly as a package file.
%    \begin{macrocode}
%<*documentation>
\endinput
\makeatother
\def\UseOption{}
\documentclass{pmn-ldoc} 
\newcommand{\docdate}{2003/11/02}
\usepackage[latin1]{inputenc}
 % \OnlyDescription
 % \DisableCrossrefs
\begin{document}
  \DocInput{pmn-vrs.sty}
\end{document}
%</documentation>
%    \end{macrocode}
% \Finale \sloppy \PrintChanges
