%%%
%%% 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>
%%%

\makeatletter
\let\MYLATEXdocument\document

\def\document{\endgroup
  \let\document\MYLATEXdocument
  \makeatother
  \def\@tempb{****Customised with^^J}%
  \@for\@tempa:=\@filelist\do{%
      \edef\@tempb{\@tempb\@spaces\@tempa^^J}}%
  \everyjob\expandafter{\the\everyjob\typeout{\@tempb}}%
  \catcode`\\=13\relax%
  \catcode`\#=12\relax%
  \dump}%

\def\document{\endgroup
  \let\document\MYLATEXdocument
  \makeatother
  \everyjob\expandafter{\the\everyjob
     \begingroup
      \def\AtEndDocument##1{\MYLATEXcustomised##1}%
      \MYLATEXlistfiles
      \endgroup}%
  \@addtofilelist{.}%
  \catcode`\\=13\relax%
  \catcode`\#=12\relax%
  \dump}%

\let\MYLATEXlistfiles\listfiles

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

\def\MYLATEXcustomised#1#2#3\typeout#4{%
  \typeout{Format customised with:^^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%

