2 % \iffalse meta-comment
4 % Copyright 1995, 1999 American Mathematical Society.
5 % Copyright 2016 LaTeX3 Project and American Mathematical Society.
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 % http://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.
15 % This work has the LPPL maintenance status `maintained'.
17 % The Current Maintainer of this work is the LaTeX3 Project.
23 \documentclass{amsdtx}
24 \def\MaintainedByLaTeXTeam#1{%
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{http://latex-project.org/bugs.html}.\end{tabular}}}\end{center}}
31 \GetFileInfo{amsgen.sty}
33 \title{The \pkg{amsgen} package}
34 \author{American Mathematical Society\\Michael Downes}
35 \date{Version \fileversion, \filedate}
42 % \MaintainedByLaTeXTeam{amslatex}
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/
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'.}
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]
65 % \section{Implementation}
66 % Some general macros shared by \fn{amsart.dtx}, \fn{amsmath.dtx},
67 % \fn{amsfonts.dtx}, \dots
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.
80 \providecommand{\@saveprimitive}[2]{\begingroup\escapechar`\\\relax
81 \edef\@tempa{\string#1}\edef\@tempb{\meaning#1}%
82 \ifx\@tempa\@tempb \global\let#2#1%
85 % Check to see if \arg{2} was already given the desired primitive
86 % meaning somewhere else.
88 \edef\@tempb{\meaning#2}%
91 \@latex@error{Unable to properly define \string#2; primitive
92 \noexpand#1no longer primitive}\@eha
100 % \begin{macro}{\@nx}
101 % Shorthands for long command names.
103 \let\@xp=\expandafter
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.
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
123 % \usepackage{amsmath,amsthm}
126 \def\@oparg#1[#2]{\@ifnextchar[{#1}{#1[#2]}}
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
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}
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.
147 \long\def\@ifnotempty#1{\@ifempty{#1}{}}
152 % Some abbreviations to conserve token mem.
154 \def\FN@{\futurelet\@let@token}
156 \def\RIfM@{\relax\ifmmode}
157 \def\setboxz@h{\setbox\z@\hbox}
160 \def\relaxnext@{\let\@let@token\relax}
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.
167 \long\def\new@ifnextchar#1#2#3{%
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
174 \def\reserved@a{#2}\def\reserved@b{#3}%
175 \futurelet\@let@token\new@ifnch
179 \ifx\@let@token\reserved@d \let\reserved@b\reserved@a \fi
185 % \begin{macro}{\@ifstar}
186 % There will essentially never be a space before the \qc{\*}, so
187 % using \cs{@ifnextchar} is unnecessarily slow.
189 \def\@ifstar#1#2{\new@ifnextchar *{\def\reserved@a*{#1}\reserved@a}{#2}}
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}).
199 \@ifundefined{every@math@size}{%
201 % Reuse the same token register; since it was never used except for
202 % the purposes that are affected below, this is OK.
204 \let\every@math@size=\every@size
206 \expandafter\ifx\csname S@\f@size\endcsname\relax
207 \calculate@math@sizes
209 \csname S@\f@size\endcsname
211 % \ifnum \tracingfonts>\tw@
212 % \@font@info{Setting up math fonts for
213 % \f@size/\f@baselineskip}\fi
216 \csname mv@\math@version \endcsname
218 \let \glb@currsize \f@size
223 % \ifnum \tracingfonts>\tw@
224 % \@font@info{No math setup for \f@size/\f@baselineskip}%
229 % Remove |\the\every@size| from \cs{size@update}.
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
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
247 \let\size@update\relax}%
249 }{}% end \@ifundefined test
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@}.
263 \addto@hook\every@math@size{\compute@ex@}
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.
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}})
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.
289 % Never make \cs{ex@} larger than 1.5pt.
294 % Adjust by the reference size and multiply by 2 to allow for
297 \advance\dimen@10\p@ \multiply\dimen@\tw@
299 % Save information about the current sign of \cs{dimen@}.
301 \edef\@tempa{\ifdim\dimen@>\z@ -\fi}%
303 % Get the absolute value of \cs{dimen@}.
305 \dimen@ \ifdim\dimen@<\z@ -\fi \dimen@
306 \advance\dimen@-\@m sp % fudge factor
308 % Here we use \cs{vfuzz} merely as a convenient scratch register
312 % Multiply in a loop.
314 \def\do{\ifdim\dimen@>\z@
317 %\message{\vfuzz: \the\vfuzz, \dimen@: \the\dimen@}%
320 \dimen@\p@ \advance\dimen@-\vfuzz
322 \global\advance\ex@ \@tempa\dimen@
325 %\typeout{\string\f@size: \f@size}\showthe\ex@
328 % Tests of the \cs{compute@ex@} function yield the following results:
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\\
341 % \end{tabular}\end{center}
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.
348 \def\@addpunct#1{\ifnum\spacefactor>\@m \else#1\fi}
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.
356 \def\frenchspacing{\sfcode`\.1006\sfcode`\?1005\sfcode`\!1004%
357 \sfcode`\:1003\sfcode`\;1002\sfcode`\,1001 }
361 % \subsection{Miscellaneous}
363 \def\nomath@env{\@amsmath@err{%
364 \string\begin{\@currenvir} allowed only in paragraph mode%
365 }\@ehb% "You've lost some text"
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.
376 \def\Invalid@@{Invalid use of \string}
379 % The usual \cs{endinput} to ensure that random garbage at the end of
380 % the file doesn't get copied by \fn{docstrip}.