1 (defvar imaxima-mylatex
6 %%% Use this file to make a format based on the preamble of any LaTeX
9 %%% There are no restrictions on the distribution or modification of
10 %%% this file, except that other people should not attempt to alter
11 %%% the master copy on the ctan archives.
16 %%% Given a LaTeX file `abc.tex', use initex as follows:
18 %%% initex &latex mylatex.ltx abc (Generic TeX)
19 %%% initex \\&latex mylatex.ltx abc (unix and other TeX's)
20 %%% tex /i &latex mylatex.ltx abc (emtex)
22 %%% If you are on a Mac or using some shell that makes it inconvenient
23 %%% to use a command line such as the above examples then you may
24 %%% make a file `mylatex.tex' with the single line
25 %%% \\input mylatex.ltx abc
26 %%% and then pass the file mylatex.tex to your (ini)tex shell to produce
27 %%% the format, ie something equivalent to initex &latex mylatex.tex.
29 %%% If you are using OzTeX, see the separate instructions below.
31 %%% This should make a format file mylatex.fmt which you can then use
34 %%% Using the new format
35 %%%%%%%%%%%%%%%%%%%%%%%%
37 %%% tex &mylatex abc (generic TeX)
38 %%% virtex \\&mylatex abc (Unix TeX)
40 %%% This will process your document, abc.tex, just as LaTeX does, but
41 %%% quicker as the contents of the preamble will be stored in the
42 %%% format file and will not need to be run each time.
44 %%% If (vir)tex fails to find your mylatex.fmt then it is not searching
45 %%% in the current directory, either modify your TEXFORMATS path (or
46 %%% equivalent) to search `.' or (on unix/dos) use ./ as in:
47 %%% virtex \\&./mylatex abc
49 %%% Making and using the format with OzTeX
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 %%% Given a LaTeX file `abc.tex', do this: select `TeX...' from OzTeX's
53 %%% TeX menu, and go to the folder containing the file `abc.tex' as if you
54 %%% were selecting the file `abc.tex'. Then hit the Cancel button - this
55 %%% procedure sets OzTeX's working folder to the one containing abc.tex.
56 %%% Next, select iniTeX from the TeX menu, and type:
58 %%% &latex mylatex.ltx abc
60 %%% This should make a format file mylatex.fmt which you can save in the
61 %%% same folder as the file you're working on.
63 %%% To use the new format, put this at the very start of the very first
64 %%% line of your document:
71 %%% The file abc.tex must contain a line *just* with
73 %%% Everything up to (but not including) the \\begin{document} will
74 %%% be saved in the format and not executed in subsequent runs.
76 %%% If you are modifying the document (or working on a similar document)
77 %%% you may wish to add new commands to your document preamble.
78 %%% The `mylatex' format normally skips the whole preamble (believing
79 %%% it to be pre-loaded) and so such new commands do not take effect.
80 %%% You could re-make the format, preloading the new preamble, but that
81 %%% might be inconvenient to do every time, and so an alternative scheme
82 %%% has been introduced.
83 %%% If the preamble contains a comment mylatex (ie a line just
84 %%% containing a % white space and the word mylatex) then the mylatex
85 %%% format will start reading the preable at that point so any new
86 %%% commands can be placed after such a comment and they will be
89 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93 %%% Modified 1994/10/21 after comments by
94 %%% Volker Kunert <volker@numsun1.mathematik.uni-halle.de>
95 %%% Modified 1996/01/26 To fix printout of preloaded files (which
96 %%% hasnt worked since December 94 release, and to fix
97 %%% incompatibility with \\makeindex command.
98 %%% Modified 1997/10/04 To generalise the \\makeindex support to work
99 %%% with any (well most:-) \\openout uses in the preamble.
100 %%% Modified 1997/10/09 Most? Ross Moore pointed out I just broke
101 %%% changebar, so further tinkering. Also useful discussions
102 %%% with Ross lead to the following changes.
103 %%% Added `mylatex' comment feature.
104 %%% Added some font preloading.
105 %%% Modified 1998/01/21 Jean-Francois Mertens pointed out that comments
106 %%% before the first TeX command were broken by the previous
107 %%% version. In particular %&mylatex special comments which
108 %%% would be picked up by some TeX versions to automatically
109 %%% select the format.
110 %%% Modified 1998/10/14 Rowland McDonnell added notes on how to use
111 %%% mylatex.ltx with OzTeX
112 %%% Modified 1999/01/04 Rowland McDonnell corrected notes on how to
113 %%% use mylatex.ltx with OzTeX.
114 %%% Modified 2020/10/23 Phelype Oleinik updated to work with new hook code
115 %%% in \\begin{document}
116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120 % Save the original definitions.
121 \\let\\MYLATEXdocument\\document
122 \\let\\MYLATEXopenout\\openout
125 \\ifx\\@execute@begin@hook\\@undefined
126 \\message{Begin hook undefined}
128 \\message{Begin hook defined}
129 \\let\\MYLATEX@execute@begin@hook\\@execute@begin@hook
130 \\def\\@execute@begin@hook#1{}%
133 % The version of \\document to use on the initex run.
134 % Just preloads some fonts, puts back \\document and \\openout,
135 % sets up the banner to display the file list of files preloaded,
136 % then sets up some special catcodes so the preamble will be
137 % skipped on normal runs with the new format.
138 \\def\\document{\\endgroup
139 % Force some font preloading.
140 {\\setbox\\z@\\hbox{%
141 $$% math (not bold, some setups don't have \\boldmath)
143 {\\ifx\\large\\@undefined\\else\\large\\fi % large and footnote
144 \\ifx\\footnotesize\\@undefined\\else\\footnotesize\\fi}%
145 {\\bfseries\\itshape}% bold and bold italic
147 \\ttfamily% monospace
148 \\sffamily% sans serif
150 \\let\\document\\MYLATEXdocument
151 \\let\\openout\\MYLATEXopenout
152 \\let\\@execute@begin@hook\\MYLATEX@execute@begin@hook
154 \\everyjob\\expandafter{\\the\\everyjob
157 \\expandafter\\MYLATEXcustomised\\@dofilelist
160 \\catcode`\\\\=13\\relax%
161 \\catcode`\\#=12\\relax%
162 \\catcode`\\ =9\\relax%
166 % In principle \\openout stream= filename need not be space terminated,
167 % and need not be immediate, but this covers \\makeindex \\makeglossary
168 % and index package's \\newindex which are all the cases of \\openout
169 % that occur before \\begin{document} that I could see.
170 % Thanks to Ross Moore for pointing out \\AtBeginDocument is too late
171 % eg changebar package *closes* the stream in \\AtBeginDocument, so need
172 % to make sure it is opened before that. Make a special purpose hook.
175 \\g@addto@macro\\MYLATEXopens{\\immediate\\openout#1 }}
176 \\let\\MYLATEXopens\\@empty
178 % Templates for ending the `preamble skipping process'.
179 \\def\\MYLATEXbegin{\\begin{document}}
180 \\def\\MYLATEXcomment{mylatex}
182 % Banner for \\everyjob.
183 \\def\\MYLATEXcustomised#1#2#3\\typeout#4{%
184 \\typeout{CUSTOMISED FORMAT. Preloaded files:^^J%
185 \\@spaces\\@spaces.}#3}
187 % While the preamble is being skipped, the EOL is active
188 % and defined to grab each line and inspect it looking
189 % for \\begin{document} or mylatex lines.
190 % The special catcodes required are not enabled until after the
191 % first TeX command in the file, so as to avoid problems with
192 % the special processing that TeX does on the first line, choosing
193 % the format, or the file name etc.
194 {\\catcode`\\^^M=\\active%
197 /gdef\\{/catcode`/\\=0 /catcode`/^^M=13 /catcode`/%=9 ^^M}%
199 /def/MYLATEXline{#1}%
200 % If hit a comment `mylatex' then do as if you'd hit \\begin{document}
201 % except don't run the real \\document as a \\begin{document} will be
202 % coming up later in the file at the end of the preamble.
203 /ifx/MYLATEXline/MYLATEXcomment%
204 /let/MYLATEXbegin/relax%
205 /let/MYLATEXline/relax%
207 % If hit \\begin{document} put things back as they should be, run the
208 % hook with any save \\openouts then do the original \\document code.
209 /ifx/MYLATEXline/MYLATEXbegin%
210 /catcode`/^^M=5/relax%
213 /catcode`/%=14/relax%
214 /catcode`/ =10/relax%
215 /expandafter/MYLATEXopens/expandafter/MYLATEXbegin%
217 % Otherwise grab the next line to look at.
221 % Trick lookahead to allow mylatex.ltx and the document filename to be
222 % given on the same command line. (initex &latex mylatex.ltx abc.tex)
223 \\expandafter\\input\\endinput%
226 "Used by `imaxima-dump-tex'. If set to nil, then imaxima will assume that mylatex.ltx is installed on your system; otherwise, it creates mylatex.ltx from this source.
228 Source: David Carlisle's mylatex.ltx
229 https://github.com/davidcarlisle/dpctex/tree/master/mylatex" )
231 (provide 'mylatex.ltx
)