Debian Codegraph @

texmf-dist/doc/latex/frankenstein/unsupported/includex.sty

raw
1 %^^A* legal notices
2 % \iffalse
3 %
4 % This file is part of the Frankenstein bundle, comprising the
5 % files listed in the file Manifest.txt. You should have
6 % received the complete bundle when you received this file.
7 %
8 % Copyright 1995-2001 Matt Swift <[email protected]>.
9 %
10 % This file contains both the code and documentation for the
11 % includex LaTeX package. It will work ONLY if it is placed in
12 % a proper directory. Files called README, INSTALL,
13 % includex.tex includex.ins, and includex.dvi
14 % should have also been distributed to you with this file. See
15 % README for more information on how to generate a version of
16 % this file that will work faster than this one.
17 %
18 % This program is free software; you may redistribute it and/or
19 % modify it under the conditions of the LaTeX Project Public
20 % License, either version 1.2 or (at your option) any later version.
21 % The latest version of this license is in
22 % http://www.latex-project.org/lppl.txt, and version 1.2 or later is
23 % part of all distributions of LaTeX version 1999/12/01 or later.
24 %
25 % This program is distributed in the hope that it will be useful,
26 % but without any warranty; without even the implied warranty of
27 % merchantability or fitness for a particular purpose. See the
28 % LaTeX Project Public License for more details.
29 %
30 % \fi
31 %
32 %^^A* checks
33 %
34 %^^A NOTE: The character table, with two %'s, will get written to all files.
35 %% \CharacterTable
36 %% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
37 %% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
38 %% Digits \0\1\2\3\4\5\6\7\8\9
39 %% Exclamation \! Double quote \" Hash (number) \#
40 %% Dollar \$ Percent \% Ampersand \&
41 %% Acute accent \' Left paren \( Right paren \)
42 %% Asterisk \* Plus \+ Comma \,
43 %% Minus \- Point \. Solidus \/
44 %% Colon \: Semicolon \; Less than \<
45 %% Equals \= Greater than \> Question mark \?
46 %% Commercial at \@ Left bracket \[ Backslash \\
47 %% Right bracket \] Circumflex \^ Underscore \_
48 %% Grave accent \` Left brace \{ Vertical bar \|
49 %% Right brace \} Tilde \~}
50 %
51 % \CheckSum{227}
52 %
53 % \begin{abstract}
54 % Includex allows you to include just the contents of one source file into
55 % another, ignoring the text outside the
56 % \code{\begin{document}}\lips\code{\end{document}} in the included file.
57 %
58 % This package is useful but may have problems and is unsupported.
59 %
60 % See also the \package{newclude} package.
61 % \end{abstract}
62 % \tableofcontents
63 %
64 % \part{Discussion}
65 % \section{Including Files}
66 %
67 % \DescribeMacro{\include*}
68 % \cs\include was always pretty useless to me because it did a \cs\clearpage
69 % before and after the \cs\input. The macro |\include*| is defined below to be
70 % like \cs\include but without the \cs\clearpage s.
71 %
72 % The other thing we do is define a command \cs\includedoc, which includes a
73 % file which is allowed to have its own \cs\documentclass and |\begin{document}|
74 % and |\end{document}| and \cs\usepackage commands.
75 %
76 % This opens up a whole new world of truly modular \LaTeX{} files. There is
77 % even nothing special about extracting the |document| environment, we can
78 % extract \emph{any} environment, or perhaps even other things.
79 %
80 % There are some problems, however. Maybe the \cs\usepackage is necessary,
81 % maybe it would conflict. Same with other commands like the \cs\newcommand
82 % family. It is simply not (yet) an issue in \LaTeX{} design to consider the
83 % implications of parent files. The problems are not insurmountable. We can
84 % begin by working with a convention, and ultimately maybe make some changes in
85 % certain macros. I will be getting to all this. I admit I have not looked
86 % carefully to see whether the design specifications of \LaTeX3{} address these
87 % important issues.
88 %
89 % The macros here will be useful in many circumstances, when the included files
90 % are themselves simple.
91 %
92 % \DescribeMacro{\includedoc}
93 % \DescribeMacro{\includedoc*}
94 % \DescribeMacro{\includedocskip}
95 % \DescribeMacro{\includedocskip*}
96 % There are now two main commands, \cs\includedoc and \cs\includedocskip,
97 % each with a |*| version analogous to the new \cmd{include*}. Each take a
98 % filename as an argument just like \cs\include.
99 %
100 % \cs\includedoc\marg{filename} reads everything in the file except for
101 % \cs\documentclass, \cs\usepackage, |\begin{document}|, |\end{document}|
102 % (and whatever follows it).
103 %
104 % \cs\includedocskip\marg{filename} does the same except it also skips
105 % everything between \cs\documentclass and |\begin{document}|.
106 %
107 % \DescribeMacro{\disable}
108 % At present there is a makeshift way to ignore additional commands when
109 % using \cs\includedoc and \cs\includedocskip. If you want to cause \cs\foo
110 % which takes no arguments to be disabled, say |\disable{\let\foo\relax}|. If
111 % \cs\foo takes one mandatory argument, say |\let\foo\Gobble| instead. If
112 % \cs\foo takes one optional and one mandatory, say |\let\foo\GobbleOM|. If
113 % \cs\foo takes two mandatory arguments, say |\let\foo\GobbleMM|. For other
114 % permutations of arguments, you can extrapolate from the macros defined
115 % below.
116 %
117 % \StopEventually{}
118 %
119 % \part{Implementation}
120 %
121 % \section{Version control}
122 %
123 % \begin{macro}{\fileinfo}
124 % \begin{macro}{\DoXUsepackagE}
125 % \begin{macro}{\HaveECitationS}
126 % \begin{macro}{\fileversion}
127 % \begin{macro}{\filedate}
128 % \begin{macro}{\docdate}
129 % \begin{macro}{\PPOptArg}
130 % These definitions must be the first ones in the file.
131 % \begin{macrocode}
132 \def\fileinfo{extra ways to include files}
133 \def\DoXPackageS {}
134 \def\fileversion{v0.6a}
135 \def\filedate{1999/02/23}
136 \def\docdate{1999/02/23}
137 \edef\PPOptArg {%
138 \filedate\space \fileversion\space \fileinfo
139 }
140 % \end{macrocode}
141 % \end{macro}
142 % \end{macro}
143 % \end{macro}
144 % \end{macro}
145 % \end{macro}
146 % \end{macro}
147 % \end{macro}
148 %
149 % If we're loading this file from a \cs\ProcessDTXFile command (see the
150 % \package{compsci} package), then \cs\JusTLoaDInformatioN will be defined;
151 % othewise we assume it is not (that's why the FunkY NamE).
152 %
153 % If we're loading from \cs\ProcessDTXFile, we want to load the packages listed
154 % in \cs\DoXPackageS (needed to typeset the documentation for this file) and
155 % then bail out. Otherwise, we're using this file in a normal way as a
156 % package, so do nothing. \cs\DoXPackageS, if there are any, are declared in
157 % the \ext{dtx} file, and, if you're reading the typeset documentation of this
158 % package, would appear just above. (It's OK to call \cs\usepackage with an
159 % empty argument or \cs\relax, by the way.)
160 % \begin{macrocode}
161 \makeatletter% A special comment to help create bst files. Don't change!
162 \@ifundefined{JusTLoaDInformatioN} {%
163 }{% ELSE (we know the compsci package is already loaded, too)
164 \UndefineCS\JusTLoaDInformatioN
165 \SaveDoXVarS
166 \eExpand\csname DoXPackageS\endcsname\In {%use \csname in case it's undefined
167 \usepackage{#1}%
168 }%
169 \RestoreDoXVarS
170 \makeatother
171 \endinput
172 }% A special comment to help create bst files. Don't change!
173 % \end{macrocode}
174 %
175 % Now we check for \LaTeX2e and declare the LaTeX package.
176 % \begin{macrocode}
177 \NeedsTeXFormat{LaTeX2e}
178 \ProvidesPackage{includex}[\PPOptArg]
179 % \end{macrocode}^^A special comment to help create bst files. Don't change!
180 %
181 % ^^A NOTE: We have to compensate for the above backslashes, which are not
182 % ^^A actually in the .dtx file the author works on, by adding to the
183 % ^^A CheckSum.
184 %%
185 % \AddToCheckSum{17}^^A `dtx-update-checksum' automatically handles this.
186 % \AddToCheckSum{7}^^A The half a macrocode env. at the top is missed, however...
187 % \AddToCheckSum{10}^^A ... and so are the 5 \defs from the .dtx file
188 % ^^A that precede it.
189 % \IfCitations {%
190 % \AddToCheckSum{2}^^A When \initelyHavECitationS is defined in
191 % } ^^A the .dtx file, we need 2 more in the CheckSum.
192 %
193 %
194 % \section{Requirements}
195 %
196 % Now we declare the package, check for \LaTeX2e, and load the other packages
197 % needed.
198 % \begin{macrocode}
199 \NeedsTeXFormat{LaTeX2e}
200 \ProvidesPackage{includex}
201 \RequirePackage{moredefs}
202 % \end{macrocode}
203 %
204 % \section{Disabling things}
205 %
206 % \begin{macro}{\disable}
207 % This allows the disabling hacks.
208 % \begin{macrocode}
209 \ReserveCS\DisableMonster % This line is elsewhere for main package
210 \newcommand\disable[1] {%
211 \g@addto@macro\DisableMonster{#1}%
212 }
213 % \end{macrocode}
214 % \end{macro}
215 %
216 % \section{New things}
217 %
218 % \begin{macro}{\sc@saved@include}
219 % \begin{macro}{\include}
220 % \begin{macro}{\sc@include}
221 % \begin{macro}{\sc@@include}
222 % This is a simple redefinition of \cs\include without the \cs\clearpage
223 % commands. Nothing tricky going on.
224 % \begin{macrocode}
225 \newlet\sc@saved@include\include
226 \renewcommand\include {%
227 \@ifstar
228 \sc@include
229 \sc@saved@include
230 }
231 \newcommand\sc@include {%
232 \relax
233 \ifnum\@auxout=\@partaux
234 \@latex@error{\string\include\space cannot be nested}\@eha
235 \else
236 \expandafter\sc@@include
237 \fi
238 }
239 \newcommand\sc@@include[1] {%
240 \if@filesw
241 \immediate\write\@mainaux{\string\@input{#1.aux}}%
242 \fi
243 \@tempswatrue
244 \if@partsw
245 \@tempswafalse
246 \edef\@tempb{#1}%
247 \@for \@tempa:=\@partlist
248 \do{\ifx\@tempa
249 \@tempb
250 \@tempswatrue
251 \fi}%
252 \fi
253 \if@tempswa
254 \let\@auxout\@partaux
255 \if@filesw
256 \immediate\openout\@partaux #1.aux%
257 \immediate\write\@partaux{\relax}%
258 \fi
259 \@input@{#1.tex}%
260 \@writeckpt{#1}%
261 \if@filesw
262 % NOTE: Robin took out the \immediate here.
263 % \immediate\closeout\@partaux
264 \closeout\@partaux
265 \fi
266 \else
267 \@nameuse{cp@#1}%
268 \fi
269 \let\@auxout\@mainaux
270 }
271 % \end{macrocode}
272 % \end{macro}
273 % \end{macro}
274 % \end{macro}
275 % \end{macro}
276 %
277 % Now we start dealing with the much more tricky extraction of the |document|
278 % environment.
279 %
280 % We start with considering how to quit inputting a file. The idea is to make
281 % the |\end{document}| command of the included file call \cs\endinput. But
282 % there is a hitch that characters on the line after the |\end{document}| get
283 % inserted when you don't want them to. To beat that limitation, we have to do
284 % some work.
285 %
286 % \begin{macro}{\sc@radical@shutdown}
287 % We will add a bunch of commands to this macro, with the idea of \cs\catcode ing
288 % everything and its brother to a comment. This would be a brute force
289 % method!
290 % \begin{macrocode}
291 \ReserveCS\sc@radical@shutdown
292 % \end{macrocode}
293 % First log a message that we're about to do some crazy things. In case
294 % something ever goes wrong, this might help.
295 % \begin{macrocode}
296 \addto@macro\sc@radical@shutdown {%
297 \PackageInfo{includex}{\protect\sc@radical@shutdown\space beginning}%
298 }
299 % \end{macrocode}
300 % Now we start adding \cs\catcode commands. These first two should be
301 % redundant; but just in case someone changed things\lips.
302 % \begin{macrocode}
303 \addto@macro\sc@radical@shutdown{\catcode`\%=14} % 14 = comment
304 \addto@macro\sc@radical@shutdown{\catcode`\^=7} % 7 = superscript
305 % \end{macrocode}
306 % \begin{macro}{\sc@disable@char}
307 % Next, we define a command we weill use in a loop in a moment.
308 % \begin{macrocode}
309 \newcommand\sc@disable@char[1] {%
310 \addto@macro\sc@radical@shutdown
311 {\catcode`#1=14}} % 14 = comment
312 % \end{macrocode}
313 % \end{macro}
314 % The following list contains every keyboard char except these three, which are
315 % treated specially: |%#|.
316 % The first is already a comment, and we handle the second in a moment. Each
317 % character in the following list is \cs\catcode d to a comment:
318 % \begin{macrocode}
319 \@tfor\sc@t@a:=abcdefghijklmnopqrstuvwxyz%
320 ABCDEFGHIJKLMNOPQRSTUVWXYZ%
321 ~!@$&*()_+-=[]|/?.,<>%
322 1234567890%
323 `'";:%
324 \^\\\{\}\ % this is really the chars "^\{}" and space
325 \do {\expandafter\sc@disable@char\sc@t@a}
326 % \end{macrocode}
327 % We add |#| separately, because it's tricky or impossible to put it into the
328 % list we just used.
329 % \begin{macrocode}
330 \sc@disable@char\#
331 % \end{macrocode}
332 % We end the macro with \cs\endinput. This has to come after all the previous,
333 % otherwise, \TeX{} goes ahead and reads to the end of the line immediately,
334 % with regular catcodes. This is a good theory, I'm not sure it's necessary.
335 % \begin{macrocode}
336 \addto@macro\sc@radical@shutdown{\endinput}
337 % \end{macrocode}
338 % \end{macro}
339 %
340 % \begin{macro}{\sc@radical@shutdown@aftergroup}
341 % We need to use |\sc@radical@shutdown| this way.
342 % \begin{macrocode}
343 \newcommand\sc@radical@shutdown@aftergroup {%
344 \aftergroup\sc@radical@shutdown
345 }
346 % \end{macrocode}
347 % \end{macro}
348 %
349 % \begin{macro}{\sc@begindoc@toks}
350 % \begin{macro}{\sc@enddoc@toks}
351 % These are for \cs\AtBeginIncludedDocument and \cs\AtEndIncludedDocument.
352 % \begin{macrocode}
353 \newtoks\sc@begindoc@toks
354 \sc@begindoc@toks{}
355 \newtoks\sc@enddoc@toks
356 \sc@enddoc@toks{}
357 % \end{macrocode}
358 % \end{macro}
359 % \end{macro}
360 %
361 % \begin{macro}{\AtBeginIncludedDocument}
362 % The analogue of \cs\AtBeginDocument.
363 % \begin{macrocode}
364 \newcommand\AtBeginIncludedDocument[1] {%
365 \sc@begindoc@toks\expandafter{\the\sc@begindoc@toks#1}%
366 }
367 % \end{macrocode}
368 % \end{macro}
369 %
370 % \begin{macro}{\AtEndIncludedDocument}
371 % The analogue of \cs\AtEndDocument
372 % \begin{macrocode}
373 \newcommand\AtEndIncludedDocument[1] {%
374 \sc@enddoc@toks\expandafter{\the\sc@enddoc@toks#1}%
375 }
376 % \end{macrocode}
377 % \end{macro}
378 %
379 % \begin{macro}{\includedoc}
380 % \begin{macro}{\includedoc*}
381 % Now we start from the other end, defining the user command.
382 % \begin{macrocode}
383 \newcommand\includedoc {%
384 % Robin's new:
385 \@ifstar {%
386 \def\sc@includebit@cmd{\include*}\sc@includebit
387 }{% ELSE
388 \let\sc@includebit@cmd\include\sc@includebit
389 }%
390 }
391
392 % My old:
393 % {\sc@includebit}
394 % {\clearpage
395 % \sc@includebit[\clearpage]}}
396 % \end{macrocode}
397 % \end{macro}
398 % \end{macro}
399 %
400 % \begin{macro}{\sc@includebit}
401 % The commented-out code is for some eventual extensions.
402 %
403 % Interface is \cmd{sc@includebit}\oarg{postlude}\marg{file} (where
404 % \oarg{postlude} is command(s) to be executed after the inclusion is
405 % complete); it is assumed that \cmd{sc@includebit@cmd} is either \cs\include
406 % or \cmd{include*}
407 % \begin{macrocode}
408 \newcounter{sc@count}
409 \newcounter{bit}
410 \newcommand\sc@includebit [2] [] {%
411 \setcounter{sc@count}{\thebit}%
412 \begingroup
413 \DisableMonster
414 \let\usepackage\GobbleOM
415 % Robin's new:
416 \def\enddocument {%
417 \makeatletter
418 \the\sc@enddoc@toks
419 \sc@radical@shutdown@aftergroup
420 }
421 % My old:
422 % \let\enddocument\sc@radical@shutdown@aftergroup
423 \let\documentclass\GobbleOM
424 \let\documentstyle\GobbleOM % why worry about branching if 2.09..
425 \def\document {%
426 \the\sc@begindoc@toks
427 }%
428 \def\IncludedJobname {#2}%
429 \sc@includebit@cmd{#2}%
430 \endgroup
431 \par
432 #1
433 }
434 % \end{macrocode}
435 % \end{macro}
436 %
437 % \begin{macro}{\includedocskip}
438 % \begin{macro}{\includedocskip*}
439 % Now we make a similar command that \emph{entirely} skips the preamble,
440 % whereas \cs\includedoc only skipped those commands that we specifically
441 % disabled. Obviously this whole business of the preamble needs to be
442 % radically reconceived if convenient modularity of documents is to be had. At
443 % the moment, no distinction is made between things like \cs\newcommand and
444 % \cs\usepackage that should be exported to a parent file, and those things that
445 % should not.
446 % \begin{macrocode}
447 \newcommand\includedocskip {%
448 \@ifstar {%
449 \sc@includebitskip
450 }{% ELSE
451 \clearpage
452 \sc@includebitskip[\clearpage]%
453 }%
454 }
455 % \end{macrocode}
456 % \end{macro}
457 % \end{macro}
458 %
459 % I tried combining |\sc@includebitskip| and |\sc@includebit| but something
460 % changed when I used a conditional to do this. I'm sure the problem could be
461 % figured out and the two combined.
462 %
463 % \begin{macro}{\sc@includebitskip}
464 % We begin skipping with the \cs\documentclass or \cs\documentstyle command, and
465 % stop with the |\begin{document}| command. With some hacking to the new
466 % |verbatim| environment, this could be done. I haven't done this yet, so this
467 % is implemented by stuffing everything into a macro argument. I can't think
468 % of a \cs\begin occurring between \cs\documentclass the \cs\begin document, but
469 % that will screw things up if it does.
470 %
471 % The commented lines here are once again for a future extension.
472 % \begin{macrocode}
473 \newcommand\sc@includebitskip [2] [] {%
474 \setcounter{sc@count}{\thebit}%
475 \begingroup
476 \DisableMonster
477 \let\enddocument\sc@radical@shutdown@aftergroup
478 \long\def\documentclass ##1\begin{%
479 \begingroup
480 \def\@currenvir{document}%
481 \GobbleM
482 }% "{document}" is still to be read.
483 \let\documentstyle\documentclass
484 \include*{#2}%
485 \endgroup
486 \par
487 #1\relax
488 }
489 % \end{macrocode}
490 % \end{macro}
491 %
492 % \Finale