%\iffalse
% Copyright 1997 Javier Bezos-L\'opez. All rights reserved.
% 
% This file is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
% 
% IMPORTANT COPYRIGHT NOTICE:
%
% Permission is granted to copy this file to another file with a clearly
% different name and to customize the declarations in that copy to serve
% the needs of your installation, provided that you comply with
% the conditions in the file legal.txt from the LaTeX2e distribution.
% 
% However, NO PERMISSION is granted to produce or to distribute a
% modified version of this file under its original name.
%  
% You are NOT ALLOWED to change this file.
%
%\fi
\def\fileversion{1.0a}
\def\filedate{April 15, 1997}
\def\docdate{August 3, 1997}
%
% \title{\textsf{Accents} Package\\
%   version 1.0a}
% \author{Javier Bezos-L\'opez\footnote{E-mail: 
%   \texttt{jbezos@mx3.redestb.es}}}
%
% \date{\docdate}
% 
% \maketitle
%
% \changes{?}{1994/08/14}{First version, part of the eureka package
%  (never distributed)}
% \changes{1.0}{1997/05/01}{Split from eureka.lbr. Adapted to LaTeX2e
%   with a couple of bugs fixed.
%   English (more or less) documentation added}
% 
% \section{Description}
% 
% This package reimplements the accent commands |\hat|, |\check|,
% |\tilde|, etc., to allow multiple accents  with right placement. Also
% adds the accent |\ring| ($\ring x$). So you can write $\hat{\hat{\hat
% h}}$ with  |$\hat{\hat{\hat h}}$|.\footnote{The algorithm of the
% American Mathematical Society, at least in the early versions,
% misplaces the accents over the $h$.} The code is brief but
% slow, although in fast systems, like Intel 486, Motorola 68030 or
% \textsc{RISC}  technology, is hardly felt.
% 
% Also, a new command is defined:
% |\accentset{<acc-symbol>}{<nucl-symbol>}| which builds an accent, as 
% for instance |\accentset{\star}{d}| ($\accentset{\star}{d}$) or
% |\accentset{\diamond}{h}|  ($\accentset{\diamond}{h}$). Accents so
% defined behaves in quite similar way to real accents. Note that 
% |<acc-symbol>| is always in |\scriptscriptmode|; hence, using
% |\accentset| in scripts won't give the desired  result.
% 
% The command |\underaccent{<accent>}{<nucl-symbol>}| puts the accent
% under the symbol, but only  ``real'' accents are allowed. For
% instance, |\underaccent{\hat}{x}| ($\underaccent{\hat}{x}$). 
% |\undertilde| is the equivalent to |\widetilde|.
% 
% Some points are to be noted:
% \begin{itemize}
% \item Slant of letters are automatically taken care of, even
% in |\accentset|.
% \item Placement of scripts after the symbol are right, as for
% instance in |\hat{\hat{\hat f}}_1^1|  ($\hat{\hat {\hat f}}_1^1$)
% \item The package does not provides alternative accents for fonts
% lacking them. If you want an accented  |\mathcal| letter you had to
% write |\hat{\hat{\mathcal{A}}}| ($\hat{\hat{\mathcal{A}}}$).
% \item |\mathbf{\hat{\hat h}}| gets the bold accent;
% |\hat{\hat{\mathbf{h}}}| not.
% \item The reimplemetation of accents presumes standard encodings. (This
% point needs improvement.)
% \end{itemize}
% 
% Two package options are provided:
% \begin{description}
% \item[\texttt{single}] If you are interested only in |\accentset|.
% Accents are not reimplemented.
% \item[\texttt{nonscript}] If you intend to use multiple accents in
% text and display modes only.
% \end{description} Macros are speeded up dramaticaly with both
% options; if your system is slow, I commend using the  options in
% drafts and removing them for the final print.
% 
% \section{Implementation}
% 
% For the moment the code is not described, but I give a few hints:
% \begin{itemize}
% \item The algorithm is (almost) recursive.
% \item Definitions are global so that the values in the last loop will
% be taken. 
% \item Accents are built over an empty box with the width of the
% nucleous. The nucleous is put after, in  order attach the scripts.
% \end{itemize}
%
% \StopEventually{}
%<*driver>

\documentclass{article}
\usepackage{doc,accents}

\advance\textwidth6pc
\advance\oddsidemargin-2pc
\advance\textheight4pc

