under accents

• To: math-font-discuss@cogs.susx.ac.uk
• Subject: under accents
• From: Matthias Clasen <mclasen@sun2.mathematik.uni-freiburg.de>
• Date: Fri, 9 May 1997 11:13:57 +0200 (MET DST)


This week I have been trying to figure out a way to get under accents
working in math mode. Justin Zieglers Proposal reserves a few slots for
specially designed under accent glyphs, but since TeX does not offer a
primitive for under accent placement they would still need macros to get
properly placed, so I thought that the macros might as well work with the
normal accent glyphs and do some surgery on them to make under accent
glyphs. The macros need two additional pieces of font information for
their work:

1) The space to put between the accent and the accentee.

This could be stored as a kern pair involving the accent. The macros
below use the kern pair accent-accent for that purpose.

2) The proper skew for the accentee.

This depends on the accentee and so has to be stored in its font. The
macros below use the kern pair skewchar-accentee for that purpose.

I'd like to ask for comments on this idea. Is this a sensible approach to
under accents ? The macros can certainly be improved, e.g. by moving some
calculations out of the \mathchoice.

One restriction of this approach is that it does not treat subscripts and
superscripts in a special way like the TeX primitive \mathaccent does,
simply because I don't know how to implement it.

Another restriction of this approach is that under accents will simply be
centered under glyphs from text fonts unless the extra skewchar kerning
is added to them (is that possible for the EC fonts ?), but I guess this
is just as good as one can do without the additional skewing info.

Matthias

\newdimen\accentsep@
\newdimen\accentht@
\newdimen\accenteeskew@

% #1 is the accent glyph
% #2 is the accentee glyph used for determining the skew
% #3 is what is actually placed over the accent
% (#2 and #3 are separated to allow correct placement of over/underaccents.

\def\placeunderaccent@#1#2#3{\mathchoice
{\@puacc{\displaystyle}{\textfont}{#1}{#2}{#3}}
{\@puacc{\textstyle}{\textfont}{#1}{#2}{#3}}
{\@puacc{\scriptstyle}{\scriptfont}{#1}{#2}{#3}}
{\@puacc{\scriptscriptstyle}{\scriptscriptfont}{#1}{#2}{#3}}}

% This is based on \mathaccent@ from amsmath.sty
\def\@puacc#1#2#3#4#5{%
\ifnum\mathgroup=\m@ne\xdef\thefam@{2}\else\xdef\thefam@{\the\mathgroup}\fi
% determine the space to put between accent and accentee
% and the height of the accent
\setbox\z@\hbox{$\m@th#1#3\hbox{}#3$}%
\setbox\@ne\hbox{$\m@th#1#3#3$}%
% determine the skew
\setbox\z@\hbox{\unbracefonts@$\m@th#1\mathgroup\thefam@\relax \theskewchar@\hbox{}#4$}%
\setbox\@ne\hbox{\unbracefonts@$\m@th#1\mathgroup\thefam@\relax \theskewchar@#4$}%
%
\mathord{\o@lign{$\m@th#1\mathgroup\thefam@\relax#5$%
\crcr\noalign{\nointerlineskip}%
\hidewidth\vbox to\accentht@{%
\vskip\accentsep@\hbox{$\m@th#1#3$}\vss}%
\hskip\accenteeskew@\hidewidth}}}

% This macro creates a variable class token with the
% charcode of the skewchar of the current family.
% It is stolen from amsmath.sty
\newcount\skewcharcount@
\newcount\familycount@
\def\theskewchar@{\familycount@\@ne
\global\skewcharcount@\the\skewchar\textfont\@ne
\ifnum\mathgroup>\m@ne\ifnum\mathgroup<16
\global\familycount@\the\mathgroup\relax
\global\skewcharcount@\the\skewchar\textfont\the\mathgroup\relax\fi\fi
\ifnum\skewcharcount@>\m@ne
\ifnum\skewcharcount@<128
\multiply\familycount@256\relax
\mathchar\skewcharcount@\else
\global\skewcharcount@\m@ne\fi\else
\global\skewcharcount@\m@ne\fi}

% This macro determines the x height of the current family.
\begingroup \catcode\"=12
\gdef\@@@xht#1"#2#3#4"#5{\fontdimen5\the#5#3}%
\gdef\accentxheight@#1#2{\expandafter\@@@xht\meaning#1"#2}
\endgroup

% I dont know what this does.
\def\unbracefonts@{\let\math@bgroup\@empty\let\math@egroup\@empty}

% #1 is the under accent glyph
% #2 is what is to be accented
\def\underaccent#1#2{\placeunderaccent@{#1}{#2}{#2}}

% #1 is the under accent glyph
% #2 should be a \mathaccent
% #3 is what is to be accented
\def\overunderaccent#1#2#3{\placeunderaccent@{#1}{#3}{#2{#3}}}

% these are the usual math accent glyphs, used as mathords.
\DeclareMathSymbol{\hatchar}        {\mathord}{letters}  {2}
\DeclareMathSymbol{\dotchar}        {\mathord}{letters} {10}

\def\underhat#1{\underaccent\hatchar{#1}}
\def\underdot#1{\underaccent\dotchar{#1}}

`