%%% ====================================================================
%%%  @LaTeX-file{
%%%     filename        = "amsfonts.dtx",
%%%     version         = "1.2beta",
%%%     date            = "1994/12/13",
%%%     time            = "11:38:30 EST",
%%%     author          = "American Mathematical Society",
%%%     copyright       = "Copyright (C) 1994 American Mathematical Society,
%%%                        all rights reserved.  Copying of this file is
%%%                        authorized only if either:
%%%                        (1) you make absolutely no changes to your copy,
%%%                        including name; OR
%%%                        (2) if you do make changes, you first rename it
%%%                        to some other name.",
%%%     address         = "American Mathematical Society,
%%%                        Technical Support,
%%%                        Electronic Products and Services,
%%%                        P. O. Box 6248,
%%%                        Providence, RI 02940,
%%%                        USA",
%%%     telephone       = "401-455-4080 or (in the USA and Canada)
%%%                        800-321-4AMS (321-4267)",
%%%     FAX             = "401-331-3842",
%%%     checksum        = "54647 485 2257 19037",
%%%     email           = "tech-support@math.ams.org (Internet)",
%%%     codetable       = "ISO/ASCII",
%%%     keywords        = "latex, amslatex, ams-latex, amsfonts, msam,
%%%                        msbm, eufm, blackboard bold",
%%%     supported       = "yes",
%%%     abstract        = "This file is part of the AMS-\LaTeX{} package,
%%%                        It is a \LaTeX{} option that provides a
%%%                        `newsymbol' command for defining math symbols
%%%                        from the two math symbol fonts in the AMSFonts
%%%                        (version 2.0+) font package. It also defines
%%%                        commands for producing Fraktur and `blackboard
%%%                        bold' letters (uppercase only). See the AMSFonts
%%%                        user's guide for more information.",
%%%     docstring       = "The checksum field above contains a CRC-16
%%%                        checksum as the first value, followed by the
%%%                        equivalent of the standard UNIX wc (word
%%%                        count) utility output of lines, words, and
%%%                        characters.  This is produced by Robert
%%%                        Solovay's checksum utility.",
%%%  }
%%% ====================================================================
% \iffalse
%<*driver>
\documentclass{amsdtx}
\begin{document}
\title{The \texttt{amsfonts} package}
\author{Frank Mittelbach\\Rainer Sch\"opf\\Michael Downes}
\date{Version \fileversion, \filedate}
\hDocInput{amsfonts.dtx}
\end{document}
%</driver>
% \fi
%
% \maketitle
%
% \MakeShortVerb\|
%
% \section{Introduction}
%
%    The package \pkg{amsfonts} makes math fonts from the AMSFonts
%    package usable within \latex/. It also provides some special
%    struts and redefines \cn{big}, \cn{Big}, etc to scale properly in
%    large or small sizes.
%
% \StopEventually{}
%
% \changes{v1.2}{1994/10/25}{Made every@math@size code explicitly global}
%
%    Provide package info.
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{amsfonts}[1994/10/25 v1.2beta]
%    \end{macrocode}
%
%    \begin{macrocode}
\let\@amsfonts=T
\DeclareOption{noamsfonts}{\let\@amsfonts=F}
%    \end{macrocode}
%    The `psamsfonts' option is intended to mean that the Y\&Y/Blue Sky
%    Research PostScript versions of the AMSFonts should be used. In
%    that font set, the only \fn{.tfm} files provided below size 10 are
%    5 and 7, rather than 5,6,7,8,9. This means that if the standard
%    \fn{.fd} files are used, any attempt to use 6,8,9 point math will
%    result in error messages about missing \fn{.tfm} files. In order to
%    ensure that the proper \fn{.fd} files are used for the PS case, we
%    preload them immediately. Otherwise the \fn{.fd} files would be
%    auto-loaded when \LaTeX{} encounters the first math formula in a
%    document, and the standard auto-loading mechanisms don't provide a
%    way [that I know of---mjd,7-Oct-1994] to choose the `57' varieties
%    of the \fn{.fd} files.
%    \begin{macrocode}
\DeclareOption{psamsfonts}{%
  \input{Umsa57.fd}\input{Umsb57.fd}\input{Ueuf57.fd}}
%    \end{macrocode}
%
%    Process the package options.
%    \begin{macrocode}
\ProcessOptions
%    \end{macrocode}
%
%    We'll need some of the general utility functions from
%    \fn{amsgen.sty}.
%    \begin{macrocode}
\RequirePackage{amsgen}
%    \end{macrocode}
%
% \section{Size dependent definitions}
%
%    We now define all stuff which has to change whenever a new math
%    size is to be activated. \latex/ provides a hook called
%    |\every@math@size| to support such a need. All assignments in the
%    |\every@math@size| hook that need to take outside effect should be
%    global.
%
% \subsection{Struts for math}
%
%    The macros in this section should all be reimplemented because by
%    now there exist too many concepts which handle the same material in
%    a slightly different manner. All these ideas should be carefully
%    studied and everything unnecessary should be removed. This includes
%    also the {\tt ltplain.dtx} file where a lot of these commands are
%    still defined. (FMi)
%
%    For example perhaps the \cn{bBigg} delimiters could use
% \begin{verbatim}
% 1.2\ht\strutbox (1.8, 2.4, 3.0)
% \end{verbatim}
%    instead of
% \begin{verbatim}
% 1.0\big@size (1.5, 2.0, 2.5)
% \end{verbatim}
%    since \cs{strut} is reset with every size change [mjd,7-Oct-1994].
%    But this change would introduce the possibility of changed line
%    and page breaks in existing documents, so would need to be
%    handled with care.
%
% \begin{macro}{\Mathstrut@}
% \begin{macro}{\Mathstrutbox@}
%    Here comes the code for Spivak's |\Mathstrut@|.
%    \begin{macrocode}
\newbox\Mathstrutbox@
\setbox\Mathstrutbox@=\hbox{}
\def\Mathstrut@{\copy\Mathstrutbox@}
%    \end{macrocode}
%     The setting of the height and depth of the |\Mathstrutbox@|
%     is done in the |\every@math@size| hook since it depends on the
%     height of a paren (note: we assume the text paren and math paren
%     have the same height).
%    \begin{macrocode}
\addto@hook\every@math@size{\setbox\z@\hbox{\normalfont(}%
%    \end{macrocode}
%    These height and depth assignments are implicitly global.
%    \begin{macrocode}
  \ht\Mathstrutbox@\ht\z@ \dp\Mathstrutbox@\dp\z@}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\strut@}
% \begin{macro}{\strutbox@}
%    Next follows a special internal strut which is supposed to match
%    the height and the depth of a normal |\strut| minus
%    |\normallineskiplimit| according to M. Spivak.
%    \begin{macrocode}
\newbox\strutbox@
\def\strut@{\copy\strutbox@}
\addto@hook\every@math@size{%
  \global\setbox\strutbox@\hbox{\lower.5\normallineskiplimit
         \vbox{\kern-\normallineskiplimit\copy\strutbox}}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \subsection{Big delimiters}
%
%    We are now going to redefine the Plain \tex/ commands |\big|,
%    |\bigl| etc.\ to produce different results in different sizes.
%    Actually we only have to define |\big|, |\Big| etc.\ since
%    commands  like |\bigl| are all defined in terms of these
%    commands.
%
% \begin{macro}{\big}
% \begin{macro}{\Big}
% \begin{macro}{\bigg}
% \begin{macro}{\Bigg}
%     To save token space we put everything into the common macro
%    |\bBigg@|. The macros are now simply a call to |\bBigg@| with a
%    factor to determine the correct height of the delimiter as an
%    argument. This code should better go into a future version of
%    \fn{ltplain.tex}; the macro |\n@space| is then superfluous (since it
%    is only used once) and should be removed to avoid wasting hash
%    table space unnecessarily.
%    \begin{macrocode}
\def\big{\bBigg@\@ne}
\def\Big{\bBigg@{1.5}}
\def\bigg{\bBigg@\tw@}
\def\Bigg{\bBigg@{2.5}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\bBigg@}
%    Now we tackle the macro which has to do the real work. It
%    actually has two arguments, the factor and the wanted delimiter.
%    \begin{macrocode}
\def\bBigg@#1#2{%
%    \end{macrocode}
%    We start with an extra set of braces because we want
%    constructions like |\def\bigl{\mathopen\big}| to work without the
%    overhead of extra arguments.
%    \begin{macrocode}
   {%
    \hbox{$\left#2\vcenter to#1\big@size{}\right.%
           \n@space
     $}}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\big@size}
%    |\big@size| needs to be set to 1.2 times the height of a math
%    paren. This height is already recorded in |\Mathstrutbox@|.
%    \begin{macrocode}
\addto@hook\every@math@size{%
  \global\big@size 1.2\ht\Mathstrutbox@
  \global\advance\big@size 1.2\dp\Mathstrutbox@ }
\newdimen\big@size
%    \end{macrocode}
% \end{macro}
%
%    If the `noamsfonts' option was specified, we skip the remainder
%    of this file.
%    \begin{macrocode}
\ifx F\@amsfonts \endinput\fi
%    \end{macrocode}
%
% \section{Preparing to use the \AmSTeX{} fonts}
%
%    We declare the encoding schemes for two AMS math symbol fonts.
%    U encoding with |\noaccents@| for math is already provided
%    in base NFSS
%
%    The AMS symbol fonts will be assigned via |\DeclareSymbolFont|
%    since most of their characters are accessed with the |\mathchardef|
%    primitive. This means that these fonts are loaded for the
%    particular size whenever a size or version switch is requested by
%    the user. At the present time bold forms of these fonts don't
%    exist. So there are no overriding |\SetSymbolFont| commands for
%    mathversion `bold'.
%    \begin{macrocode}
\DeclareSymbolFont{AMSa}{U}{msa}{m}{n}
\DeclareSymbolFont{AMSb}{U}{msb}{m}{n}
%    \end{macrocode}
%
%    The next constructs are symbols that work the same in text or math.
%    They are built the hard way using |\hexnumber@\sym...|.
%    \begin{macrocode}
\@ifundefined{yen}{%
  \edef\yen{\noexpand\mathhexbox{\hexnumber@\symAMSa}55}
}{}
\@ifundefined{checkmark}{%
  \edef\checkmark{\noexpand\mathhexbox{\hexnumber@\symAMSa}58}
}{}
\@ifundefined{circledR}{%
  \edef\circledR{\noexpand\mathhexbox{\hexnumber@\symAMSa}72}
}{}
\@ifundefined{maltese}{%
  \edef\maltese{\noexpand\mathhexbox{\hexnumber@\symAMSa}7A}
}{}
%    \end{macrocode}
%
%    We now define a few symbols which reside in the msam and msbm fonts
%    The |\catcode| change is to ensure that the double-quote character
%    is not active (which at one time was a problem when something like
%    {\tt german.sty} was used).
%    \begin{macrocode}
\begingroup \catcode`\"=12
\DeclareMathDelimiter\ulcorner{\mathopen} {AMSa}{"70}{AMSa}{"70}
\DeclareMathDelimiter\urcorner{\mathclose}{AMSa}{"71}{AMSa}{"71}
\DeclareMathDelimiter\llcorner{\mathopen} {AMSa}{"78}{AMSa}{"78}
\DeclareMathDelimiter\lrcorner{\mathclose}{AMSa}{"79}{AMSa}{"79}
%    \end{macrocode}
%
%    The next two definitions redefine the |\widehat| and
%    |\widetilde| command to use a special accent if their
%    argument is suitably wide. (In plain \TeX{} these commands can
%    produce three different accents depending on the size of the
%    argument.)  The current implementation will tend to give wrong results
%    (tilde or hat symbol too wide) if these accents are used in script
%    or scriptscript math style. But making that part work properly is
%    too much effort given the limitations of \TeX{} 3.x.
%    \begin{macrocode}
\xdef\widehat#1{\noexpand\@mathmeasure\z@\textstyle{#1}%
  \noexpand\ifdim\noexpand\wdz@>\tw@ em%
  \mathaccent"0\hexnumber@\symAMSb 5B{#1}%
  \noexpand\else\mathaccent"0362{#1}\noexpand\fi}
%
\xdef\widetilde#1{\noexpand\@mathmeasure\z@\textstyle{#1}%
  \noexpand\ifdim\noexpand\wdz@>\tw@ em%
  \mathaccent"0\hexnumber@\symAMSb 5D{#1}%
  \noexpand\else\mathaccent"0365{#1}\noexpand\fi}
%    \end{macrocode}
%    Now we define two special arrows which are built with special
%    characters from the first symbol font.
%    \begin{macrocode}
\DeclareMathSymbol\dabar@{\mathord}{AMSa}{"39}
\xdef\dashrightarrow{\mathrel{\dabar@\dabar@
                              \mathchar"0\hexnumber@\symAMSa 4B}}%
\xdef\dashleftarrow{\mathrel{\mathchar"0\hexnumber@\symAMSa 4C\dabar@
                              \dabar@}}%
%
\global\let\dasharrow\dashrightarrow
%    \end{macrocode}
%    To avoid using too many control sequence names by defining all
%    new symbols provided with the two fonts, we defined so far only
%    symbols which are not assigned via |\mathchardef|. The majority
%    however will be only defined if the user calls the {\tt amssymb}
%    documentstyle option or by explicitly defining symbols using the
%    |\DeclareMathSymbol| macro.
%
%    Finally we test the |\DeclareMathSymbol| command by redefining the
%    \PlainTeX{} symbols which where made up from different characters
%    (and thus could not change sizes properly) but are now available
%    as real characters. Note that we have to make them undefined
%    first otherwise |\DeclareMathSymbol| will complain that they are
%    already defined.
%    \begin{macrocode}
\global\let\rightleftharpoons\undefined
\DeclareMathSymbol\rightleftharpoons{\mathrel}{AMSa}{"0A}
\global\let\angle\undefined
\DeclareMathSymbol\angle            {\mathord}{AMSa}{"5C}
\global\let\hbar\undefined
\DeclareMathSymbol\hbar             {\mathord}{AMSb}{"7E}
\global\let\sqsubset\undefined
\DeclareMathSymbol\sqsubset         {\mathrel}{AMSa}{"40}
\global\let\sqsupset\undefined
\DeclareMathSymbol\sqsupset         {\mathrel}{AMSa}{"41}
\global\let\mho\undefined
\DeclareMathSymbol\mho              {\mathord}{AMSb}{"66}
%    \end{macrocode}
%
%      Just to avoid inconsistency with the LaTeX manual, let's define
%      these math symbols from the lasy fonts so that a newsymbol
%      statement from the user isn't required. For most users this uses
%      up string pool unnecessarily, sigh. We let them to |\undefined|
%      first in case they were defined earlier through some combination
%      of format file or option file choices. Otherwise |\newsymbol|
%      would produce an error message.
%
%    First we load the symbols under the official AMS names and the
%    define the \LaTeX{} names via |\let| unless they are already
%    defined (which probably means that the lasy fonts are defined).
%
%    \begin{macrocode}
\DeclareMathSymbol\square           {\mathord}{AMSa}{"03}
\DeclareMathSymbol\lozenge          {\mathord}{AMSa}{"06}
\DeclareMathSymbol\vartriangleright {\mathrel}{AMSa}{"42}
\DeclareMathSymbol\vartriangleleft  {\mathrel}{AMSa}{"43}
\DeclareMathSymbol\trianglerighteq  {\mathrel}{AMSa}{"44}
\DeclareMathSymbol\trianglelefteq   {\mathrel}{AMSa}{"45}
\DeclareMathSymbol\rightsquigarrow  {\mathrel}{AMSa}{"20}
%    \end{macrocode}
%    The next few symbols are not at all perfect. We define them here
%    only temp.\ until proper shapes have been added to the fonts.
%    Also we define them only if the still are in virgin state. (FMi)
%    \begin{macrocode}
\def\@tempa{\not@base\lhd}
\ifx\lhd\@tempa
 \global\let\lhd\vartriangleleft
 \global\let\unlhd\trianglelefteq
 \global\let\rhd\vartriangleright
 \global\let\unrhd\trianglerighteq
 \global\let\Box\square
 \global\let\Diamond\lozenge
 \global\let\leadsto\rightsquigarrow
%    \end{macrocode}
%      No equivalent of the |\Join| symbol in lasy is available in
%      msam or msbm so we make do with a composite of two
%      characters.
%
%    \begin{macrocode}
\xdef\Join{\mathrel{\mathchar"0\hexnumber@\symAMSb 6F\mkern-13.8mu%
  \mathchar"0\hexnumber@\symAMSb 6E}}
\fi
%    \end{macrocode}
%
%    Now we close the group so that |"| will get its old |\catcode|
%    back.
%    \begin{macrocode}
\endgroup
%    \end{macrocode}
%
% \section{Defining \protect\meta{math alphabet identifiers}}
%
% \begin{macro}{\mathfrak}
%    The Fraktur alphabet will be accessed by the command
%    |\mathfrak| inside of math mode.
%    \begin{macrocode}
\DeclareMathAlphabet\mathfrak{U}{euf}{m}{n}
\SetMathAlphabet\mathfrak{bold}{U}{euf}{b}{n}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\mathbb}
%      The AMS symbol font B contains the blackboard bold math alphabet.
%      There is only a single weight of this alphabet so it is used in
%      all math versions.
%    \begin{macrocode}
\DeclareSymbolFontAlphabet{\mathbb}{AMSb}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Setting up the fonts for correct accents in math}
%
%    There are a few \meta{math alphabets} which don't have any or
%    enough accents for math in the corresponding fonts. For example the
%    |\mathbb| \meta{math alphabet identifier} comes from a symbol font
%    with none of the normal accents in the correct places. \AmSTeX{}
%    has a sophisticated solution for this problem: all math
%    accents are defined in a way that the font where the accents are
%    taken from depends on the current value of a macro called
%    |\accentclass@|. To support this idea \meta{math alphabet
%    identfier} which come with their own accents should set this macro
%    to the number {\tt 7} (variable family in the speech if the
%    \TeX{}book) all others should set it to {\tt 0} so that the accents
%    are taken from the \meta{math group} zero in the current {\em math
%    version}.
%
%    There is a |\DeclareFontEncodingDefaults| macro which declares such
%    defaults. For the {\tt amsfonts} package we set this default in the
%    following way. This information will be ignored unless the amstex
%    package is also loaded.
%    \begin{macrocode}
\DeclareFontEncodingDefaults{\relax}{\def\accentclass@{7}}
%    \end{macrocode}
%
% \section{Some backward compatibility definitions}
%
%    The following commands are provided for compatibility
%    reasons.
% \begin{macro}{\frak}
% \begin{macro}{\Bbb}
% \begin{macro}{\bold}
%    \begin{macrocode}
\def\frak{\@subst@obsolete\frak\mathfrak}
\def\Bbb{\@subst@obsolete\Bbb\mathbb}
\def\bold{\@subst@obsolete\bold\mathbf}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
%    The \cn{newsymbol} command has different syntax than
%    \cn{DeclareMathSymbol} so it cannot use the direct substitution
%    function \cs{@subst@obsolete}.
%    \begin{macrocode}
\begingroup \catcode`\"=12 \relax
\gdef\newsymbol#1#2#3#4#5{%
  \@obsolete\newsymbol\DeclareMathSymbol
  \@ifdefinable#1{%
     \edef\next@
       {\ifcase #2 \or
          \hexnumber@\symAMSa\or
          \hexnumber@\symAMSb\fi}%
     \ifx\next@\@empty
       \PackageError{amsfonts}{\Invalid@@\newsymbol}\@ehd%
     \else
      \global\mathchardef#1"#3\next@#4#5
     \fi}}
\endgroup
%    \end{macrocode}
%
%    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{369}
% \Finale
