%%%
%%% mylatex.ltx
%%%
%%% Use this file to make a format based on the preamble of the
%%% LaTeX file abc.tex
%%%
%%% Use initex as follows:
%%%
%%% initex &latex  mylatex.ltx abc      (Generic TeX)
%%% initex \&latex mylatex.ltx abc      (unix and other TeX's)
%%% tex /i &latex  mylatex.ltx abc      (emtex)
%%%
%%% This should make a format file mylatex.fmt which you can then use
%%% as follows
%%%
%%% tex  &mylatex abc          (generic TeX)
%%% virtex \&mylatex abc       (Unix TeX)
%%%
%%% This will process your document, abc.tex, just as LaTeX does, but
%%% quicker as the contents of the preamble will be stored in the
%%% format file and will not need to be run each time.
%%%
%%% If (vir)tex fails to find your mylatex.fmt then it is not searching
%%% in the current directory, either modify your TEXFORMATS (or equivalent)
%%% path to search `.' or (on unix/dos) use   ./  as in:
%%% virtex \&./mylatex abc
%%%
%%%
%%% The file abc.tex must contain a line *just* with
%%% \begin{document}
%%% (In particular no comments on that line.)
%%% Everything up to (but not including) the \begin{document} will
%%% be saved in the format and not executed in subsequent runs.
%%%
%%% David Carlisle
%%%        1994/09/27
%%%
%%%  Modified 1994/10/21 after comments by
%%%  Volker Kunert <volker@numsun1.mathematik.uni-halle.de>
%%%  Modified 1996/01/26 To fix printout of preloaded files (which
%%%  hasnt worked since December 94 release, and to fix
%%%  incompatibility with \makeindex command.
%%%

\makeatletter
\let\MYLATEXdocument\document


\def\document{\endgroup
  \let\document\MYLATEXdocument
  \makeatother
  \everyjob\expandafter{\the\everyjob
     \begingroup
      \listfiles
      \expandafter\MYLATEXcustomised\@dofilelist
      \endgroup}%
  \@addtofilelist{.}%
  \catcode`\\=13\relax%
  \catcode`\#=12\relax%
  \ifx\@indexfile\@undefined\else
    \AtBeginDocument{%
      \newwrite\@indexfile
      \immediate\openout\@indexfile=\jobname.idx }%
  \fi
  \dump}%


\def\MYLATEXbegin{\begin{document}}%

\def\MYLATEXcustomised#1#2#3\typeout#4{%
  \typeout{CUSTOMISED FORMAT. Preloaded files:^^J%
  \@spaces\@spaces.}#3}

{\catcode`\^^M=\active%
  \catcode`\/=0 %
  /catcode`\\=13 %
  /gdef\{/catcode`/\=0 /catcode`/^^M=13 ^^M}%
  /long/gdef^^M#1^^M{%
    /def/MYLATEXline{#1}%
    /ifx/MYLATEXline/MYLATEXbegin%
     /catcode`/^^M=5/relax%
  /catcode`/#=6/relax%
     /expandafter/MYLATEXline/else/expandafter^^M/fi}}%

\expandafter\input\endinput%

