Debian Codegraph @

texmf-dist/source/latex/amsmath/amsgen.dtx

raw
1 %
2 % \iffalse meta-comment
3 %
4 % Copyright (C) 1995, 1999 American Mathematical Society.
5 % Copyright (C) 2016-2025 LaTeX Project and American Mathematical Society.
6 %
7 % This work may be distributed and/or modified under the
8 % conditions of the LaTeX Project Public License, either version 1.3c
9 % of this license or (at your option) any later version.
10 % The latest version of this license is in
11 % https://www.latex-project.org/lppl.txt
12 % and version 1.3c or later is part of all distributions of LaTeX
13 % version 2005/12/01 or later.
14 %
15 % This work has the LPPL maintenance status `maintained'.
16 %
17 % The Current Maintainer of this work is the LaTeX Project.
18 %
19 % \fi
20 %
21 % \iffalse
22 %<*driver>
23 \documentclass{amsdtx}
24 \def\MaintainedByLaTeXTeam#1{%
25 \begin{center}%
26 \fbox{\fbox{\begin{tabular}{@{}l@{}}%
27 This file is maintained by the \LaTeX{} Project team.\\%
28 Bug reports can be opened (category \texttt{#1}) at\\%
29 \url{https://latex-project.org/bugs/}.\end{tabular}}}\end{center}}
30 \usepackage{amsgen}
31 \GetFileInfo{amsgen.sty}
32 \begin{document}
33 \title{The \pkg{amsgen} package}
34 \author{American Mathematical Society\\Michael Downes}
35 \date{Version \fileversion, \filedate}
36 \DocInput{amsgen.dtx}
37 \end{document}
38 %</driver>
39 % \fi
40 %
41 % \maketitle
42 % \MaintainedByLaTeXTeam{amslatex}
43 %
44 % \MakeShortVerb\|
45 %
46 % \section{Introduction}
47 % This is an internal package for storing common functions
48 % that are shared by more than one package in the \amslatex/
49 % distribution. Some of these might eventually make it into the \latex/
50 % kernel.
51 %
52 % \MaybeStop{}
53 %
54 % Standard package info.
55 % Using \cs{ProvidesFile} rather than \cs{ProvidesPackage} because
56 % the latter, when input by, e.g, \cls{amsbook}, results in
57 % \texttt{LaTeX warning: You have requested document class `amsbook',
58 % but the document class provides `amsgen'.}
59 % \begin{macrocode}
60 \NeedsTeXFormat{LaTeX2e}% LaTeX 2.09 can't be used (nor non-LaTeX)
61 [1994/12/01]% LaTeX date must December 1994 or later
62 \ProvidesFile{amsgen.sty}[1999/11/30 v2.0 generic functions]
63 % \end{macrocode}
64 %
65 % \section{Implementation}
66 % Some general macros shared by \fn{amsart.dtx}, \fn{amsmath.dtx},
67 % \fn{amsfonts.dtx}, \dots
68 %
69 % \begin{macro}{\@saveprimitive}
70 % The \pkg{amsmath} package redefines a number of \tex/ primitives.
71 % In case some preceding package also decided to redefine one of
72 % those same primitives, we had better do some checking to make
73 % sure that we are able to save the primitive meaning for internal
74 % use. This is handled by the \cs{@saveprimitive} function. We
75 % follow the example of \cs{@@input} where the primitive meaning is
76 % stored in an internal control sequence with a |@@| prefix.
77 % Primitive control sequences can be distinguished by the fact that
78 % \cs{string} and \cs{meaning} return the same information.
79 % \begin{macrocode}
80 \providecommand{\@saveprimitive}[2]{\begingroup\escapechar`\\\relax
81 \edef\@tempa{\string#1}\edef\@tempb{\meaning#1}%
82 \ifx\@tempa\@tempb \global\let#2#1%
83 \else
84 % \end{macrocode}
85 % Check to see if \arg{2} was already given the desired primitive
86 % meaning somewhere else.
87 % \begin{macrocode}
88 \edef\@tempb{\meaning#2}%
89 \ifx\@tempa\@tempb
90 \else
91 \@latex@error{Unable to properly define \string#2; primitive
92 \noexpand#1no longer primitive}\@eha
93 \fi
94 \fi
95 \endgroup}
96 % \end{macrocode}
97 % \end{macro}
98 %
99 % \begin{macro}{\@xp}
100 % \begin{macro}{\@nx}
101 % Shorthands for long command names.
102 % \begin{macrocode}
103 \let\@xp=\expandafter
104 \let\@nx=\noexpand
105 % \end{macrocode}
106 % \end{macro}
107 % \end{macro}
108 %
109 % \begin{macro}{\@emptytoks}
110 % A token register companion for \cs{@empty}. Saves a little main mem and
111 % probably makes initializations such as |\toks@{}| run faster too.
112 % \begin{macrocode}
113 \newtoks\@emptytoks
114 % \end{macrocode}
115 % \end{macro}
116 %
117 % \begin{macro}{\@oparg}
118 % Use of \cs{@oparg} simplifies some constructions where a macro
119 % takes an optional argument in square brackets. We can't use
120 % \cn{newcommand} here because this function might be previously
121 % defined by the \pkg{amsmath} package in a loading sequence such as
122 % \begin{verbatim}
123 % \usepackage{amsmath,amsthm}
124 % \end{verbatim}
125 % \begin{macrocode}
126 \def\@oparg#1[#2]{\@ifnextchar[{#1}{#1[#2]}}
127 % \end{macrocode}
128 % \end{macro}
129 %
130 % \begin{macro}{\@ifempty}
131 % \begin{macro}{\@ifnotempty}
132 % |\@ifnotempty| and |\@ifempty| use category 11 |@| characters to
133 % test whether the argument is empty or not, since these are highly
134 % unlikely to occur in the argument. As with \cn{@oparg}, there is a
135 % possibility that these commands were defined previously in
136 % \fn{amsmath.sty}.
137 % \begin{macrocode}
138 \long\def\@ifempty#1{\@xifempty#1@@..\@nil}
139 \long\def\@xifempty#1#2@#3#4#5\@nil{%
140 \ifx#3#4\@xp\@firstoftwo\else\@xp\@secondoftwo\fi}
141 % \end{macrocode}
142 % \cs{@ifnotempty} is a shorthand that makes code read better when
143 % no action is needed in the empty case. At a cost of double
144 % argument-reading---so for often-executed code, avoiding
145 % \cs{@ifnotempty} might be wise.
146 % \begin{macrocode}
147 \long\def\@ifnotempty#1{\@ifempty{#1}{}}
148 % \end{macrocode}
149 % \end{macro}
150 % \end{macro}
151 %
152 % Some abbreviations to conserve token mem.
153 % \begin{macrocode}
154 \def\FN@{\futurelet\@let@token}
155 \def\DN@{\def\next@}
156 \def\RIfM@{\relax\ifmmode}
157 \def\setboxz@h{\setbox\z@\hbox}
158 \def\wdz@{\wd\z@}
159 \def\boxz@{\box\z@}
160 \def\relaxnext@{\let\@let@token\relax}
161 % \end{macrocode}
162 %
163 % \begin{macro}{\new@ifnextchar}
164 % This macro is a new version of \latex/'s \verb+\@ifnextchar+,
165 % macro that does not skip over spaces.
166 % \begin{macrocode}
167 \long\def\new@ifnextchar#1#2#3{%
168 % \end{macrocode}
169 % By including the space after the equals sign, we make it possible
170 % for \cs{new@ifnextchar} to do look-ahead for any token, including a
171 % space!
172 % \begin{macrocode}
173 \let\reserved@d= #1%
174 \def\reserved@a{#2}\def\reserved@b{#3}%
175 \futurelet\@let@token\new@ifnch
176 }
177 %
178 \def\new@ifnch{%
179 \ifx\@let@token\reserved@d \let\reserved@b\reserved@a \fi
180 \reserved@b
181 }
182 % \end{macrocode}
183 % \end{macro}
184 %
185 % \begin{macro}{\@ifstar}
186 % There will essentially never be a space before the \qc{\*}, so
187 % using \cs{@ifnextchar} is unnecessarily slow.
188 % \begin{macrocode}
189 \def\@ifstar#1#2{\new@ifnextchar *{\def\reserved@a*{#1}\reserved@a}{#2}}
190 % \end{macrocode}
191 % \end{macro}
192 %
193 % The hook \cs{every@size} was changed to \cs{every@math@size} in the
194 % December 1994 release of \latex/ and its calling procedures changed.
195 % If \cs{every@math@size} is undefined it means the user has an older
196 % version of \latex/ so we had better define it and patch a couple of
197 % functions (\cs{glb@settings} and \cs{set@fontsize}).
198 % \begin{macrocode}
199 \@ifundefined{every@math@size}{%
200 % \end{macrocode}
201 % Reuse the same token register; since it was never used except for
202 % the purposes that are affected below, this is OK.
203 % \begin{macrocode}
204 \let\every@math@size=\every@size
205 \def\glb@settings{%
206 \expandafter\ifx\csname S@\f@size\endcsname\relax
207 \calculate@math@sizes
208 \fi
209 \csname S@\f@size\endcsname
210 \ifmath@fonts
211 % \ifnum \tracingfonts>\tw@
212 % \@font@info{Setting up math fonts for
213 % \f@size/\f@baselineskip}\fi
214 \begingroup
215 \escapechar\m@ne
216 \csname mv@\math@version \endcsname
217 \globaldefs\@ne
218 \let \glb@currsize \f@size
219 \math@fonts
220 \endgroup
221 \the\every@math@size
222 \else
223 % \ifnum \tracingfonts>\tw@
224 % \@font@info{No math setup for \f@size/\f@baselineskip}%
225 % \fi
226 \fi
227 }
228 % \end{macrocode}
229 % Remove |\the\every@size| from \cs{size@update}.
230 % \begin{macrocode}
231 \def\set@fontsize#1#2#3{%
232 \@defaultunits\@tempdimb#2pt\relax\@nnil
233 \edef\f@size{\strip@pt\@tempdimb}%
234 \@defaultunits\@tempskipa#3pt\relax\@nnil
235 \edef\f@baselineskip{\the\@tempskipa}%
236 \edef\f@linespread{#1}%
237 \let\baselinestretch\f@linespread
238 \def\size@update{%
239 \baselineskip\f@baselineskip\relax
240 \baselineskip\f@linespread\baselineskip
241 \normalbaselineskip\baselineskip
242 \setbox\strutbox\hbox{%
243 \vrule\@height.7\baselineskip
244 \@depth.3\baselineskip
245 \@width\z@}%
246 %%% \the\every@size
247 \let\size@update\relax}%
248 }
249 }{}% end \@ifundefined test
250 % \end{macrocode}
251 %
252 % \begin{macro}{\ex@}
253 % The \cs{ex@} variable provides a small unit of space for use in
254 % math-mode constructions, that varies according to the current type
255 % size. For example, the \cn{pmb} command uses \cs{ex@} units.
256 % Since a macro or mu unit solution for the \meta{dimen} \cs{ex@} won't
257 % work without changing a lot of current code in the \pkg{amsmath}
258 % package, we set \cs{ex@} through the \cs{every@math@size} hook.
259 % The value of \cs{ex@} is scaled nonlinearly in a range of roughly
260 % 0.5pt to 1.5pt, by the function \cs{compute@ex@}.
261 % \begin{macrocode}
262 \newdimen\ex@
263 \addto@hook\every@math@size{\compute@ex@}
264 % \end{macrocode}
265 % \end{macro}
266 %
267 % \cs{compute@ex@} computes \cs{ex@} as a nonlinear scaling from 10pt
268 % to current font size (\cs{f@size}). Using .97 as the multiplier makes 1
269 % |ex@| $\approx$ .9pt when the current type size is 8pt and 1 |ex@|
270 % $\approx$ 1.1pt when the current type size is 12pt.
271 %
272 % The formula is essentially
273 % \begin{displaymath}
274 % \newcommand{\points}{\mbox{pt}}
275 % \newcommand{\floor}[1]{\lfloor#1\rfloor}
276 % 1\points \pm (1\points - (.97)^{\floor{\vert 10 - n\vert}})
277 % \end{displaymath}
278 % where $n$ = current type size, but adjusted to differentiate
279 % half-point sizes as well as whole point sizes, and there is a
280 % cutoff for extraordinarily large values of \cs{f@size} ($>$ 20pt)
281 % so that the value of \cs{ex@} never exceeds 1.5pt.
282 %
283 % \begin{macrocode}
284 \def\compute@ex@{%
285 \begingroup
286 \dimen@-\f@size\p@
287 \ifdim\dimen@<-20\p@
288 % \end{macrocode}
289 % Never make \cs{ex@} larger than 1.5pt.
290 % \begin{macrocode}
291 \global\ex@ 1.5\p@
292 \else
293 % \end{macrocode}
294 % Adjust by the reference size and multiply by 2 to allow for
295 % half-point sizes.
296 % \begin{macrocode}
297 \advance\dimen@10\p@ \multiply\dimen@\tw@
298 % \end{macrocode}
299 % Save information about the current sign of \cs{dimen@}.
300 % \begin{macrocode}
301 \edef\@tempa{\ifdim\dimen@>\z@ -\fi}%
302 % \end{macrocode}
303 % Get the absolute value of \cs{dimen@}.
304 % \begin{macrocode}
305 \dimen@ \ifdim\dimen@<\z@ -\fi \dimen@
306 \advance\dimen@-\@m sp % fudge factor
307 % \end{macrocode}
308 % Here we use \cs{vfuzz} merely as a convenient scratch register
309 % \begin{macrocode}
310 \vfuzz\p@
311 % \end{macrocode}
312 % Multiply in a loop.
313 % \begin{macrocode}
314 \def\do{\ifdim\dimen@>\z@
315 \vfuzz=.97\vfuzz
316 \advance\dimen@ -\p@
317 %\message{\vfuzz: \the\vfuzz, \dimen@: \the\dimen@}%
318 \@xp\do \fi}%
319 \do
320 \dimen@\p@ \advance\dimen@-\vfuzz
321 \global\ex@\p@
322 \global\advance\ex@ \@tempa\dimen@
323 \fi
324 \endgroup
325 %\typeout{\string\f@size: \f@size}\showthe\ex@
326 }
327 % \end{macrocode}
328 % Tests of the \cs{compute@ex@} function yield the following results:
329 %
330 % \begin{center}\begin{tabular}{rlrl}
331 % \cs{f@size}& \cs{ex@}& \cs{f@size}& \cs{ex@}\\
332 % 10& 1.0pt& 9& 0.94089pt\\
333 % 11& 1.05911pt& 8.7& 0.91266pt\\
334 % 12& 1.11473pt& 8.5& 0.91266pt\\
335 % 14.4& 1.23982pt& 8.4& 0.88527pt\\
336 % 17.28& 1.36684pt& 8& 0.88527pt\\
337 % 20.74& 1.5pt& 7& 0.83293pt\\
338 % 19.5& 1.4395pt& 6& 0.78369pt\\
339 % && 5& 0.73737pt\\
340 % && 1& 0.57785pt
341 % \end{tabular}\end{center}
342 %
343 % \begin{macro}{\@addpunct}
344 % Use of the \cs{@addpunct} function allows ending punctuation in
345 % section headings and elsewhere to be intelligently omitted
346 % when punctuation is already present.
347 % \begin{macrocode}
348 \def\@addpunct#1{\ifnum\spacefactor>\@m \else#1\fi}
349 % \end{macrocode}
350 % \end{macro}
351 %
352 % \begin{macro}{\frenchspacing}
353 % Change \cn{frenchspacing} to ensure that \cs{@addpunct} will
354 % continue to work properly even when `french' spacing is in effect.
355 % \begin{macrocode}
356 \def\frenchspacing{\sfcode`\.1006\sfcode`\?1005\sfcode`\!1004%
357 \sfcode`\:1003\sfcode`\;1002\sfcode`\,1001 }
358 % \end{macrocode}
359 % \end{macro}
360 %
361 % \subsection{Miscellaneous}
362 % \begin{macrocode}
363 \def\nomath@env{\@amsmath@err{%
364 \string\begin{\@currenvir} allowed only in paragraph mode%
365 }\@ehb% "You've lost some text"
366 }
367 % \end{macrocode}
368 % A trade-off between main memory space and hash size; using
369 % \verb+\Invalid@@+ saves 14 bytes of main memory for each use of
370 % \verb+\Invalid@+, at the cost of one control sequence name.
371 % \verb+\Invalid@+ is currently used about five times and
372 % \verb+\Invalid@@+ is used by itself in some other instances,
373 % which means that it saves us more memory than \verb+\FN@+,
374 % \verb+\RIfM@+, and some of the other abbreviations above.
375 % \begin{macrocode}
376 \def\Invalid@@{Invalid use of \string}
377 % \end{macrocode}
378 %
379 % The usual \cs{endinput} to ensure that random garbage at the end of
380 % the file doesn't get copied by \fn{docstrip}.
381 % \begin{macrocode}
382 \endinput
383 % \end{macrocode}
384 %
385 % \CheckSum{337}
386 % \Finale