%%% ====================================================================
%%%  @LaTeX-file{
%%%     filename        = "amsfonts.dtx",
%%%     version         = "2.2b",
%%%     date            = "1995/02/01",
%%%     time            = "11:12:55 EST",
%%%     author          = "American Mathematical Society",
%%%     copyright       = "Copyright (C) 1995 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        = "60492 437 2050 17848",
%%%     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 is part of the AMSFonts distribution,
%%%                        It provides easy access to certain math fonts
%%%                        for extra math symbols, fraktur letters, and
%%%                        blackboard bold letters."
%%%     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 some of the math fonts from the
%    AMSFonts package usable within \latex/. For wholesale substitution
%    of Euler math, see Frank Jensen's \pkg{euler} package.
%
% \StopEventually{}
%
%    Provide package info.
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{amsfonts}[1995/02/01 v2.2b]
%    \end{macrocode}
%
% \section{Package options}
%
% \subsection{The psamsfonts option}
%
%    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
%    load 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}{%
  \ifnum\cmex@opt=7 \def\cmex@opt{10}%
  \else \def\cmex@opt{0}\fi
  \input{Umsa57.fd}\input{Umsb57.fd}\input{Ueuf57.fd}}
%    \end{macrocode}
%
% \subsection{Font definitions for \fn{cmex}}
%    The AMSFonts distribution provides some extra sizes of the
%    \fn{cmex} font; these will not be used by \latex/ unless we change
%    the font definition that refers to \fn{cmex}. However, when the
%    Y\&Y/Blue Sky Research PostScript versions of the AMSFonts are
%    used, there is only \fn{cmex10}, and no smaller sizes. Because of
%    complications in the order of option processing, we use a flag that
%    will be set to `0' by the \fn{psamsfonts} option, and initialize
%    it to `1'. This means that sizes 7--9 of \fn{cmex} will be used,
%    unless the \opt{psamsfonts} option is in effect. There's probably a
%    better way to do this (submit your suggestions please to
%    \fn{tech-support@math.ams.org}) but I don't see anything obvious at
%    the moment [mjd,1995/01/31]. If the flag is already defined, then
%    we assume that it was set by an earlier load of \pkg{amsmath}, and
%    we don't override its value.
%    \begin{macrocode}
\@ifundefined{cmex@opt}{\def\cmex@opt{1}}{}
%    \end{macrocode}
%
%    Process the options for this package.
%    \begin{macrocode}
\ProcessOptions\relax
%    \end{macrocode}
%
%    Processing the cmex7 and cmex10 options is a little tricky because
%    of different possible loading orders for \pkg{amsmath} and
%    \pkg{amsfonts}. The package \pkg{amsmath} sets the \cs{cmex@opt}
%    flag to 7 or 10, and the package \pkg{amsfonts} sets the flag to 1
%    or 0.
%    \begin{macrocode}
\ifnum\cmex@opt=1 \relax
  \catcode`\ =9
  \DeclareFontShape{OMX}{cmex}{m}{n}{%
    <-8> cmex7%
    <8> cmex8%
    <9> cmex9%
    <10> <10.95> <12> <14.4> <17.28> <20.74> <24.88>cmex10%
  }{}%
  \expandafter\let\csname OMX/cmex/m/n/10\endcsname\relax
  \catcode`\ =10
\else
  \ifnum\cmex@opt=10 % need to override cmex7 fontdef from amsmath
    \input{OMXcmex.fd}%
    \expandafter\let\csname OMX/cmex/m/n/10\endcsname\relax
    \def\cmex@opt{0}%
  \fi
