summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/mylatexformat/mylatexformat.ltx
blob: cb5a76ae676a2b1b484f2acb0ef9c91f6eb4898c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
%%
%% This is file `mylatexformat.ltx',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% mylatexformat.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% mylatexformat : 2011/02/12 v3.4 - Use mylatexformat.ltx to make a format based on the preamble of any LaTeX file
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3 of this license or (at your option) any later
%% version. The latest version of this license is in
%%    http://www.latex-project.org/lppl.txt
%% 
%% This work consists of the main source file mylatexformat.dtx
%% and the derived files
%%    mylatexformat.ltx, mylatexformat.pdf, mylatexformat.ins
%% 
%% mylatexformat - Use mylatexformat.ltx to make a format based on the preamble of any LaTeX file
%% Copyright (C) 2010-2011 by Florent Chervet <florent.chervet@free.fr>
%% 
%%% _____________________________________________________________________
%%%                           mylatexformat.ltx
%%%                           ^^^^^^^^^^^^^^^^^
%%% From an original idea by David Carlisle - mylatex.ltx 1994/09/27
%%% ^^a9 lppl 2010-2011 - F Chervet - 2011/02/12 v3.4
%%% _____________________________________________________________________
%%%
%%% Use this file to make a format based on the preamble of any LaTeX
%%% file.
%%%
%%% The format is made from the very beginning of the file up to either:
%%%   i) the command : \endofdump
%%%                    placed in the preamble
%%%  ii) the command : \csname endofdump\endcsname
%%%                    placed in the preamble
%%% iii) \begin{document}
%%%                    if \endofdump nor \csname endofdump\endcsname
%%%                    haven't been found in the preamble.
%%%
%%% A format helps to speed up compilations, packages which have been
%%% dumped in the format are loaded at very high speed.
%%% --------------------------------------------------------------------
%%% There are no restrictions on the distribution or modification of
%%% this file, except that other people should not attempt to alter
%%% the master copy on the ctan archives.
%%%
%%% Making the format --------------------------------------------------
%%% ^^^^^^^^^^^^^^^^^                                       USING MikTeX
%%% *  With preloaded pdflatex format (pdf output) :
%%%    etex -initialize [opts] "&pdflatex" mylatexformat.ltx """abc.tex"""
%%%    => compile your document using :
%%%            pdflatex
%%%         or texify --tex-option=-output-format=pdf
%%%
%%% *  With preloaded latex format (dvi output) :
%%%    etex -initialize [opts] "&latex" mylatexformat.ltx """abc.tex"""
%%%    => compile your document using
%%%            latex
%%%         or texify --tex-option=-output-format=dvi
%%%
%%% * With preloaded format xelatex (pdf output) :
%%%    xetex -initialize [opts] "&xelatex" mylatexformat.ltx """abc.tex"""
%%%    => compile your document using xelatex
%%%
%%% NOTA BENE:    Please, notice the 3 quotes !
%%% ^^^^^^^^^^
%%%
%%% In fact, 3 quotes are necessary only if you "file name.tex" contains a space !
%%%
%%% -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
%%% Exemple of a command line for making format using pdfTeX :
%%%
%%%   etex -initialize -interaction=nonstopmode
%%%                    -save-size=20000 -stack-size=20000
%%%                    -jobname="Mon Beau Format Perso"
%%%                    "&pdflatex" mylatexformat.ltx "Mon Fichier TeX.tex"
%%%
%%%   "Mon Beau Format Perso.fmt" (en Fran^^e7ais dans le texte) will be created
%%%   (or overwritten) in the current working directory.
%%%
%%% Using the format ---------------------------------------------------
%%% ^^^^^^^^^^^^^^^^^                                       USING MikTeX
%%% Add the format to the very first line of your LaTeX file :
%%% --> first line :       %&"format file name"
%%% without the .fmt extension.
%%% [You may use the option :    -dont-parse-first-line option
%%%  to avoid loading the format]
%%% --------------------------------------------------------------------
%% ____________________________________________________________________
%% The following informations come from mylatex.ltx from David Carlisle:
%% Given a LaTeX file `abc.tex', use initex as follows:
%%
%% initex &latex  mylatexformat.ltx abc      (Generic TeX)
%% initex \&latex mylatexformat.ltx abc      (unix and other TeX's)
%% tex /i &latex  mylatexformat.ltx abc      (emtex)
%%
%% If you are on a Mac or using some shell that makes it inconvenient
%% to use a command line such as the above examples then you may
%% make a file `mylatex.tex' with the single line
%% \input mylatex.ltx abc
%% and then pass the file mylatex.tex to your (ini)tex shell to produce
%% the format, ie something equivalent to initex &latex mylatex.tex.
%%
%% If you are using OzTeX, see the separate instructions below.
%%
%% This should make a format file mylatex.fmt which you can then use
%% as follows
%%
%% Using the new format
%% ^^^^^^^^^^^^^^^^^^^^
%%
%% 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 path (or
%% equivalent) to search `.' or (on unix/dos) use   ./  as in:
%% virtex \&./mylatex abc
%%
%% Making and using the format with OzTeX
%% ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
%%
%% Given a LaTeX file `abc.tex', do this: select `TeX...' from OzTeX's
%% TeX menu, and go to the folder containing the file `abc.tex' as if you
%% were selecting the file `abc.tex'. Then hit the Cancel button - this
%% procedure sets OzTeX's working folder to the one containing abc.tex.
%% Next, select iniTeX from the TeX menu, and type:
%%
%% &latex mylatex.ltx abc
%%
%% This should make a format file mylatex.fmt which you can save in the
%% same folder as the file you're working on.
%%
%% To use the new format, put this at the very start of the very first
%% line of your document:
%%
%% %&mylatex
%%
%% Further Notes
%%
%% The file abc.tex must contain a line *just* with
%% \begin{document}
%% Everything up to (but not including) the \begin{document} will
%% be saved in the format and not executed in subsequent runs.
%%
%% If you are modifying the document (or working on a similar document)
%% you may wish to add new commands to your document preamble.
%% The `mylatex' format normally skips the whole preamble (believing
%% it to be pre-loaded) and so such new commands do not take effect.
%% You could re-make the format, preloading the new preamble, but that
%% might be inconvenient to do every time, and so an alternative scheme
%% has been introduced.
%% If the preamble contains a comment   mylatex  (ie a line just
%% containing a % white space and the word mylatex) then the mylatex
%% format will start reading the preable at that point so any new
%% commands can be placed after such a comment and they will be
%% executed.
%% --------------------------------------------------------------------
%%
%%\RequirePackage{etex}% RequirePackage may be used before the class
%%
%% In principle \openout stream= filename need not be space terminated,
%% and need not be immediate, but this covers \makeindex \makeglossary
%% and index package's \newindex which are all the cases of \openout
%% that occur before \begin{document} that I could see.
%% Thanks to Ross Moore for pointing out \AtBeginDocument is too late
%% eg changebar package *closes* the stream in \AtBeginDocument, so need
%% to make sure it is opened before that. Make a special purpose hook.
\makeatletter
%% \begin is overloaded in order to stop \dump at begin document
%% if the macro \endofdump is not given somewhere in the preamble.
%% Rem: it is NOT POSSIBLE to redefine \document, for the macro
%%      \document is changed or patched by some classes or packages
%%      (auxhook, etoolbox etc.)
\begingroup \def\x #1{\endgroup
   \gdef\begin ##1{\MYLATEX@StopAtdocument{##1}#1}
}\expandafter\x\expandafter{\begin{#1}}
\def\MYLATEX@StopAtdocument #1{\expandafter
   \ifx\csname #1\endcsname\document \expandafter\endofdump \fi
}% \MYLATEX@StopAtdocument
\let\MYLATEX@openout \openout
\def\openout#1 {\g@addto@macro\MYLATEX@opens{\immediate\openout#1 }}
\def\MYLATEX@opens {\let\MYLATEX@opens \@undefined}
\def\MYLATEX@cleanup {\let\MYLATEX@cleanup \@undefined
   \def\MYLATEX@StopAtdocument ##1\MYLATEX@StopAtdocument ##2##3\@nil{%
      \gdef\begin ####1{##1##3}%
   }\expandafter\MYLATEX@StopAtdocument \begin{##1}\@nil
   \let\openout                \MYLATEX@openout
   \let\MYLATEX@openout        \@undefined
   \let\MYLATEX@StopAtdocument \@undefined
}% \MYLATEX@cleanup
\def\MYLATEX@fontpreloading{\let\MYLATEX@fontpreloading \@undefined
   \begingroup \setbox0=\hbox {%
      $$% math (not bold, some setups don't have \boldmath)
      \def\x {\bfseries\itshape}{\itshape}\ttfamily\sffamily
      \normalfont \x
      \ifdefined\large \large \x \fi
      \ifdefined\Large \Large \x \fi
      \ifdefined\LARGE \LARGE \x \fi
      \ifdefined\Huge  \Huge  \x \fi
      \ifdefined\small \small \x \fi
      \ifdefined\footnotesize \footnotesize \x \fi
      \ifdefined\tiny  \tiny \x \fi}%
      \@for\x:={lae,lfe,lgr,ot1,ot1tt,ot6,t1,t2a,t2b,t2c,t5}\do{%
         \ifcsname cmap@set@\x\endcsname  \global\expandafter
               \let\csname cmap@set@\x\endcsname \@undefined   \fi
         \uppercase\expandafter{\expandafter\def\expandafter\x\expandafter{\x}}%
         \ifcsname cmap@set@\x\endcsname  \global\expandafter
               \let\csname cmap@set@\x\endcsname \@undefined   \fi}%
   \endgroup
}% \MYLATEX@fontpreloading
\let\MYLATEX@listfiles \listfiles
\def\endofdump{\let\endofdump \relax
   \MYLATEX@cleanup
   \MYLATEX@fontpreloading
   \makeatother
   \everyjob\expandafter{\the\everyjob
      \let\MYLATEX@temp \listfiles
      {%
         \MYLATEX@listfiles
         \global\let\MYLATEX@listfiles \@undefined
         \expandafter\MYLATEX@banner \@dofilelist
      }%
      \let\listfiles \MYLATEX@temp     % to be able to used \listfiles once after the format
      \let\MYLATEX@temp \@undefined
      \MYLATEX@scanpreamble}%
   \dump
}% \endofdump
%% Banner for \everyjob.
{\@makeother\"  % just in case
\xdef\MYLATEX@banner #1#2#3\typeout #4{%
   \global\let\noexpand\MYLATEX@banner \noexpand\@undefined
   \newlinechar`\noexpand\^^J\message{%
   ==============================================================================^^J%
   JOB NAME\@spaces\@spaces\space: "\noexpand\jobname"^^J%
   CUSTOMISED FORMAT: "\jobname"^^J%
   PRELOADED FILES:^^J}%
   #3%
   \message{%
   ==============================================================================}%
}% \MYLATEX@banner
\long\gdef\MYLATEX@start #1#2{\global\let\MYLATEX@start \@undefined
   \message{%
   (mylatexformat)Info: start reading document "\jobname"^^J%
   (mylatexformat)\@spaces\space\on@line.
            (\ifcase#1 \string\endofdump\else\string\begin{document}\fi)^^J%
   ==============================================================================}%
   \endgroup
   \MYLATEX@opens\relax #2%
}% \MYLATEX@start
}% \catcode group

