| 1 |
% \def\filename{ifoption.dtx} |
| 2 |
% \def\fileversion{1.02} |
| 3 |
% \def\filedate{2002/03/04} |
| 4 |
% |
| 5 |
% \iffalse meta-comment |
| 6 |
% |
| 7 |
% American Mathematical Society |
| 8 |
% Technical Support |
| 9 |
% Publications Technical Group |
| 10 |
% 201 Charles Street |
| 11 |
% Providence, RI 02904 |
| 12 |
% USA |
| 13 |
% tel: (401) 455-4080 |
| 14 |
% (800) 321-4267 (USA and Canada only) |
| 15 |
% fax: (401) 331-3842 |
| 16 |
% email: [email protected] |
| 17 |
% |
| 18 |
% Copyright 2001, 2010 American Mathematical Society. |
| 19 |
% |
| 20 |
% This work may be distributed and/or modified under the |
| 21 |
% conditions of the LaTeX Project Public License, either version 1.3c |
| 22 |
% of this license or (at your option) any later version. |
| 23 |
% The latest version of this license is in |
| 24 |
% http://www.latex-project.org/lppl.txt |
| 25 |
% and version 1.3c or later is part of all distributions of LaTeX |
| 26 |
% version 2005/12/01 or later. |
| 27 |
% |
| 28 |
% This work has the LPPL maintenance status `maintained'. |
| 29 |
% |
| 30 |
% The Current Maintainer of this work is the American Mathematical |
| 31 |
% Society. |
| 32 |
% |
| 33 |
% \fi |
| 34 |
% |
| 35 |
% \iffalse |
| 36 |
%<*driver> |
| 37 |
\NeedsTeXFormat{LaTeX2e} |
| 38 |
\documentclass{amsdtx} |
| 39 |
\providecommand{\mdash}{\textemdash} |
| 40 |
\newcommand{\xt}[1]{\texttt{#1}} |
| 41 |
\providecommand{\qq}[1]{``#1''} |
| 42 |
\providecommand{\lat}[1]{\protect\LaTeX{}} |
| 43 |
\begin{document} |
| 44 |
\title{The \pkg{ifoption} package} |
| 45 |
\author{Michael~J. Downes\\American Mathematical Society} |
| 46 |
\date{Version \fileversion, \filedate} |
| 47 |
\DocInput{ifoption.dtx} |
| 48 |
\end{document} |
| 49 |
%</driver> |
| 50 |
% \fi |
| 51 |
% |
| 52 |
% \maketitle |
| 53 |
% \section{Introduction} |
| 54 |
% |
| 55 |
% The \pkg{ifoption} package provides an \cn{IfOption} command that |
| 56 |
% has certain advantages over the \cs{@ifpackagewith} command\mdash |
| 57 |
% e.g., default options specified with \cs{ExecuteOptions} test as |
| 58 |
% true rather than false. In order for this to work properly, |
| 59 |
% mutually exclusive options should be specified with |
| 60 |
% \cs{DeclareExclusiveOptions}, another command defined by the |
| 61 |
% \pkg{ifoption} package. |
| 62 |
% \StopEventually{} |
| 63 |
% |
| 64 |
% \section{Implementation} |
| 65 |
% \subsection{Package info} |
| 66 |
% |
| 67 |
% Standard declaration of package name and date. |
| 68 |
% \begin{macrocode} |
| 69 |
\NeedsTeXFormat{LaTeX2e} |
| 70 |
\ProvidesPackage{ifoption}[2002/03/04 v1.02] |
| 71 |
% \end{macrocode} |
| 72 |
% |
| 73 |
% \subsection{Some utility functions} |
| 74 |
% |
| 75 |
% \begin{macrocode} |
| 76 |
\let\@xp\expandafter \let\@nx\noexpand |
| 77 |
% \end{macrocode} |
| 78 |
% |
| 79 |
% \begin{macrocode} |
| 80 |
\def\@True{00} |
| 81 |
\def\@False{01} |
| 82 |
% \end{macrocode} |
| 83 |
% |
| 84 |
% \subsection{Background} |
| 85 |
% See the definitions of \cs{@onefilewithoptions} and |
| 86 |
% \cs{@pushfilename} in the \lat/ kernel. |
| 87 |
% |
| 88 |
% When we have |
| 89 |
%\begin{verbatim} |
| 90 |
%\DeclareOption{foo}{some code} |
| 91 |
%\end{verbatim} |
| 92 |
% in a file named \fn{bar.sty}, \lat/ defines \cs{ds@foo} to contain |
| 93 |
% \emph{some code}. Then if the package is invoked with |
| 94 |
%\begin{verbatim} |
| 95 |
%\usepackage[foo]{bar} |
| 96 |
%\end{verbatim} |
| 97 |
% there are two consequences: \opt{foo} is added to the options list |
| 98 |
% for package \pkg{bar}, which is the control sequence |
| 99 |
% \cs{[email protected]}; and when \cs{ProcessOptions} is called, it |
| 100 |
% executes \cs{ds@option-name} for each option found in the list. |
| 101 |
% When it is finished running the options, \cs{ProcessOptions} |
| 102 |
% undefines all the \cs{ds@whatever} for the current package, which |
| 103 |
% are listed in the control sequence \cs{@declaredoptions}. At the |
| 104 |
% end of \fn{bar.sty}, \cs{@declaredoptions} is globally reset to |
| 105 |
% empty. Thus subordinate packages with options cannot be loaded in |
| 106 |
% the \qq{first half} of a package that also has options, where first half |
| 107 |
% means the area leading up to the \cs{ProcessOptions} call. |
| 108 |
% |
| 109 |
% For mutually exclusive options \xt{a}, \xt{b}, \xt{c}, when option |
| 110 |
% \xt{b} is invoked it should remove all of its sibling options from |
| 111 |
% the options-actually-used list and add itself to the list. For this |
| 112 |
% task we make use of the fact that \cs{ProcessOptions} ends by |
| 113 |
% undefining all the declared options of the current package or |
| 114 |
% documentclass. |
| 115 |
% |
| 116 |
% \begin{macrocode} |
| 117 |
\def\CurrentPackage{\@currname} |
| 118 |
\let\CurrentClass\CurrentPackage |
| 119 |
% \end{macrocode} |
| 120 |
% |
| 121 |
% \begin{macrocode} |
| 122 |
\newcommand{\IfOption}{} |
| 123 |
\def\IfPackageOption{\@ifpackagewith} |
| 124 |
\def\IfClassOption{\@ifclasswith} |
| 125 |
\def\IfOption{% |
| 126 |
\ifx\@currext\@pkgextension \@xp\IfPackageOption |
| 127 |
\else \@xp\IfClassOption |
| 128 |
\fi |
| 129 |
\@currname |
| 130 |
} |
| 131 |
% \end{macrocode} |
| 132 |
% |
| 133 |
% \begin{macrocode} |
| 134 |
\newcommand{\DeclareExclusiveOptions}[1]{% |
| 135 |
\xdef\@declaredoptions{\@declaredoptions,#1}% |
| 136 |
\gdef\ProcessExclusiveOptions{\relax}% |
| 137 |
\@for\CurrOption:=#1\do{% |
| 138 |
\@xp\deo@a\csname ds@\CurrOption\@xp\endcsname\@xp{\CurrOption}{#1}% |
| 139 |
}% |
| 140 |
} |
| 141 |
\def\DeclareBooleanOption{\DeclareExclusiveOptions} |
| 142 |
% \end{macrocode} |
| 143 |
% |
| 144 |
% \begin{macrocode} |
| 145 |
\def\deo@a#1#2#3{% |
| 146 |
\def#1{% |
| 147 |
\g@addto@macro\ProcessExclusiveOptions{\OptionsFalseTrue{#3}{#2}}% |
| 148 |
}% |
| 149 |
} |
| 150 |
% \end{macrocode} |
| 151 |
% |
| 152 |
% \begin{macrocode} |
| 153 |
\def\cull@options#1,{% |
| 154 |
\@xp\ifx\csname ds@#1\@gobble\@percentchar\@empty\endcsname\@False |
| 155 |
\else #1,\fi |
| 156 |
\cull@options |
| 157 |
} |
| 158 |
|
| 159 |
\newcommand{\OptionsFalseTrue}[2]{% |
| 160 |
\begingroup |
| 161 |
\@for\CurrentOption:=#1\do{% |
| 162 |
\@xp\let\csname ds@\CurrentOption\endcsname\@False |
| 163 |
}% |
| 164 |
\let\ds@\@False |
| 165 |
\@xp\xdef\csname opt@\@currname.\@currext\endcsname{% |
| 166 |
\@xp\@xp\@xp\cull@options\csname opt@\@currname.\@currext\endcsname |
| 167 |
% \end{macrocode} |
| 168 |
% Lacking \cs{@secondofthree} and not keen on defining it \ldots |
| 169 |
% \begin{macrocode} |
| 170 |
,\@firstoftwo\@firstoftwo,#2% |
| 171 |
}% |
| 172 |
\endgroup |
| 173 |
} |
| 174 |
% \end{macrocode} |
| 175 |
% |
| 176 |
% The usual \cs{endinput} to ensure that random garbage at the end of |
| 177 |
% the file doesn't get copied by \fn{docstrip}. |
| 178 |
% \begin{macrocode} |
| 179 |
\endinput |
| 180 |
% \end{macrocode} |
| 181 |
% |
| 182 |
% \CheckSum{112} |
| 183 |
% \Finale |