Debian Codegraph @

texmf-dist/source/latex/tools/somedefs.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 1993-2025
4 %
5 % The LaTeX Project and any individual authors listed elsewhere
6 % in this file.
7 %
8 % This file is part of the Standard LaTeX `Tools Bundle'.
9 % -------------------------------------------------------
10 %
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 % https://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.
18 %
19 % The list of all files belonging to the LaTeX `Tools Bundle' is
20 % given in the file `manifest.txt'.
21 %
22 % \fi
23 % \title{The \textsf{somedefs} toolkit package}
24 % \date{long time ago in a different century\ldots}
25 % \author{Alan Jeffrey}
26 % \MaintainedByLaTeXTeam{tools}
27 % \maketitle
28 %
29 % \changes{v0.03}{2025-06-04}{Add notice pointing out this is historical}
30 % \begin{flushleft}
31 % \bfseries
32 % This package is retained in the \LaTeX{} \pkg{tools} bundle for
33 % stability reasons. Whilst bug fixes will be applied to \pkg{somedefs},
34 % no \emph{new} features will be considered.
35 % \end{flushleft}
36 %
37 % \changes{v0.03}{1994/06/01}{Use new style error commands. DPC}
38 % \changes{v0.02}{1994/05/10}{Added a \cmd\relax, to stop arguments to
39 % \cmd\newcommand\ being unbraced by \cmd\ProvidesCommand. Added
40 % an error message for commands which are requested but never
41 % defined. Spotted by DPC.}
42 %
43 % \section*{Overview}
44 %
45 % This is an example `programmers toolkit' package, for use by package
46 % writers. It allows package writers to provide options which switch
47 % definitions on and off. For example, a package |fred| might define a
48 % large number of commands, including |\foo| and |\baz|, so:
49 % \begin{verbatim}
50 % \usepackage{fred}
51 % \end{verbatim}
52 % would use a lot of memory, even if |\foo| and |\baz| were the only
53 % commands needed. However, if the author of |fred| used the |somedefs|
54 % package, then the user would be able to say:
55 % \begin{verbatim}
56 % \usepackage[only,foo,baz]{fred}
57 % \end{verbatim}
58 % and only the commands |\foo| and |\baz| would be defined.
59 %
60 % To use the |somedefs| package in your own packages or classes, you
61 % say:
62 % \begin{verbatim}
63 % \RequirePackage{somedefs}
64 % \end{verbatim}
65 % You can then use four new commands:
66 % \begin{flushleft}\begin{itemize}
67 % \item |\UseAllDefinitions| which says that all the commands in the
68 % file should be defined.
69 % \item |\UseSomeDefinitions| which says that only the commands
70 % specified by |\UseDefinition| should be defined.
71 % \item |\UseDefinition{|\meta{name}|}| which says that the command
72 % |\name| should be defined.
73 % \item |\ProvidesDefinition{|\meta{definition}|}| which provides one
74 % definition, of the form |\definingcommand{\command}...|
75 % \end{itemize}\end{flushleft}
76 % For example, the package |fred| could say:
77 % \begin{verbatim}
78 % \RequirePackage{somedefs}
79 % \UseAllDefinitions
80 % \DeclareOption{only}{\UseSomeDefinitions}
81 % \DeclareOption*{\UseDefinition{\CurrentOption}}
82 % \ProcessOptions
83 % \ProvidesDefinition{\newcommand{\foo}{...}}
84 % \ProvidesDefinition{\newcommand{\baz}{...}}
85 % \end{verbatim}
86 % One of the commands |\UseAllDefinitions| or |\UseSomeDefinitions|
87 % should always be used. You may have some commands which need other
88 % commands, in which case you have to declare the options by hand. For
89 % example, if the command |\bar| needs the command |\foo|, you could
90 % say:
91 % \begin{verbatim}
92 % \DeclareOption{bar}{\UseDefinition{bar}\UseDefinition{foo}}
93 % \end{verbatim}
94 % For a longer example of the use of the |somedefs| package, look at the
95 % |rawfonts| package.
96 %
97 % \MaybeStop{}
98 %
99 % \section*{Implementation}
100 %
101 % The driver for the documentation you're now reading.
102 % \begin{macrocode}
103 %<*driver>
104 \documentclass{ltxdoc}
105 \begin{document}
106 \DocInput{somedefs.dtx}
107 \end{document}
108 %</driver>
109 % \end{macrocode}
110 % This is a \LaTeXe{} package.
111 % \begin{macrocode}
112 %<*package>
113 \NeedsTeXFormat{LaTeX2e}
114 \ProvidesPackage{somedefs}[1994/06/01 v0.03 Toolkit for optional definitions]
115 % \end{macrocode}
116 % \begin{macro}{\UseSomeDefinitions}
117 % \begin{macro}{\UseAllDefinitions}
118 % \begin{macro}{\UseDefinition}
119 % \begin{macro}{\ProvidesDefinition}
120 % \begin{macro}{\@providesdefinition}
121 % \begin{macro}{\@provides@definition}
122 % \begin{macro}{\@unprovided@definition}
123 % The package works by having |\UseDefinition{|\meta{name}|}| define
124 % |\name| to be |\@unprovided@definition|.
125 % If |\UseSomeDefinitions| has been called,
126 % then |\ProvidesDefinition| looks to see if |\name|
127 % is |\@unprovided@definition|. If
128 % |\UseAllDefinitions| has been called, then |\ProvidesDefinition|
129 % does nothing. If neither has been called, then
130 % |\ProvidesDefinition| produces an error message.
131 % \begin{macrocode}
132 \def\UseSomeDefinitions{%
133 \let\ProvidesDefinition\@providesdefinition
134 }
135 \def\UseAllDefinitions{%
136 \let\ProvidesDefinition\@firstofone
137 }
138 \def\UseDefinition#1{%
139 \expandafter\let\csname#1\endcsname\@unprovided@definition
140 }
141 \def\ProvidesDefinition#1{%
142 \PackageError{somedefs}%
143 {No \noexpand\UseSomeDefinitions or \string\UseAllDefinitions}%
144 {The package which used the `somedefs' package has an error.}%
145 }
146 \def\@providesdefinition#1{\@provides@definition#1\relax
147 \@provides@definition}
148 \def\@provides@definition#1#2#3\@provides@definition{%
149 \ifx#2\@unprovided@definition
150 #1#2#3%
151 \fi
152 }
153 \def\@unprovided@definition{%
154 \PackageError{somedefs}%
155 {Package `somedefs' error: this command was never defined}%
156 {You have requested a command which does not exist.}%
157 }
158 \@onlypreamble\UseSomeDefinitions
159 \@onlypreamble\UseAllDefinitions
160 \@onlypreamble\UseDefinition
161 \@onlypreamble\ProvidesDefinition
162 \@onlypreamble\@providesdefinition
163 \@onlypreamble\@provides@definition
164 % \end{macrocode}
165 % \end{macro}
166 % \end{macro}
167 % \end{macro}
168 % \end{macro}
169 % \end{macro}
170 % \end{macro}
171 % \end{macro}
172 % That's it!
173 % \begin{macrocode}
174 %</package>
175 % \end{macrocode}
176 %
177 % \Finale
178 %
179 % \endinput