\typeout{**** Don't waste paper and recycle it ****}

\catcode`|=\active

\begingroup

\catcode`<=\active
\gdef|{\verb|\catcode`<=\active\def<{|\xxsynt}}
\gdef\xxsynt#1>{\textit{#1}|}

\endgroup

\raggedright
\nofiles
\OnlyDescription

\begin{document}
\DocInput{accents.dtx}
\end{document}

%</driver>
%<*package>

\ProvidesPackage{accents}[1997/05/01 Multiaccents support]

\let\cc@palette\mathpalette

\DeclareOption{nonscript}
  {\renewcommand\cc@palette[2]{#1\textstyle{#2}}}

\DeclareOption{single}
  {\renewcommand\cc@accent[1]{\mathaccent#1}}

\newdimen\cc@skew
\newdimen\cc@wd

\newcount\cc@code
\newcount\cc@group
\newcount\cc@skewchar

\newif\ifcc@more

\def\cc@phant#1{\v@true\h@true\finph@nt}% with \box0 from \cc@fetch

\def\cc@setchar{\cc@skewchar\ifnum\mathgroup=\m@ne
    \skewchar\textfont\@ne
  \else\ifnum\skewchar\textfont\mathgroup=\m@ne
    \skewchar\textfont\@ne
  \else\skewchar\textfont\mathgroup\fi\fi
  \advance\cc@skewchar"7100 }

\def\cc@accent#1#2{\begingroup\cc@code=#1
  \let\math@bgroup\@empty\def\math@egroup##1{\cc@setchar##1}%
  \cc@palette\cc@@accent{#2}\cc@nuc\endgroup}

\def\cc@iaccent#1#2{\cc@fetch{#2}%
  \mathaccent#1{\ifcc@more#2\else\cc@phant{#2}%
    \gdef\cc@nuc{#2}\fi\kern\cc@skew}\kern-\cc@skew}%

\def\cc@@accent#1#2{\let\cc@style=#1%
  \cc@fetch{#2}\mathaccent\cc@code{\ifcc@more#2\else\cc@phant{#2}%
    \gdef\cc@nuc{#2}\fi\kern\cc@skew}\kern-\cc@skew
    \kern\cc@wd}%

\def\grave{\cc@accent{"7012}}
\def\acute{\cc@accent{"7013}}
\def\check{\cc@accent{"7014}}
\def\breve{\cc@accent{"7015}}
\def\bar{\cc@accent{"7016}}
\def\ring{\cc@accent{"7017}}
\def\hat{\cc@accent{"705E}}
\def\dot{\cc@accent{"705F}}
\def\tilde{\cc@accent{"707E}}
\def\ddot{\cc@accent{"707F}}
\def\vec{\cc@accent{"017E}}

\def\accentset#1#2{\begingroup\def\@tempa{#1}%
  \let\math@bgroup\@empty\def\math@egroup##1{\cc@setchar##1}%
  \cc@palette\cc@accentset{#2}\cc@nuc\endgroup}

\def\cc@accentset#1#2{\let\cc@style=#1\cc@fetch{#2}%
  \sbox\z@{$\m@th\cc@style\mathgroup\cc@group
    \ifcc@more#2\else\cc@phant{#2}%
    \gdef\cc@nuc{#2}\fi$}%
  \cc@align{\hidewidth\kern\cc@skew
     $\m@th\scriptscriptstyle\mathgroup\cc@group\@tempa$%
     \hidewidth\cr{\box\z@}}\kern\cc@wd}%

\def\cc@iaccentset#1#2{\cc@fetch{#2}%
  \sbox\z@{$\m@th\cc@style\ifcc@more#2\else\cc@phant{#2}%
    \gdef\cc@nuc{#2}\fi$}%
  \cc@align{\hidewidth\kern\cc@skew
     $\m@th\scriptscriptstyle#1$\hidewidth\cr
   {\box\z@}}}%

\def\cc@align#1{\vbox{\baselineskip\z@skip\lineskip.25ex
  \ialign{##\crcr#1\crcr}}}

\def\cc@fetch#1{\cc@group=\the\mathgroup
  \let\cc@accent\@gobble \let\accentset\@gobble
  \sbox\z@{$\m@th\mathgroup\cc@group\cc@setchar
     \cc@style#1{}\mathchar\cc@skewchar$}%
  \sbox\@ne{$\m@th\mathgroup\cc@group\cc@setchar
     \cc@style#1\mathchar\cc@skewchar$}%
  \cc@morefalse\def\cc@accent##1{\global\cc@moretrue}%
  \def\accentset##1{\global\cc@moretrue}%
  \global\cc@skew2\wd\@ne \global\advance\cc@skew-2\wd\z@
  \setbox\z@\hbox{$\m@th\mathgroup\cc@group\cc@style#1$}%
  \global\cc@wd-\wd\z@
  \let\cc@accent\cc@iaccent \let\accentset\cc@iaccentset}

\def\@dddots{{\cc@style.\mkern-1.7mu\textstyle.\mkern-1.7mu.}}
\def\@ddddots{{\cc@style.\mkern-2.1mu.\mkern-2.1mu.\mkern-2.1mu.}}

\def\dddot{\accentset{\@dddots}}
\def\ddddot{\accentset{\@ddddots}}

\def\undertilde#1{\setbox\z@=\hbox{$\m@th#1$}%
  \oalign{$\m@th#1$\crcr\hidewidth
    \vbox to.5ex{\hbox{$\hss\widetilde{\hbox{\vrule depth\z@
      height\z@ width\wd\z@}}\hss$}\vss}\hidewidth}}

\def\underaccent#1{\expandafter\cc@uaccent#1\@@}
\def\cc@uaccent#1#2\@@#3{\oalign{$\m@th#3$\crcr\hidewidth
    \vbox to.2ex{\hbox{$\m@th\mathchar#2$}\vss}\hidewidth}}

\ProcessOptions
\ProcessOptions

%</package>
% \Finale