Debian Codegraph @

texmf-dist/source/latex/amsmath/amstext.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{amstext}
31 \GetFileInfo{amstext.sty}
32 \begin{document}
33 \title{The \pkg{amstext} package}
34 \author{Frank Mittelbach \and Rainer Sch\"opf}
35 \date{Version \fileversion, \filedate}
36 \DocInput{amstext.dtx}
37 \end{document}
38 %</driver>
39 % \fi
40 %
41 % \maketitle
42 % \MaintainedByLaTeXTeam{amslatex}
43 %
44 % \MakeShortVerb\|
45 %
46 % \section{Introduction}
47 %
48 % This style file implements the \AmSTeX{} macro \cn{text} for use
49 % with the new font selection scheme. The \cn{text} macro is a
50 % sophisticated command which allows the user to insert ``normal text''
51 % into math formulas without worrying about correct sizes in sub- or
52 % superscripts. It can also be used in ordinary text; there it
53 % produces an unbreakable unit similar to \cn{mbox}.
54 %
55 % Here is an example demonstrating some of its features:
56 % \[
57 %^^A mathbin spacing is nonscript glue, disappears in superscript
58 % x^{2\,\times\,\text{size of $y$}}
59 % \leq
60 % z_{i_{\text{upper bound of the array}}}
61 % \]
62 % This was produced by
63 % \begin{verbatim}
64 % \[
65 % x^{2\,\times\,\text{size of $y$}}
66 % \leq
67 % z_{i_{\text{upper bound of the array}}}
68 % \]
69 % \end{verbatim}
70 %
71 % Additionally this style file redefines an internal \fn{plain.tex}
72 % macro called \cs{mathhexbox} so that commands like \cn{dag}
73 % or \cn{P} will change sizes if used in math subscripts.
74 %
75 % \MaybeStop{}
76 % Package information.
77 % \begin{macrocode}
78 \NeedsTeXFormat{LaTeX2e}% LaTeX 2.09 can't be used (nor non-LaTeX)
79 [1994/12/01]% LaTeX date must be December 1994 or later
80 \ProvidesPackage{amstext}[2024/11/17 v2.01 AMS text]
81 % \end{macrocode}
82 %
83 % \section{The implementation}
84 % We need a few tools from \fn{amsgen.sty}.
85 % \begin{macrocode}
86 \RequirePackage{amsgen}
87 % \end{macrocode}
88 %
89 % \begin{macro}{\text}
90 % Now we come to the \cn{text} macro which is used to place
91 % ordinary text inside of math formulas. If it is used outside
92 % math it will produce an unbreakable unit of text.
93 % \begin{macrocode}
94 \DeclareRobustCommand{\text}{%
95 \ifmmode\expandafter\text@\else\expandafter\mbox\fi}
96 % \end{macrocode}
97 % At the present time (late 1994) the \latex/ internal function
98 % |\nfss@text| is used in |\ref|, in font commands like |\textbf|,
99 % and in a few text symbol definitions like |\$| and |\pounds|. By
100 % equating |\nfss@text| to |\text| we give it the ability of
101 % |\text| to change sizes properly if used in a subscript.
102 % \begin{macrocode}
103 \let\nfss@text\text
104 % \end{macrocode}
105 % \end{macro}
106 %
107 % \begin{macro}{\text@}
108 % If \cn{text} is encountered inside math mode the macro
109 % \cs{text@} is called. It has one mandatory argument, the text
110 % which should be produced. Since we do not know in which math
111 % style we are currently in we call \cs{mathchoice} to typeset
112 % our text in all four possible styles.
113 % \begin{macrocode}
114 \def\text@#1{{\mathchoice
115 % \end{macrocode}
116 % To save token space we call a macro \cs{textdef@} which takes
117 % three arguments: the current math style, the corresponding size
118 % macro and the text to typeset possibly with some additional
119 % information for typesetting.
120 % \begin{macrocode}
121 {\textdef@\displaystyle\f@size{#1}}%
122 % \end{macrocode}
123 % The other three cases are similar except for the
124 % \cs{iffirstchoice@} switch which we set to false. This is
125 % done to prevent \LaTeX{} macros like \cn{ref} or \cn{index}
126 % from writing their arguments more than once.
127 % \begin{macrocode}
128 {\textdef@\textstyle\f@size{\firstchoice@false #1}}%
129 {\textdef@\textstyle\sf@size{\firstchoice@false #1}}%
130 {\textdef@\textstyle \ssf@size{\firstchoice@false #1}}%
131 % \end{macrocode}
132 % Here we need to check whether a math size-change occurred inside
133 % the argument of \cn{text}. If so, restore
134 % \begin{macrocode}
135 \check@mathfonts
136 }%
137 }
138 % \end{macrocode}
139 % The macros \cs{f@size}, \cs{sf@size} and \cs{ssf@size} hold the
140 % sizes which should be used when we are loading a new font for use
141 % in \cs{textfont}, \cs{scriptfont} and \cs{scriptscriptfont}. There
142 % is some question whether we should use \cs{tf@size} or
143 % \cs{f@size} for the main size, but since the primary purpose of the
144 % \cn{text} macro is to switch back to text within a display, it
145 % seems that \cs{f@size} is the better choice. (Indeed it could be
146 % said that the \cn{text} actually provides two different functions:
147 % one for escaping out of math mode in a display to print some words,
148 % and the other for handling math objects that are named by a
149 % fragment of text, when \cn{operatorname} isn't the right choice.
150 % For the latter \cs{tf@size} might be more correct but for the
151 % former \cs{f@size} is clearly better.)
152 % \end{macro}
153 %
154 % \begin{macro}{\textdef@}
155 % To typeset the argument of \cn{text} correctly we have to make
156 % several actions. We start by placing everything inside an
157 % \cs{hbox}. But this is not enough: we need one extra level of
158 % grouping. These extra braces are necessary because of the new
159 % font selection scheme which might produce an \cs{aftergroup}
160 % to globally restore some font values after the current group. To
161 % prevent any damage by this mechanism we add the braces thereby
162 % bringing the token inserted by \cs{aftergroup} inside the
163 % \cs{hbox}.\footnote{The mechanism will not produce a second
164 % \cs{aftergroup}. For more details see the technical documentation
165 % for NFSS2.}
166 % \begin{macrocode}
167 \def\textdef@#1#2#3{\hbox{{%
168 % \end{macrocode}
169 % Since text typeset inside an \cs{hbox} always stays in the size
170 % of the text surrounding the formula we have to adjust this for
171 % script and scriptscript sizes. For any math formula inside this
172 % argument this will be achieved by setting \cs{everymath} to
173 % the first argument of \cs{textdef@} since this argument
174 % contains the math size in the current typeset case of
175 % \cs{mathchoice}.
176 % Since \latex/ also knows about \cn{parbox}es and the
177 % \env{minipage} environment it might be neccessary to adjust
178 % \cs{everydisplay} too but this has to be tested further.
179 % \begin{macrocode}
180 \everymath{#1}%
181 % \end{macrocode}
182 % The next line of code changes locally (i.e.\ inside the current
183 % \cs{hbox}) the value of \cs{f@size}. This macro holds the
184 % size for typesetting ordinary text (e.g.\ loading or selecting a
185 % new font via \cs{selectfont}). By changing it to a smaller
186 % value a following \cs{selectfont} will switch to the wanted
187 % size.
188 % \begin{macrocode}
189 \let\f@size#2\selectfont
190 % \end{macrocode}
191 % Now we simply call the third argument and close all open groups.
192 % \begin{macrocode}
193 #3}}}
194 % \end{macrocode}
195 % \end{macro}
196 %
197 % \begin{macro}{\iffirstchoice@}
198 % Here is the switch that we use to decide if \cn{ref} etc.\
199 % should print its warnings. The default is true since
200 % normally these warnings shouldn't be suppressed.
201 % \begin{macrocode}
202 \newif\iffirstchoice@
203 \firstchoice@true
204 % \end{macrocode}
205 % \end{macro}
206 %
207 % \subsection{Re-definition of \latex/ macros to work with \cn{text}}
208 %
209 % If a counter-changing command occurs inside the argument of
210 % \cn{text}, we don't want the counter to be changed four times
211 % because \cn{stepcounter} and \cn{addtocounter} have global effect.
212 % So we add the \cs{iffirstchoice@} test to make the counter
213 % operations execute only once.
214 %
215 % \begin{macro}{\stepcounter}
216 % Use \cs{def} rather than \cn{renewcommand*} because the star-form
217 % (for non-\cs{long} definitions) doesn't work with the June 1994
218 % release of \latex/.
219 % \begin{macrocode}
220 \def\stepcounter#1{%
221 \iffirstchoice@
222 \addtocounter{#1}\@ne
223 \begingroup \let\@elt\@stpelt \csname cl@#1\endcsname \endgroup
224 \fi
225 }
226 % \end{macrocode}
227 % \end{macro}
228 %
229 % \begin{macro}{\addtocounter}
230 % \begin{macrocode}
231 \def\addtocounter#1#2{%
232 \iffirstchoice@
233 \@ifundefined {c@#1}{\@nocounterr {#1}}%
234 {\global \advance \csname c@#1\endcsname #2\relax}%
235 \fi}
236 % \end{macrocode}
237 % \end{macro}
238 %
239 % For \cn{ref}, \cn{pageref}, and indeed anything else that issues a
240 % warning or error, \cn{text} will produce four copies of the
241 % warning/error message. To suppress the last three copies, we change
242 % \cs{GenericInfo}, \cs{GenericWarning}, \cs{GenericError}.
243 % \begin{macrocode}
244 \let\m@gobble\@empty
245 \@xp\let\csname m@gobble4\endcsname\@gobblefour
246 \long\@xp\def\csname m@gobble6\endcsname#1#2#3#4#5#6{}
247 % \end{macrocode}
248 %
249 % \begin{macrocode}
250 \toks@{%
251 \csname m@gobble\iffirstchoice@\else 4\fi\endcsname
252 \protect}
253 \edef\GenericInfo{\the\toks@
254 \@xp\@nx\csname GenericInfo \endcsname}
255 %
256 \edef\GenericWarning{\the\toks@
257 \@xp\@nx\csname GenericWarning \endcsname}
258 %
259 \toks@{%
260 \csname m@gobble\iffirstchoice@\else 6\fi\endcsname
261 \protect}
262 \edef\GenericError{\the\toks@
263 \@xp\@nx\csname GenericError \endcsname}
264 % \end{macrocode}
265 %
266 % At one time \cn{label}, \cs{@wrindex} and \cs{@wrglossary} were
267 % changed here too to use the \cs{iffirstchoice@} test but it seems
268 % that was a mistake because those are non-immediate writes.
269 % Something like
270 % \begin{verbatim}
271 % \text{something \index{foo}}
272 % \end{verbatim}
273 % within a math formula would therefore \emph{lose the index term} if
274 % the surrounding context was not displaystyle. (Unlikely in
275 % practice, but not impossible.) [mjd,1994/12/09]
276 %
277 %\subsection{Applications of \cn{text}}
278 %
279 % \begin{macro}{\mathhexbox}
280 % We start with a re-definition of the \fn{plain.tex} macro
281 % \cs{mathhexbox}. (Although M. Spivak in \amstex/ uses the name
282 % \cs{mathhexbox@} for this purpose, I [FMi] don't see any reason
283 % to use a new name since the new definition is superior, has the
284 % same syntax and is used for the same purpose.)
285 % \begin{macrocode}
286 \begingroup \catcode`\"=12
287 \gdef\mathhexbox#1#2#3{\text{$\m@th\mathchar"#1#2#3$}}
288 \endgroup
289 % \end{macrocode}
290 % This redefinition means that now symbols like \S, \P, \dag, \ldots,
291 % which are defined via \cs{mathhexbox} in \fn{plain.tex} or
292 % elsewhere now correctly change sizes if they are used in math mode.
293 % \end{macro}
294 %
295 % The usual \cs{endinput} to ensure that random garbage at the end of
296 % the file doesn't get copied by \fn{docstrip}.
297 % \begin{macrocode}
298 \endinput
299 % \end{macrocode}
300 %
301 % \CheckSum{129}
302 % \Finale