\fi
%    \end{macrocode}
%
% \section{Miscellaneous}
%    In case the \pkg{amsfonts} package is used apart from the
%    \pkg{amsmath} package, we need to define the following functions.
%    Note: we don't use \cn{providecommand} because the June 94 release
%    of \LaTeX{} doesn't support the \verb'*' option for non-long
%    commands and we don't want to assume [at this time---1995/01/30]
%    that all users have upgraded to the December 94 release.
%    \begin{macrocode}
\@ifundefined{@mathmeasure}{%
  \def\@mathmeasure#1#2#3{\setbox#1\hbox{\frozen@everymath\@emptytoks
    \m@th$#2#3$}}
}{}
\@ifundefined{@emptytoks}{% \newtoks is still outer in LaTeX2e---why?
  \csname newtoks\endcsname\@emptytoks
}{}
%    \end{macrocode}
%
% \section{Preparing to use the extra math fonts}
%
%    We declare the encoding schemes for two AMS math symbol fonts.
%    U encoding with \cs{noaccents@} for math is already provided
%    in base NFSS
%
%    The AMS symbol fonts will be assigned via \cs{DeclareSymbolFont}
%    since most of their characters are accessed with the \cs{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 \cs{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...|.
%    Also, for compatibility with both June 1994 and December 1994
%    releases of \latex/ we avoid the use of \cn{DeclareTextSymbol}
%    here.
%    \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 \fn{msam} and \fn{msbm} fonts
%    The \cs{catcode} change is to ensure that the double-quote character
%    is not active (which at one time was a problem when something like
%    \fn{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 \cs{widehat} and
%    \cs{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\wd\z@>\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\wd\z@>\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 \cs{mathchardef}. The majority
%    however will be only defined if the user calls the {\tt amssymb}
%    documentstyle option or by explicitly defining symbols using the
%    \cs{DeclareMathSymbol} macro.
%
%    Finally we test the \cs{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 \cs{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}
%
%    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 with pre-1995
%    versions of the \pkg{amsfonts} package. If a \cn{documentclass}
%    command is used the \cs{@obsolete} function will issue a warning
%    saying that the command is obsolete.
%
% \begin{macro}{\frak}
% \begin{macro}{\Bbb}
% \begin{macro}{\bold}
%    \begin{macrocode}
\def\frak{\@subst@obsolete{amsfonts}\frak\mathfrak}
\def\Bbb{\@subst@obsolete{amsfonts}\Bbb\mathbb}
\def\bold{\@subst@obsolete{amsfonts}\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{amsfonts}\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}
%
%  \begin{macro}{\@obsolete}
%    This command gives a warning on the first use that the command
%    given as second arg is deprecated/obsolete, with the third arg
%    recommended as a substitute. In compatibility mode we just continue
%    silently.
%    \begin{macrocode}
\long\def\@gobblethree#1#2#3{}
\if@compatibility
  \let\@obsolete\@gobblethree
\else
  \def\@obsolete#1#2#3{\PackageWarning{#1}{%
    Obsolete command \protect#2; \protect#3 should be used instead}}%
\fi
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\@subst@obsolete}
%    For obsolete commands that have a substitute command.
%    \begin{macrocode}
\def\@subst@obsolete#1#2#3{\@obsolete{#1}#2#3\gdef#2{#3}#2}
%    \end{macrocode}
%  \end{macro}
%
%    If we're processing a pre-existing LaTeX 2.09 document, define
%    \cn{square} etc.\@ for compatibility reasons. Otherwise we should
%    leave those symbols undefined: the \latex/ symbols \cn{Box},
%    etc.\@ were moved into the \pkg{latexsym} package for \LaTeXe{} so
%    it's no longer mandatory to emulate them.
%    \begin{macrocode}
\if@compatibility \else \endinput \fi
%    \end{macrocode}
%
%    First we load the symbols under the official AMS names and then
%    define the \latex/ names via \cs{let} unless they are already
%    defined (which probably means that the lasy fonts are defined).
%    \begin{macrocode}
\begingroup \catcode`\"=12
\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}
%    Check if \cn{lhd} still has its initial (disabled) state:
%    \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
\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}
%
% \changes{v1.2beta}{1994/10/25}{Made every@math@size code explicitly global}
% \changes{v1.2}{1994/12/08}{Exported non-font stuff elsewhere}
% \changes{v2.2}{1995/01/05}{Moved square, Box, etc to compat-only section}
% \changes{v2.2a}{1995/01/30}{Added missing def for @mathmeasure}
% \changes{v2.2b}{1995/02/01}{Dealt with cmex font complications}
%
% \CheckSum{361}
% \Finale
