%+ \iffalse %%% %%% @LaTeX-style{ %%% filename = "supplements.sty", %%% version = "1.0", %%% date = "22 July 1992", %%% time = "16:02:34.59 ", %%% author = "Norman Gray", %%% address = "Department of Physics %%% Open University %%% Milton Keynes %%% MK7 6AA, UK", %%% e-mail = "N.O.Gray@open.ac.uk (Internet)", %%% telephone = "+44 908 652279", %%% FAX = "+44 908 653744", %%% archived = "Aston, SHSU", %%% keywords = "LaTeX, cross-references", %%% codetable = "ISO/Ascii", %%% checksum = "40751 264 1754 13145", %%% docstring = "This style file allows one to maintain consistency %%% between files which must, for whatever reason, be %%% LaTeX'd (or even TeX'd) separately. You may specify %%% which counters (page, table, and so on) are to be %%% synchronised between the two files, index entries %%% and \label definitions may be made in any of the %%% synchronised files, and any cross-references will be %%% available in all the files. %%% %%% For additional documentation on the workings of the %%% package, see below. For a user's guide, see the %%% file supplements.hlp. %%% %%% The checksum field above contains a CRC-16 %%% checksum as the first value, followed by the %%% equivalent of the standard UNIX wc (word %%% count) utility output of lines, words, and %%% characters. This is produced by Robert %%% Solovay's checksum utility." %%% } %%% %%% This style file was produced by Norman Gray (N.O.Gray@open.ac.uk). If you %%% have any comments or suggestions, I'd be delighted to hear them. %%% %%% \fi % This style file allows parts of a document to be kept in % separate files (the `supplements files'), and \LaTeX ed % separately, but remain fully integrated with the file they belong % to (the `main file'). % % Assume a main file called |main.tex|, and a file of supplementary % pages called |SF.tex| (there can be several of these files). Both the % main file and the supplementary file (or files) should have the % |[supplements]| style option. % % In the supplements file, |SF.tex|, the pages to be inserted lie % between % $$ % |\begin{supplements}{main}{counters}| % $$ % and % $$ % |\end{supplements}| % $$ % The second argument is the name of the `main file', and the third % argument, |{counters}| contains a list of the counters which are % to be synchronised, for example, |{page,table}|. The former % reads in |main.aux|, if it exists, which sets up cross references % and citations, and sets the starting values of the synchronised % counters. The |\end{supplements}|, just before the % |\end{document}|, writes the number of supplementary pages to the % file |SF.aux|. Although it's not an error, there shouldn't be % more than one pair of |\begin...\end{supplements}| in the file. % % In |main.tex|, the command |\thesupplements[SF]| uses the % information in |SF.aux| to write to the aux file the current % values of the appropriate counters, then inputs |SF.aux|, and % increments the counters to one after the highest value in % |SF.tex|. If the argument |[SF]| is omitted, it defaults to % `supplements'. % % The sequence is: % \begin{description} % \item[\LaTeX\ the supplements file(s)] This writes the control % sequence % $$ % |\supp@synch{\jobname}{counter(inc),...}| % $$ % to the aux-file. The second argument consists of the list of % counters to be synchronised, and the amount by which they are to be % advanced in the main file (because there are that many % tables/pages\dots\ in the supplementary file). % \item[\LaTeX\ the main file] |\thesupplements| calls |\supp@inc|, % for each element in the control sequence |\SF@synchs|, which % is defined by |\supp@synch| when it reads in the aux-files. % This advances the right counters, and then writes the current % values of the specified counters to the main aux-file. It then % writes |\@input{SF.aux}| to the current aux file, so that it will % be read in by |\begin| and |\end{document}|. Because the main % aux-file won't have been thus modified first time round, the % macro is able to read in |SF.aux| immediately, if % |\SF@synchs| is not defined. % \item[\LaTeX\ the supplementary file(s) again] The main-file's % aux-file is read in, so that the start values of the counters % are now known for each file, so these will be printed with the % correct numbering. % \item[\LaTeX{} the main file again] If there are any cross references % to pages withing the supplementary files, then you'll have to % \LaTeX{} the main file again to get those cross references correct. % \end{description} % % Note that the program reads the supplementary aux-file only {\sl % via\/} the |\@input{SF.aux}| command in the main aux-file (the only % exception is the first time through the main file, when there's no % such command in |main.aux|). This means that all the aux-files are % read when \LaTeX\ is {\sl expecting\/} to read an aux-file, rather % than in the middle of a document. We have to have this behaviour (or % at least have the line |\@input{SF.aux}| somewhere in the main % aux-file at the end of the run) so that Bib\TeX can find |\citation|s % made in the supplementary files. It would certainly be simpler if the % aux-files were read in by the |\thesupplements| command, but this way % seems generally safer, as well as giving the correct behaviour with % Bib\TeX. % % Limitations % \begin{enumerate} % \item % It shouldn't be terribly difficult to persuade the style to % synchronise topmarks, as well, but it doesn't, at the moment. % \item % Although, again, it shouldn't be a terribly difficult thing to % implement, the style doesn't allow you to have more than one % lot of supplements in a single supplements file. % \end{enumerate} % \- % + |\supp@synch|: this is written to |SF.aux| by |\endsupplements| in % |SF.tex|, and gives the list of counters which are to be incremented for file % |#1.tex|, and their increments. The second argument is of the form % |counter(increment),...|, which says that the specified counter is to be % incremented by |inc|. The command defines the macro |\SF@synchs| to have % this expansion. (|#1|=supps file, |#2|=counters plus increments)\- \def\supp@synch#1#2{\expandafter\gdef\csname #1@synchs\endcsname{#2}} % + |\supp@inc|: called by |\thesupplements| in the main \TeX{} file, for each % element of |\SF@synchs|. It increments counter |#1| by value |#2|, and % writes the current value of the counter for the benefit of supplements file % |#3|. \- \def\supp@inc#1(#2)#3{\immediate\write\@mainaux {\string\supp@start{#3}{#1}{\expandafter\the\csname c@#1\endcsname }}\global\advance\csname c@#1\endcsname by #2} % + |\supp@start|: this is written to the main aux-file by |\supp@inc| in the % main \TeX{} file, and gives the starting values for the counters for a % specific supplements file. It defines the macro |\SF@counter| to be the % current value of the counter. (|#1|=supps file, |#2|=counter, |#3|=value) \- \def\supp@start#1#2#3{\@namedef{#1@#2}{#3}} % + User commands, |\supplements| and |\endsupplements|. % These two go in the supplements file. % % |\supplements|: Read the aux-file generated by the main file, and % initialise counters to hold the starting values of the list of counters % given in the second argument. Also, define |\index| to be |\suppindex|. % (|#1|=name of main file, |#2|=comma-separated list of counters) \- \def\supplements#1#2{% \makeatletter\@input{#1.aux}\makeatother% read in the main aux-file \edef\@synchs{#2}% % define |\@synchs| to be the list of counters \@for\@tempa:=\@synchs% % for each counter in that list \dots \do {\expandafter\newcount \csname c@start\@tempa\endcsname % declare a new % counter to hold the initial value of the % counter. \@ifundefined{\jobname @\@tempa}% |\supp@start| should define this {\value\@tempa=1}% |\supp@start| {\em hasn't} defined it---default {\value\@tempa =\@nameuse{\jobname @\@tempa}}% set the counter to the % starting value given in |\supp@start| \value{start\@tempa}=\value\@tempa}%\dots and save it \let\index\suppindex% % finally, deal with index entries in supps file } % + |\endsupplements|: end of the supplementary material. Start a new % page---write how many pages or tables (or whatever\dots) there were, % building up, in |\@inclist| a comma-separated list of |count(inc)|. Then % write that list to the aux-file as the argument of |\supp@synch|. \- \def\endsupplements{\clearpage \def\@inclist{}% % clear the list \@for\@tempa:=\@synchs% % for each of the list of counters \dots \do {\advance\csname c@\@tempa\endcsname -\value{start\@tempa}% subtract start value from % the current counter value \edef\@inclist{\ifx\@inclist\@empty \else \@inclist,\fi \@tempa (\the\value\@tempa)} } \immediate\write\@mainaux {\string\supp@synch{\jobname}{\@inclist}}% write a |\supp@synch| % command to the aux-file } % + |\thesupplements|: goes in the main file. For each element in % |\SF@synchs|, which was defined by |\supp@synchs| when the supplementary % aux-file was read in, call |\supp@inc|. Then write |\@input{SF.aux}| to % the aux-file, so that the right supplementary aux-file is read in by % |\end{document}|. This has to be a non-|\immediate| write, and it has to be % to the current aux-file rather than the main one, so that it is in the % correct sequence w.r.t.\ |\@writefile| commands generated by section % headings. % \- \def\thesupplements{\@ifnextchar[{\@insertsupplements}% {\@insertsupplements[supplements]}} \def\@insertsupplements[#1]{{\clearpage \@ifundefined{#1@synchs}% This is the first time through - read aux-file now {\openin1 #1.aux \ifeof1 % % If there's no aux-file at all, % give |\SF@synchs| a dummy value \@namedef{#1@synchs}{}\typeout{No file #1.aux.}% \dots and remark on it \else \closein1 \relax \makeatletter\@@input #1.aux \makeatother % read in the aux-file. % |\#1@synchs| is now defined (one way or the % other) \fi}{}% % no else clause \edef\@synchs{\csname #1@synchs\endcsname}% define |\@synchs| to have the % same value as |\#1@synchs|: can't use % |\csname| in |\@for| \typeout{}\message{Supplement: #1 [\the\c@page-}% print out a message \@for\@tempa:=\@synchs % % for each of the |counter(inc)| pairs \dots \do {\expandafter\supp@inc\@tempa{#1}}% increment the appropriate counter \write\@auxout{\string\@input{#1.aux}}% write an |\@input| % command to the current aux-file, to read in % the supplementary aux-file \message{-\the\c@page]}\typeout{}% give the ending page number }} % + Add support for |\index| commands in the supplements file. The command % causes |\supp@index| to be written on the .aux file. |\supp@index| is % defined, in turn, to write its arguments on the .idx file if one is open, and % if the .aux file is being read in by the |\end{document}| command. Thus it % won't be read in by the supplements file, since |\makeindex| shouldn't be % given. It checks to see if it's the |\begin| or the |\end{document}| which % is reading it in by using the fact that |\document| is |\let| equal to % |\@notprerr| at the end of the |\document| command. % % The upshot is that a proper |\indexentry| command should be written when the % aux file is read in at the end of the main file. This chunk is largely % swiped from |latex.tex|. \- \def\suppindex{\@bsphack\begingroup\@sanitize\supp@wrindex} \def\supp@wrindex#1{\let\thepage\relax \xdef\@gtempa{\write\@mainaux{\string \supp@index{#1}{\thepage}}}\endgroup\@gtempa \if@nobreak \ifvmode\nobreak\fi\fi\@esphack} \def\supp@index{\begingroup\@sanitize\supp@@index} \def\supp@@index#1#2{\ifx\document\@notprerr % we're in |\end{document}| \@ifundefined{@indexfile}{}% {\immediate\write\@indexfile{\string\indexentry{#1}{#2}}}\fi \endgroup}