%\tracingcommands=2
%\tracingmacros=2
\def\iw{\immediate\write16}
\def\MITeX{{\it MIT}\kern-.1667em \lower.5ex\hbox{E}\kern-.125em X}
%
%  This is Andrew Marc Greene's TeX format file.  It sets up a number
%  of useful things:
%
%    Italics are obtained with //italics//
%    Boldface is obtained with **boldface**
%  / Small Caps are obtained with ..Small Caps..
%    Section headers are defined as paragraphs beginning with >
%  * Subsections begin with >>, et cetera.
%  / Three periods (...) are converted to \dots{}
%  / Fonts automatically loaded on demand.
%  * Footnotes entered as [[footnote]].
%  * Verbatim done with "verbatim"
%  / A pleasant error handler.
%    My own backslash parser
%    Ability to parse a prologue like this:
%
%         article
%         title=A New Input Style for \TeX
%         author=Andrew Marc Greene
%         date=4 Oct.~1989
%         begin
%
%
%  In short, the goals are two-fold.  First, we want to make the input
%  as easy to type as possible.  Secondly, we want it as easy to read
%  as possible.  The first means eliminating keystrokes, especially
%  difficult or unusual shifted characters (such as the braces).  The
%  second means as few cryptic control strings as possible.  It is my
%  goal to make it possible to write a simple paper without using a single
%  backslash or brace pair.  (Obviously this is not possible for math
%  papers or other uses for TeXnicalities.)
%
%  Items on the above list that are preceded by an asterisk are not
%  yet coded (/ means unfinished).  If you have an idea that you'd like
%  to see included, please send me email (amgreene@athena.mit.edu); if
%  you write any extensions to this system, please send them to me
%  so I can test them and incorporate them into the definitive
%  distribution.
%
%  Enjoy!
%
\catcode`\@=11
%
% Make // switch into italics:
%
\let\sl@shedonce=/
\let\it@lcorrect=\/
\catcode`\/=13
\def/{\futurelet\nextt@k\sl@sher}
\def\sl@sher{\begingroup\ifx/\nextt@k\aftergroup\sl@shedtwice
\else\sl@shedonce{}\fi\endgroup}
\def\sl@shedtwice/{\begingroup\def\sl@shedtwice/{\endgroup\it@lcorrect}\it}
%
% Make ** switch into bold:
%
\let\st@ronce=*
\catcode`\*=13
\def*{\futurelet\nextt@k\st@rred}
\def\st@rred{\begingroup\ifx*\nextt@k\aftergroup\st@rtwice
\else\st@ronce{}\fi\endgroup}
\def\st@rtwice*{\begingroup\def\st@rtwice*{\endgroup}\bf}
%
% Make .. switch into small-caps:
%
\let\d@tonce=.
%\catcode`\.=13
%\def.{\futurelet\nextt@k\d@tted}
\def\d@tted{\begingroup\ifx.\nextt@k\aftergroup\d@ttwice
\else\d@tonce{}\fi\endgroup}
\def\d@ttwice.{\futurelet\nextt@k\d@tagain}
\def\d@tagain{\begingroup\ifx.\nextt@k\aftergroup\d@tthrice
\else\aftergroup\d@tonlytwice\fi\endgroup}
\def\d@tonlytwice{\begingroup\def\d@tonlytwice{\endgroup}\sc}
\def\d@tthrice.{\dots }
%
% Section headers (not right)
%
%\catcode`\>=13
%\def> #1\par{\par\bigskip\noindent{\big
%\hskip -1.5em\relax #1}\par\nobreak\smallskip\nobreak\noindent}
\everypar{\futurelet\nextt@k\ch@ckpar}
\def\ch@ckpar{\begingroup\ifx>\nextt@k\aftergroup\s@ction\fi\endgroup}
\def\s@ction> #1\par{\par\bigskip\noindent{\bigf@nt
\hskip -1.5em\relax #1}\par\nobreak\smallskip\nobreak\noindent}
%
% Deal with verbatim (needs reworking)
%
\catcode`\"=13
\begingroup
\catcode`\&=12\catcode`\%=12\catcode`\{=12\catcode`\}=12\catcode`\/=12
\catcode`\~=12
\catcode`<=1\catcode`\>=2\catcode`\+=0
+gdef"<+begingroup+tt+catcode`+&=12+catcode`+%=12+catcode`+{=12+catcode`+}=12
\catcode`\~=12
\catcode`\/=12+catcode31=1+catcode`+\=12+relax+verb>
+gdef+verb#1"<#1+endgroup>
+endgroup
%
%  Backslash behavior
%
\def\st@rtcs{\def\w@rd{}%
\catcode32=12\futurelet\nextt@k\startsc@ncs} % catcode is a kludge
%
\def\startsc@ncs{\catcode32=10%
\begingroup\expandafter\ifcat\noexpand\nextt@k A\aftergroup\sc@ncs\else\aftergroup\singlech@rcs\fi\endgroup}
%
\def\singlech@rcs{\begingroup\verbc@tcodes\singlech@rcstwo}
\def\singlech@rcstwo#1{\edef\t@mp{\string #1}\expandafter\aftergroup\csname\t@mp\endcsname\endgroup}
\begingroup\catcode`\#=12
\gdef\verbc@tcodes{\catcode`\\=12\catcode`\$=12\catcode32=12\catcode13=12\catcode`\%=12\catcode`\^=12\catcode`\|=12\catcode`\#=12\catcode`\.=12\catcode`\/=12\catcode`\*=12\catcode`\_=12\catcode`\&=12\catcode`\{=12\catcode`\}=12\catcode`\"=12}
\endgroup
%
\def\sc@ncs{\begingroup%
\ifcat A\nextt@k\aftergroup\@ddtocs\else\aftergroup\sc@ncsend\fi
\endgroup}
%
\def\@ddtocs#1{\edef\w@rd{\w@rd #1}%
\futurelet\nextt@k\sc@ncs}%
%
\def\sc@ncsend{\begingroup
\expandafter\ifx\csname\w@rd\endcsname\relax
\aftergroup\cserr@r\else
\aftergroup\exp@ndcs\fi\endgroup}
%
\def\cserr@r{%
\errh@ndle{MITeX error: Unknown backslash command (\w@rd) encountered.}%
{\iw{MITeX doesn't know the command you gave.}%
\iw{Maybe you misspelled it?}}}
%
\def\exp@ndcs{\csname\w@rd\endcsname}
%
%  Parse file header
%
\def\getw@rd{\def\w@rd{}%
\futurelet\nextt@k\addtow@rd}
%
\def\nl{\relax}
\newtoks\testt@k
\begingroup
\catcode13=13\let^^M=\nl%
\gdef\addtow@rd{%
\begingroup%
\ifx^^M\nextt@k\aftergroup\f@llline\relax%
\else\ifx=\nextt@k\relax\aftergroup\equ@ls\relax%
\else\ifx:\nextt@k\relax\aftergroup\c@lon\relax%
\else\aftergroup\g@bbletow@rd\relax%
\fi\fi\fi\endgroup}%
%
\gdef\equ@ls=#1
{%\iw{equ@ls}%
\expandafter\gdef\csname\w@rd\endcsname{#1}\getw@rd}
%
\gdef\f@llline#1{%\iw{f@llline: \w@rd}%  the #1 swallows the newline
\p@rsedfalse\csname @@\w@rd\endcsname%
\begingroup%
\ifp@rsed\ifpr@logue%
\aftergroup\g@tw@rd
\else\aftergroup\b@gin\fi
\else\aftergroup\c@uldntparse\fi\endgroup}
%
\gdef\g@tw@rd{\futurelet\nextt@k\getw@rd}
%
\gdef\c@lon:{%  for fullines that take parameters
}
%
\gdef\g@bbletow@rd#1{\xdef\w@rd{\w@rd #1}%
%\iw{\w@rd}%
\futurelet\nextt@k\addtow@rd}
%
\endgroup
%
\def\c@uldntparse{%
\errh@ndle{MITeX Error:  Unknown Command (\w@rd) in Prologue}%
{\iw{The prologue contained a command that MITeX doesn't know.}%
\iw{Maybe you misspelled it?}}%
}%
%
%  Error Handler
%
\def\ir{\read-1 to }
\def\errh@ndle#1#2{\iw{}\iw{#1}
\def\errh@lp{#2}
\errwh@tnow}
%
\def\errwh@tnow{\iw{}\message{What now? }
\ir\errr@ply
\expandafter\p@rsereply\errr@ply
}
%
\def\p@rsereply#1#2
{\edef\t@mp{#1}
\expandafter\if\uppercase\t@mp H\errh@lp
\else
\if X\t@mp 
\else
\if C\t@mp
\else
\iw{}
\iw{MITeX has tripped over an error, and is waiting for further instructions.}
\iw{}
\iw{Type H for more help, X to exit, or C to continue.}
\fi\fi\fi
\begingroup
\if X\t@mp\end\else
\if C\t@mp\aftergroup\errc@ntinue\else
\aftergroup\errwh@tnow\fi
\endgroup}
%
\def\errc@ntinue{\iw{Continuing to read your file.}}
%
\newif\ifp@rsed
\newif\ifpr@logue
%
\expandafter\def\csname testfile\endcsname{%
\immediate\write16{This is test file mode.}
\futurelet\nextt@k\getw@rd}
%
{\catcode13=13%
\gdef\@@begin{\catcode13=5\p@rsedtrue\pr@loguefalse}%
%
\gdef\beginparse{\let^^M=\nl%
\pr@loguetrue%
\getw@rd}}
\catcode13=5
%
%  What happens after the prologue?
%
\def\b@gin{%
\expandafter\ifx\csname title\endcsname\relax\else
\centerline{\titlef@nt\title}\medskip\fi
\expandafter\ifx\csname author\endcsname\relax\else
\centerline{\authorf@nt\author}\bigskip\fi
\noindent}
%
%  Font stuff
%
\def\f@ntrm{cmr}
\def\f@ntit{cmti}
\def\f@ntsc{cmcsc}
\def\f@ntsl{cmsl}
\def\f@ntbf{cmbx}   % have i missed any?
%
\newcount\f@ntsizeindex\f@ntsizeindex=0
\def\f@ntsizedef#1#2{
\expandafter\def\csname f@ntsize\the\f@ntsizeindex\endcsname{#1}
\expandafter\def\csname f@ntname\the\f@ntsizeindex\endcsname{#2}
\advance\f@ntsizeindex by 1
}
%
\f@ntsizedef{50}{5}
\f@ntsizedef{60}{6}
\f@ntsizedef{70}{7}
\f@ntsizedef{80}{8}
\f@ntsizedef{90}{9}
\f@ntsizedef{100}{10}
\f@ntsizedef{110}{10 at 10.967pt}
\f@ntsizedef{120}{12}
\f@ntsizedef{144}{10 at 14.4pt}
\f@ntsizedef{170}{17}
%
%  \f@ntselect takes the \f@ntname and proceeds from there
%
\def\f@ntselect#1{% #1 has the name
\def\f@ntname{#1}\scanf@ntsizes\loadf@nt}
%
%  \scanf@ntsizes looks for the best \f@ntindex for \f@ntsize.
%
\def\scanf@ntsizes{\count255=0
\loop
\expandafter\ifnum\csname f@ntsize\the\count255\endcsname<\f@ntsize
\advance\count255 by 1
\repeat
\edef\f@ntindex{\the\count255}}
%
%  \loadf@nt switches to the font given by \f@ntname and \f@ntindex
%
\def\loadf@nt{%
\expandafter\ifx\csname \f@ntname\f@ntindex\endcsname\relax
\expandafter\font\csname \f@ntname\f@ntindex\endcsname=%
\csname f@nt\f@ntname\endcsname
\csname f@ntname\f@ntindex\endcsname\relax\fi
\csname \f@ntname\f@ntindex\endcsname}
%
\def\it{\f@ntselect{it}}
\def\rm{\f@ntselect{rm}}
\def\sc{\f@ntselect{sc}}
\def\bf{\f@ntselect{bf}}
\def\sl{\f@ntselect{sl}}
\def\tt{\f@ntselect{tt}}  % does not suppress hypenation.
%
%  Set the current size:  10pt, 11pt, 12pt
%
\def\tenpoint{\def\f@ntsize{100}\scanf@ntsizes\edef\b@seindex{\f@ntindex}}
\def\elevenpoint{\def\f@ntsize{110}\scanf@ntsizes\edef\b@seindex{\f@ntindex}}
\def\twelvepoint{\def\f@ntsize{120}\scanf@ntsizes\edef\b@seindex{\f@ntindex}}
%
%  Define \large, \Large, etc.
%
\def\genericf@ntsize#1{\count255=\b@seindex\advance\count255 by #1\relax
%\iw{You want \the\count255 out of \the\f@ntsizeindex}
\ifnum\count255<\f@ntsizeindex%\iw{Good}
\edef\f@ntindex{\the\count255}\loadf@nt\fi\ignorespaces}  % ign is a kludge
%
\def\tiniest{\genericf@ntsize{-6}}
\def\tinier{\genericf@ntsize{-5}}
\def\tiny{\genericf@ntsize{-4}}
\def\smallest{\genericf@ntsize{-3}}
\def\smaller{\genericf@ntsize{-2}}
\def\small{\genericf@ntsize{-1}}
\def\normalsize{\genericf@ntsize0}
\def\large{\genericf@ntsize1}
\def\larger{\genericf@ntsize2}
\def\largest{\genericf@ntsize3}
\def\huge{\genericf@ntsize4}
\def\hugest{\genericf@ntsize5}
%
\tenpoint\rm
%
%  Hard-coded fonts (for now)
%
\font\bigf@nt=cmbx12\relax
\font\titlef@nt=cmr17\relax
\font\authorf@nt=cmr12\relax
\tolerance=10000
%
\def\go{\immediate\write16{AMG TeX format 1.0 (4-Oct-89)}
\catcode13=13\beginparse}
%
%  Set up the catcodes for backslash
%
\catcode`\Q=0
Qcatcode`Q\=13
Qlet\=Qst@rtcs
Qcatcode31=0
Qcatcode`QQ=11
%
%  Prepare for real stuff
%
%\everyjob{\go}
\go1=1
%
%\immediate\write16{AMG TeX format 1.0 (4-Oct-89)}
%\catcode13=13\beginparse%
