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