1 % \iffalse meta-comment
3 % Copyright 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005
5 % The LaTeX3 Project and any individual authors listed elsewhere
8 % This file is part of the Standard LaTeX `Tools Bundle'.
9 % -------------------------------------------------------
11 % It may be distributed and/or modified under the
12 % conditions of the LaTeX Project Public License, either version 1.3c
13 % of this license or (at your option) any later version.
14 % The latest version of this license is in
15 % http://www.latex-project.org/lppl.txt
16 % and version 1.3c or later is part of all distributions of LaTeX
17 % version 2005/12/01 or later.
19 % The list of all files belonging to the LaTeX `Tools Bundle' is
20 % given in the file `manifest.txt'.
23 % \title{The \textsf{somedefs} toolkit package}
24 % \date{long time ago in a different century\ldots}
25 % \author{Alan Jeffrey}
26 % \MaintainedByLaTeXTeam{tools}
31 % \changes{v0.03}{1994/06/01}{Use new style error commands. DPC}
32 % \changes{v0.02}{1994/05/10}{Added a \cmd\relax, to stop arguments to
33 % \cmd\newcommand\ being unbraced by \cmd\ProvidesCommand. Added
34 % an error message for commands which are requested but never
35 % defined. Spotted by DPC.}
39 % This is an example `programmers toolkit' package, for use by package
40 % writers. It allows package writers to provide options which switch
41 % definitions on and off. For example, a package |fred| might define a
42 % large number of commands, including |\foo| and |\baz|, so:
46 % would use a lot of memory, even if |\foo| and |\baz| were the only
47 % commands needed. However, if the author of |fred| used the |somedefs|
48 % package, then the user would be able to say:
50 % \usepackage[only,foo,baz]{fred}
52 % and only the commands |\foo| and |\baz| would be defined.
54 % To use the |somedefs| package in your own packages or classes, you
57 % \RequirePackage{somedefs}
59 % You can then use four new commands:
60 % \begin{flushleft}\begin{itemize}
61 % \item |\UseAllDefinitions| which says that all the commands in the
62 % file should be defined.
63 % \item |\UseSomeDefinitions| which says that only the commands
64 % specified by |\UseDefinition| should be defined.
65 % \item |\UseDefinition{|\meta{name}|}| which says that the command
66 % |\name| should be defined.
67 % \item |\ProvidesDefinition{|\meta{definition}|}| which provides one
68 % definition, of the form |\definingcommand{\command}...|
69 % \end{itemize}\end{flushleft}
70 % For example, the package |fred| could say:
72 % \RequirePackage{somedefs}
74 % \DeclareOption{only}{\UseSomeDefinitions}
75 % \DeclareOption*{\UseDefinition{\CurrentOption}}
77 % \ProvidesDefinition{\newcommand{\foo}{...}}
78 % \ProvidesDefinition{\newcommand{\baz}{...}}
80 % One of the commands |\UseAllDefinitions| or |\UseSomeDefinitions|
81 % should always be used. You may have some commands which need other
82 % commands, in which case you have to declare the options by hand. For
83 % example, if the command |\bar| needs the command |\foo|, you could
86 % \DeclareOption{bar}{\UseDefinition{bar}\UseDefinition{foo}}
88 % For a longer example of the use of the |somedefs| package, look at the
93 % \section*{Implementation}
95 % The driver for the documentation you're now reading.
98 \documentclass{ltxdoc}
100 \DocInput{somedefs.dtx}
104 % This is a \LaTeXe{} package.
107 \NeedsTeXFormat{LaTeX2e}
108 \ProvidesPackage{somedefs}[1994/06/01 v0.03 Toolkit for optional definitions]
110 % \begin{macro}{\UseSomeDefinitions}
111 % \begin{macro}{\UseAllDefinitions}
112 % \begin{macro}{\UseDefinition}
113 % \begin{macro}{\ProvidesDefinition}
114 % \begin{macro}{\@providesdefinition}
115 % \begin{macro}{\@provides@definition}
116 % \begin{macro}{\@unprovided@definition}
117 % The package works by having |\UseDefinition{|\meta{name}|}| define
118 % |\name| to be |\@unprovided@definition|.
119 % If |\UseSomeDefinitions| has been called,
120 % then |\ProvidesDefinition| looks to see if |\name|
121 % is |\@unprovided@definition|. If
122 % |\UseAllDefinitions| has been called, then |\ProvidesDefinition|
123 % does nothing. If neither has been called, then
124 % |\ProvidesDefinition| produces an error message.
126 \def\UseSomeDefinitions{%
127 \let\ProvidesDefinition\@providesdefinition
129 \def\UseAllDefinitions{%
130 \let\ProvidesDefinition\@firstofone
132 \def\UseDefinition#1{%
133 \expandafter\let\csname#1\endcsname\@unprovided@definition
135 \def\ProvidesDefinition#1{%
136 \PackageError{somedefs}%
137 {No \noexpand\UseSomeDefinitions or \string\UseAllDefinitions}%
138 {The package which used the `somedefs' package has an error.}%
140 \def\@providesdefinition#1{\@provides@definition#1\relax
141 \@provides@definition}
142 \def\@provides@definition#1#2#3\@provides@definition{%
143 \ifx#2\@unprovided@definition
147 \def\@unprovided@definition{%
148 \PackageError{somedefs}%
149 {Package `somedefs' error: this command was never defined}%
150 {You have requested a command which does not exist.}%
152 \@onlypreamble\UseSomeDefinitions
153 \@onlypreamble\UseAllDefinitions
154 \@onlypreamble\UseDefinition
155 \@onlypreamble\ProvidesDefinition
156 \@onlypreamble\@providesdefinition
157 \@onlypreamble\@provides@definition