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}
30 % \changes{v0.03}{1994/06/01}{Use new style error commands. DPC}
31 % \changes{v0.02}{1994/05/10}{Added a \cmd\relax, to stop arguments to
32 % \cmd\newcommand\ being unbraced by \cmd\ProvidesCommand. Added
33 % an error message for commands which are requested but never
34 % defined. Spotted by DPC.}
38 % This is an example `programmers toolkit' package, for use by package
39 % writers. It allows package writers to provide options which switch
40 % definitions on and off. For example, a package |fred| might define a
41 % large number of commands, including |\foo| and |\baz|, so:
45 % would use a lot of memory, even if |\foo| and |\baz| were the only
46 % commands needed. However, if the author of |fred| used the |somedefs|
47 % package, then the user would be able to say:
49 % \usepackage[only,foo,baz]{fred}
51 % and only the commands |\foo| and |\baz| would be defined.
53 % To use the |somedefs| package in your own packages or classes, you
56 % \RequirePackage{somedefs}
58 % You can then use four new commands:
59 % \begin{flushleft}\begin{itemize}
60 % \item |\UseAllDefinitions| which says that all the commands in the
61 % file should be defined.
62 % \item |\UseSomeDefinitions| which says that only the commands
63 % specified by |\UseDefinition| should be defined.
64 % \item |\UseDefinition{|\meta{name}|}| which says that the command
65 % |\name| should be defined.
66 % \item |\ProvidesDefinition{|\meta{definition}|}| which provides one
67 % definition, of the form |\definingcommand{\command}...|
68 % \end{itemize}\end{flushleft}
69 % For example, the package |fred| could say:
71 % \RequirePackage{somedefs}
73 % \DeclareOption{only}{\UseSomeDefinitions}
74 % \DeclareOption*{\UseDefinition{\CurrentOption}}
76 % \ProvidesDefinition{\newcommand{\foo}{...}}
77 % \ProvidesDefinition{\newcommand{\baz}{...}}
79 % One of the commands |\UseAllDefinitions| or |\UseSomeDefinitions|
80 % should always be used. You may have some commands which need other
81 % commands, in which case you have to declare the options by hand. For
82 % example, if the command |\bar| needs the command |\foo|, you could
85 % \DeclareOption{bar}{\UseDefinition{bar}\UseDefinition{foo}}
87 % For a longer example of the use of the |somedefs| package, look at the
92 % \section*{Implementation}
94 % The driver for the documentation you're now reading.
97 \documentclass{ltxdoc}
99 \DocInput{somedefs.dtx}
103 % This is a \LaTeXe{} package.
106 \NeedsTeXFormat{LaTeX2e}
107 \ProvidesPackage{somedefs}[1994/06/01 v0.03 Toolkit for optional definitions]
109 % \begin{macro}{\UseSomeDefinitions}
110 % \begin{macro}{\UseAllDefinitions}
111 % \begin{macro}{\UseDefinition}
112 % \begin{macro}{\ProvidesDefinition}
113 % \begin{macro}{\@providesdefinition}
114 % \begin{macro}{\@provides@definition}
115 % \begin{macro}{\@unprovided@definition}
116 % The package works by having |\UseDefinition{|\meta{name}|}| define
117 % |\name| to be |\@unprovided@definition|.
118 % If |\UseSomeDefinitions| has been called,
119 % then |\ProvidesDefinition| looks to see if |\name|
120 % is |\@unprovided@definition|. If
121 % |\UseAllDefinitions| has been called, then |\ProvidesDefinition|
122 % does nothing. If neither has been called, then
123 % |\ProvidesDefinition| produces an error message.
125 \def\UseSomeDefinitions{%
126 \let\ProvidesDefinition\@providesdefinition
128 \def\UseAllDefinitions{%
129 \let\ProvidesDefinition\@firstofone
131 \def\UseDefinition#1{%
132 \expandafter\let\csname#1\endcsname\@unprovided@definition
134 \def\ProvidesDefinition#1{%
135 \PackageError{somedefs}%
136 {No \noexpand\UseSomeDefinitions or \string\UseAllDefinitions}%
137 {The package which used the `somedefs' package has an error.}%
139 \def\@providesdefinition#1{\@provides@definition#1\relax
140 \@provides@definition}
141 \def\@provides@definition#1#2#3\@provides@definition{%
142 \ifx#2\@unprovided@definition
146 \def\@unprovided@definition{%
147 \PackageError{somedefs}%
148 {Package `somedefs' error: this command was never defined}%
149 {You have requested a command which does not exist.}%
151 \@onlypreamble\UseSomeDefinitions
152 \@onlypreamble\UseAllDefinitions
153 \@onlypreamble\UseDefinition
154 \@onlypreamble\ProvidesDefinition
155 \@onlypreamble\@providesdefinition
156 \@onlypreamble\@provides@definition