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{amstext.sty}
33 \title{The \pkg{amstext} package}
34 \author{Frank Mittelbach \and Rainer Sch\"opf}
35 \date{Version \fileversion, \filedate}
36 \DocInput{amstext.dtx}
42 % \MaintainedByLaTeXTeam{amslatex}
46 % \section{Introduction}
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}.
55 % Here is an example demonstrating some of its features:
57 %^^A mathbin spacing is nonscript glue, disappears in superscript
58 % x^{2\,\times\,\text{size of $y$}}
60 % z_{i_{\text{upper bound of the array}}}
62 % This was produced by
65 % x^{2\,\times\,\text{size of $y$}}
67 % z_{i_{\text{upper bound of the array}}}
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.
76 % Package information.
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}[2000/06/29 v2.01 AMS text]
83 % \section{The implementation}
84 % We need a few tools from \fn{amsgen.sty}.
86 \RequirePackage{amsgen}
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.
94 \DeclareRobustCommand{\text}{%
95 \ifmmode\expandafter\text@\else\expandafter\mbox\fi}
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.
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 tyeset
112 % our text in all four possible styles.
114 \def\text@#1{{\mathchoice
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.
121 {\textdef@\displaystyle\f@size{#1}}%
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.
128 {\textdef@\textstyle\f@size{\firstchoice@false #1}}%
129 {\textdef@\textstyle\sf@size{\firstchoice@false #1}}%
130 {\textdef@\textstyle \ssf@size{\firstchoice@false #1}}%
132 % Here we need to check whether a math size-change occurred inside
133 % the argument of \cn{text}. If so, restore
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 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.)
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
167 \def\textdef@#1#2#3{\hbox{{%
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
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.
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
189 \let\f@size#2\selectfont
191 % Now we simply call the third argument and close all open groups.
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.
202 \newif\iffirstchoice@
207 % \subsection{Re-definition of \latex/ macros to work with \cn{text}}
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.
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/.
222 \addtocounter{#1}\@ne
223 \begingroup \let\@elt\@stpelt \csname cl@#1\endcsname \endgroup
229 % \begin{macro}{\addtocounter}
231 \def\addtocounter#1#2{%
233 \@ifundefined {c@#1}{\@nocounterr {#1}}%
234 {\global \advance \csname c@#1\endcsname #2\relax}%
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}.
245 \@xp\let\csname m@gobble4\endcsname\@gobblefour
246 \long\@xp\def\csname m@gobble6\endcsname#1#2#3#4#5#6{}
251 \csname m@gobble\iffirstchoice@\else 4\fi\endcsname
253 \edef\GenericInfo{\the\toks@
254 \@xp\@nx\csname GenericInfo \endcsname}
256 \edef\GenericWarning{\the\toks@
257 \@xp\@nx\csname GenericWarning \endcsname}
260 \csname m@gobble\iffirstchoice@\else 6\fi\endcsname
262 \edef\GenericError{\the\toks@
263 \@xp\@nx\csname GenericError \endcsname}
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.
271 % \text{something \index{foo}}
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]
277 %\subsection{Applications of \cn{text}}
279 % \begin{macro}{\mathhexbox}
280 % We start with an 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.)
286 \begingroup \catcode`\"=12
287 \gdef\mathhexbox#1#2#3{\text{$\m@th\mathchar"#1#2#3$}}
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.
295 % The usual \cs{endinput} to ensure that random garbage at the end of
296 % the file doesn't get copied by \fn{docstrip}.