%% While the preamble is being skipped (inside a group)
%% the EOL is active and defined to grab each line and
%% inspect it looking for :
%%        \endofdump
%% or     \csname endofdump\endcsname
%% or     \begin{document}.
%%
%% The special catcodes required are not enabled until after the
%% first TeX command in the file, so as to avoid problems with
%% the special processing that TeX does on the first line, choosing
%% the format, or the file name etc.
{% catcode group
\catcode`\^^M=13 \catcode`\&  =8 %
\long\gdef\MYLATEX@scanpreamble {%
 \begingroup \catcode`\^^M=13%
 \long\def\MYLATEX@endofdump ##1\endofdump##2##3&##4##5##6\MYLATEX {##5}%
 \long\def\MYLATEX@csendofdump ##1\csname endofdump\endcsname##2##3&##4##5##6\MYLATEX {##5}%
 \long\def\MYLATEX@document ##1document##2##3&##4##5##6\MYLATEX {##5}%
 \long\def\MYLATEX@begindocument ##1\begin##2##3\MYLATEX##4{%
    \MYLATEX@document ##2document&&{\MYLATEX@start1{##4}}{^^M}\MYLATEX}%
 \long\def^^M##1^^M{%
    \MYLATEX@endofdump##1\endofdump&&%
       {\MYLATEX@start 0{##1}}%
       {\MYLATEX@csendofdump ##1\csname endofdump\endcsname&&%
          {\MYLATEX@start 0{##1}}%
          {\MYLATEX@begindocument ##1\begin\relax\MYLATEX{##1}}%
          \MYLATEX}%
       \MYLATEX}%
 ^^M%
}% \MYLATEX@scanpreamble
}% catcode group
%% Trick lookahead to allow mylatex.ltx and the document filename to be
%% given on the same command line. (initex &latex mylatex.ltx {abc.tex})
\expandafter\input\endinput%
\endinput
%%
%% End of file `mylatexformat.ltx'.