
\lingmkletter @

%%%%%%%%%
%% \ex, \pex
%%%%%%%%%
\define@key[lingset]{ling}{exhsize}%
   {\edef\ASR@exhsize{#1}}
\newlingkey!{numoffset}
\newlingkey!{letteroffset}
\newlingkey!{exoffset}
\newlingkey!{interpartskip}
\setkeys[lingset]{ling}{numoffset=0pt,letteroffset=1em,exoffset=1em,
   interpartskip=.5em}
\newlingkey{exhsize}
\setkeys[lingset]{ling}{exhsize=\the\hsize}
\define@cmdkeys[lingset]{ling}[ling@]%
   {beforeexskip,afterexskip,pextextadjust}
\setkeys[lingset]{ling}{%
   beforeexskip=1.2em plus .1em,
   afterexskip=1.2em plus .1em,
   pextextadjust=1.7em}
\define@boolkey[lingset]{ling}[ling@]{pexnumbers}{}
\setkeys[lingset]{ling}{pexnumbers=false}
\define@boolkey[lingset]{ling}[ling@]{extextadjust}{}
\define@cmdkeys[lingset]{ling}[ling@]%
   {exsplitvfil,exbeginsplitpenalty,exparpenalty,
   exgoodparpenalty,smalltextnormalBLS,smalltextdoubleBLS,
   exsmallBLS,normaltextnormalBLS,normaltextdoubleBLS,
   exnormalBLS
}
\setkeys[lingset]{ling}{exsplitvfil=0pt plus .3\vsize,
   exbeginsplitpenalty=150,
   exparpenalty=100,
   exgoodparpenalty=-200,
   smalltextnormalBLS=12pt,
   smalltextdoubleBLS=26pt plus 2pt minus 2pt,
   exsmallBLS=12pt plus 1pt minus 1pt,
   normaltextnormalBLS=14pt,
   normaltextdoubleBLS=30pt plus 3pt minus 3pt,
   exnormalBLS=14pt plus 1pt minus 1pt
}
\newcount\exno \exno=0
\def\smallpenaltypar{\endgraf
   \vskip \ling@exsplitvfil
   \expandafter\penalty\ling@exgoodparpenalty
   \vskip-\ling@exsplitvfil}
\def\beginex{\par\penalty50 \prevdepth30pt
   \vskip\ling@beforeexskip
   \vskip\ling@exsplitvfil
      \expandafter\penalty\ling@exbeginsplitpenalty
      \vskip-\ling@exsplitvfil
   \global\advance\exno by 1
   \hsize=\ling@exhsize
   \examplebaselines
   \let\goodpar=\smallpenaltypar
   \interlinepenalty=\ling@exparpenalty
   \parindent=0pt}

\edef\ling@letterwd{.8em}

\define@cmdkeys[lingset]{ling}[ling@]%
   {everyex,flshift,pexvskipA,pexvskipB}
\setkeys[lingset]{ling}%
   {everyex=,flshift=1.4em,pexvskipA=1ex,pexvskipB=1ex}
\def\ex{\@ifnextchar[\ex@A{\def\pst@par{}\ex@B}}
\def\ex@A[#1]#2{\def\pst@par{#1}\ex@B #2}
\def\ex@pre{\bgroup
   \expandafter\Lingsetkeys\expandafter{\pst@par}
   \beginex
   \ling@everyex}
\def\ex@B{\ex@pre
   \setbox0=\hbox{\hskip\ling@numoffset
      (\rm\the\exno)\hskip\ling@exoffset}%
   \leftskip=\wd0
   \leavevmode\llap{\unhbox0}}
\newcount\pexpartcount
\newif\if@fladjust
\newif\if@firsta
\newif\if@topline
\def\pex{%
   \@ifnextchar*%
      {\@fladjusttrue \expandafter \pex@c\@gobble}%
      {\@fladjustfalse \pex@c}%
}
\def\pex@c{\@ifnextchar[\pex@d\pex@f}
\def\pex@d#1[#2]#3{\def\pst@par{#2}\pex@f #3}
\def\pex@f{\ex@pre
   \ifling@pexnumbers \pexpartcount=0 \let\a=\ling@pexnumber
      \else \pexpartcount=96 \let\a=\ling@pexchar \fi
   \setbox0=\hbox{\hskip\ling@numoffset
      (\rm\the\exno)\hskip\ling@letteroffset\hskip\ling@letterwd
         \hskip\ling@exoffset}%
   \leftskip=\wd0
   \leavevmode\llap{\unhbox0}%
   \@firstatrue\@toplinetrue
   \let\savepar=\par \def\par{\@toplinefalse\savepar
      \let\par\savepar}%
   \if@fladjust \hskip-\ling@flshift\fi}
\def\xe{\vskip\ling@afterexskip
   \nointerlineskip\allowbreak \egroup }
\def\ling@pexchar{%
   \if@firsta
         \if@topline \else \vskip\ling@pexvskipA \fi
      \else \vskip\ling@pexvskipB \fi
   \@firstafalse \ling@pexchar@aa
}
\def\ling@pexchar@aa{\advance\pexpartcount by 1\leavevmode
   \llap{\char\the\pexpartcount.\hskip\ling@exoffset}}
\def\ling@pexnumber{\advance\pexpartcount by 1
   \if@firsta \@firstafalse \else
      \par\vskip\ling@interpartskip
      \fi
   \leavevmode
   \llap{\the\pexpartcount.\hskip\ling@exoffset}}
%
% glosses
%
\newskip\glossspaceskip  \glossspaceskip=1.5ex

\def\gloss{\vtop\bgroup \halign\bgroup ##\hfil &&
         \kern\glossspaceskip ##\hfil\cr }
\def\endgloss{\strut\crcr\egroup\egroup\par\prevdepth=.5ex}
%
%% headline, footline, \psteverypage
\def\fulldate{{\the\day} {%
   \ifcase\month \or January\or February\or March\or
   April\or May\or June\or July\or August\or September\or
   October\or November\or December\fi} \the\year
}
\def\HLpageonly{\hfil\ifnum\pageno>1 \the\pageno\fi}
\def\HLpageonlybb{\ifodd\pageno\hfill\fi
      \ifnum\pageno>1 Page \the\pageno\fi \hfil}
\def\HLdateandpage{\ifnum\pageno>1
   \fulldate\hfil \the\pageno \else \hfil\fulldate\fi}
\def\HLfilename{\fulldate\qquad
   \edef\temp{\topmark}\edef\Temp{\botmark}%
   [ {\ifx\temp\Temp\else
      \ifx\temp\@empty\else
         \temp\ / \fi\fi\Temp} ]\hfill Page \the\pageno
}
\define@cmdkeys[lingset]{ling}[ling@]{headline}
\setkeys[lingset]{ling}{headline=\HLfilename}
\newlingkey!{headlinelevel}
\lingsetkeys{headlinelevel=.5truein}
%
\def\bottomnumbers{%
   \ifnum\pageno>1
      {\advance\vsize by3em
       \rput(.5\hsize,-\vsize){\tenrm\the\pageno}}\fi
}
\def\mkheadline{\rput[Bl](0,\ling@headlinelevel)%
   {\hbox to\hsize{\spaceskip=0pt \ling@headline}}}
%% redefine \plainoutput to include PSTricks commands and
%%   marginal notes
\newtoks\psteverypage   % pst commands only
\def\jfoutput{\shipout\vbox{%
   \hbox to0pt{\the\psteverypage\hss}\pagebody}
   \advancepageno
   \ifnum\outputpenalty>-20000 \else\dosupereject\fi}
\let\plainoutput=\jfoutput
\psteverypage={\mkheadline}

\def\dump{\ifling@printnotes \dumpnotes \fi
   \ifling@printrefs \dumprefs \fi}

%%%%%%%%%%%
%% sections
%%%%%%%%%%%

\newcount\secno            \secno=0
\newcount\subsecno
\newcount\subsubsecno
\newcount\subsubsubsecno

\outer\def\section #1\par{%
   \global\advance\secno by 1  \global\subsecno=0
      \global\subsubsecno=0
   \vskip0pt plus.3\vsize\penalty0
   \vskip0pt plus-.3\vsize\bigskip\vskip\parskip
   {\noindent \titlefont{sec}
       \the\secno.\enskip #1}\par\nobreak
   \medskip\noindent}

\outer\def\subsection #1 \par{%
   \global\advance \subsecno by 1 \global\subsubsecno=0
   \vskip0pt plus.1\vsize\penalty0
   \vskip0pt plus-.1\vsize\bigskip\vskip\parskip
   {\noindent \titlefont{sub}
      \the\secno .\the\subsecno. \enskip #1}\par\nobreak
   \medskip\noindent}

\outer\def\subsubsection #1 \par{%
   \global\advance \subsubsecno by 1 \global\subsubsubsecno=0
   \vskip0pt plus.1\vsize\penalty0
   \vskip0pt plus-.1\vsize\bigskip\vskip\parskip
   {\noindent \titlefont{subsub}
      \the\secno .\the\subsecno.\the\subsubsecno \enskip #1}\par\nobreak
   \medskip\nobreak\noindent}

\def\subsubsubsection #1 \par{\advance\subsubsubsecno by 1
   \vskip0pt plus.1\vsize\penalty0
   \vskip0pt plus-.1\vsize\medskip
   \noindent {\it \the\secno.\the\subsecno.\the\subsubsecno
      .\the\subsubsubsecno\enspace #1}:\hskip.5em}

\def\bulletsection #1\par{%
   \vskip0pt plus.1\vsize\penalty0
   \vskip0pt plus-.1\vsize\medskip
   \noindent $\bullet$\enspace
      {\it #1}\par\nobreak\medskip\nobreak\noindent}

%% GATHER - ftags, index, notes, contents,
\newif\ifgatherftags
\gatherftagsfalse
\newwrite\ling@ftagsfile
\def\write@ftags{\write\ling@ftagsfile}
\def\gatherftags{%
   \gatherftagstrue
   \immediate\openout\ling@ftagsfile=G-ftags.tex
}
\newif\ifgatherindex
\gatherindexfalse
\newwrite\ling@indexfile
\def\write@index{\write\ling@indexfile}
\def\gatherindex{%
   \gatherindextrue
   \immediate\openout\ling@indexfile=Gtemp-index
}
\newif\ifgathercontents
\gathercontentsfalse
\newwrite\ling@contentsfile
\def\write@contents{\write\ling@contentsfile}
\def\gathercontents{%
   \gathercontentstrue
   \immediate\openout\ling@contentsfile=G-contents
}
\newif\ifgathernotes
\gathernotesfalse
\newwrite\ling@notesfile
\def\write@notes{\write\ling@notesfile}
\def\gathernotes{%
   \gathernotestrue
   \immediate\openout\ling@notesfile=!notes.tex
}
%%%%%%%%%%
% ----- disclaimer, title, name ------

\def\title{%
   \bgroup
   \leftskip=0pt plus 1fil \rightskip=0pt plus 1fil
   \parindent=0pt \parfillskip=0pt
   \baselineskip=\ifling@doublespace 22\else 13\fi pt
   \titlefont{main}}
\def\author{\vskip.7em
   \baselineskip=\ifling@doublespace 14\else 13\fi pt
   \titlefont{subsub}}
\def\endtitle{\vskip1.6em \egroup}
\def\disclaimer{\leavevmode
   \bgroup \parindent=0pt
   \baselineskip=13pt
   \vskip-.8truein
   \hrule
   \medskip}
\def\enddisclaimer{\medskip\egroup
   \hrule
   \vskip2.5em plus 2em minus .2em}

% ------  footnotes ------

\newcount\fnno
\fnno=0

\def\raisedasterisk{\raise3pt\rlap{\twelverm *}}
\def\ackmark{$\,{}^1$ \global\fnno=1}
\def\putfnno{\hbox{\global\advance\fnno by 1 $^{\the\fnno}$}}

\long\def\acknowledgement#1{\global\advance\fnno by 1
  {\edef\next{\immediate\write\notesfile{\noexpand\note\the\fnno}}\next}%
  \immediate\write\notesfile{#1}%
  \immediate\write\notesfile{}}

%\gdef\endfn{"endfootnote}
%\gdef\putfnno{\global\advance\fnno by 1
%   ${}^{\the\fnno}$}
%\gdef\footsetup{\edef\fntempsf{\the\spacefactor}\putfnno
%   \spacefactor=\fntempsf{} }
%\gdef\footbody{\ifgathernotes\immediate\write\notesfile{}\fi%
%   \edef\n@xt{\noexpand\noexpand\noexpand \note\the\fnno}%
%   \ifgathernotes\immediate\write\notesfile{\n@xt}\fi\fnverbatim}
%\gdef\footnote{\footsetup \footbody}       %"endfootnote
%\gdef\fnverbatim{\begingroup\setupcopyfn\copyfnfirst}
%\gdef\setupcopyfn{\def\do##1{\catcode`##1=12 }\dospecials
%   \obeylines}
%{\obeylines
%\gdef\copyfn#1
%   {\def\n@xt{#1}%
%    \ifx\n@xt\endfn%
%         \ifgathernotes\immediate\write\notesfile{}\fi%
%         \let\n@xt=\endgroup%
%      \else%
%         \ifgathernotes\immediate\write\notesfile{\n@xt}\fi%
%         \let\n@xt=\copyfn \fi%
%         \n@xt}
%\gdef\copyfnfirst#1
%   {\def\n@xt{#1}%
%   \ifx\n@xt\empty%
%   \else\ifgathernotes\immediate\write\notesfile{\n@xt}\fi%
%   \fi \copyfn}}

%% printing notes and references
\def\dumpnotes{\immediate\closeout\notesfile
   \dumpnotesinit
   \def\note ##1 {%
      \smallskip\penalty10\noindent ##1.\quad}%
   \smalltext
   \input !notes.tex}
\def\dumpnotesinit{\vskip30pt
   \vskip.3\vsize\penalty-30\vskip-.3\vsize
   \centerline{Notes}
   \medskip}
\def\dumprefs{\vskip30pt
   \vskip.3\vsize\penalty-30\vskip-.3\vsize
   \smalltext
   \parindent=0pt
   \parskip=0pt plus 1pt
   \rightskip=0pt
   \tolerance=350 \interlinepenalty=400
   \centerline{\normaltext References}
   \bigskip
   \input @@refs.tex }


% -- numbering and reference to numbers

\newcount\exno \exno=0
\newcount\tracinglabels \tracinglabels=0

\def\nextx{{\advance\exno by 1 \number\exno}}
\def\anextx{{\advance\exno by 2 \number\exno}}
\def\lastx{\number\exno}
\def\blastx{{\advance\exno by -1 \number\exno}}
\def\bblastx{{\advance\exno by -2 \number\exno}}

%% TAGS
%  local tags for example numbers
\def\tagex[#1]{%
   \expandafter\xdef\csname TAG#1\endcsname{\the\exno}\ignorespaces}
% f(ar)tags
% input G-ftags.tex, first testing to see that it exists
% it needs definition of \fdef
\newread\ling@ftagsin
\def\fdef#1 #2 {\expandafter\xdef\csname TAG#1\endcsname{#2}}
\immediate\openin\ling@ftagsin=G-ftags.tex
\ifeof\ling@ftagsin \else \closein\ling@ftagsin \input G-ftags \fi
\def\ftagpage[#1]{\ifgatherftags
   \write@ftags{\noexpand\fdef #1 {\the\pageno}}\fi \ignorespaces}
\def\ftag#1[#2]{\ifgatherftags
   \immediate\write@ftags{\noexpand\fdef #2 {#1}}\fi\ignorespaces}
\def\currsec{\ifnum\chapno>0 \the\chapno
   \ifnum\secno>0 .\the\secno
   \ifnum\subsecno>0 .\the\subsecno
   \ifnum\subsubsecno>0 .\the\subsubsecno \fi\fi\fi\fi}
\def\currex{\the\exno}
\def\ftagex[#1]{\ftag\the\exno[#1]}
\def\ftagsec[#1]{\ftag\currsec[#1]}
%  retrieving tags
\def\gettag[#1]{\expandafter\ifx\csname TAG#1\endcsname\relax
   \ifgatherftags \else \write16{****TAG NOT DEFINED**** [#1]}\fi
    $\bullet${\tt #1}\else
    \ifnum\tracinglabels=1
       {\tt !#1}\else \csname TAG#1\endcsname\fi\fi}
%  Use: \gettagrel[Malay:-2]  the Malay number minus 2
%  Caution: the tag retrieved must be numeric
\def\gettagrel[#1:#2]{{\expandafter\ifx\csname TAG#1\endcsname\relax
   \tracinglabels=2 $\bullet$\fi
   \ifnum\tracinglabels=0 \count0=\csname TAG#1\endcsname
      \advance\count0 by #2 \the\count0
   \else \tt {\ifnum\tracinglabels=1 !\fi}#1:#2\fi}}

% -- right arrows ---------------------

\newskip\beforetoskip
\newskip\aftertoskip
\newskip\normaltoskipamount
\normaltoskipamount=1em minus .5em
\def\normaltoskips{\beforetoskip=\normaltoskipamount
   \aftertoskip=\normaltoskipamount}
\normaltoskips
\newdimen\torise
\torise=1ex
\def\to{\ifmmode \rightarrow \else
   \hskip\beforetoskip$\rightarrow$\hskip\aftertoskip \fi}
\def\tooby #1 {\hskip\beforetoskip\hbox{$\buildrel {\rm #1}
   \vrule width0pt depth\torise height0pt
   \over\longrightarrow$}\hskip\aftertoskip}

% -- alignment ---------------

\newskip\Tskip \Tskip=2.4em
\def\Tspace{\hskip\Tskip}
\def\hwit#1{\hidewidth \it #1\hidewidth}

% numbering and lettering in \halign
\let\numbers=\letters
\newcount\lettercharno \lettercharno=1
\newdimen\letterswd \letterswd=2em
\def\omitletter{\omit\hskip\letterswd}
\def\iniletters{\global\lettercharno=96 }
\def\ininumbers{\lettercharno=48}
\newtoks\everyletter \everyletter={}
\def\letters{\global\advance\lettercharno by 1
   \hbox to\letterswd{\rm \the\everyletter\char\the\lettercharno.\hfil}}
\let\numbers=\letters
\def\lettering{\iniletters
   \def\\{\global\advance\lettercharno by 1 \char\the\lettercharno}}
%% the following should be placed on the line before the
%% line in which the letter is set
\def\tagletterA{\xdef\letterA{\char\the\lettercharno}}
\def\tagletterB{\xdef\letterB{\char\the\lettercharno}}
\def\tagletterC{\xdef\letterC{\char\the\lettercharno}}
\def\tagletterD{\xdef\letterD{\char\the\lettercharno}}
\def\tagletterE{\xdef\letterE{\char\the\lettercharno}}
%%%%% \crskip matters
\def\crs{\cr\noalign{\vskip\crskip}}
\newskip\crskip
\newskip\normalcrskipamount  \normalcrskipamount=.6em
\def\normalcrskip{\crskip=\normalcrskipamount}
\normalcrskip
%%%%% utilities
\def\clap#1{\hbox to 0pt{\hss#1\hss}}

\def\ling@doublespacestyle{%
   exhsize=6truein,
   beforeexskip=1.4em plus.1em,
   afterexskip=1.4em plus.1em,
   interpartskip=0pt}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\lingrestore @

\everymath={\rm}



