% sections
\lingmkletter @
\outer\def\section #1\par{%
   \global\advance\secno by 1  \global\subsecno=0
      \global\subsubsecno=0
   \vskip0pt plus.4\vsize\penalty-20
   \vskip0pt plus-.4\vsize\bigskip\vskip\parskip
   {\noindent \titlefont{sec}
       \the\secno.\enskip #1\par}\nobreak
   \ifgathercontents \edef\temp{{\the\secno}}%
      \expandafter\writecontents\temp{#1}\sec\fi \nobreak
   \medskip\nobreak\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
   \ifgathercontents \edef\temp{{\the\secno.\the\subsecno}}%
      \expandafter\writecontents\temp{#1}\subsec\fi \nobreak
   \medskip\nobreak\noindent
}
\def\writecontents#1#2#3{%
   \write@contents{\noexpand#3{#1} {#2}
         \noexpand\writefill \the\pageno \noexpand\par}%
}
\def\writefill{%
   \leaders\hbox to 2ex{\hfil.\hfil}\hfill\enspace
}
\outer\def\appendix#1#2\par{%
   \vskip0pt plus.4\vsize\penalty-20
   \vskip0pt plus-.4\vsize\bigskip\vskip\parskip
   \def\app@name{#1}\subsecno=0%
   {\noindent \titlefont{sec}
      Appendix #1.\enspace
         \ignorespaces#2\par}\nobreak
   \ifgathercontents \edef\temp{{#1}}%
      \expandafter\writecontents\temp{#2}\sec\fi
   \medskip\nobreak\noindent
}
\def\subappendix#1\par{%
   \medskip
   \noindent
   \advance\subsecno by 1
   {\titlefont{sub}\app@name.\the\subsecno.\enspace
      \ignorespaces#1\medskip\noindent}%
   \ifgathercontents \edef\temp{{\app@name.\the\subsecno}}%
      \expandafter\writecontents\temp{#1}\subsec\fi \nobreak
}
\lingrestore @
