summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/koma-script/doc/english/scrwfile.tex
blob: 0ecb1c9a7fbca7f22d6f0338ff95e5f8689542ac (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
%%
%% This is file `scrwfile.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% scrwfile.dtx  (with options: `doc')
%% 
%% Copyright (c) 2010-2012 by Markus Kohm <komascript(at)gmx.info>
%% 
%% This file was generated from file(s) of the KOMA-Script bundle.
%% ---------------------------------------------------------------
%% 
%% This work may be distributed and/or modified under the conditions of
%% the LaTeX Project Public License, version 1.3c of the license.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3c or later is part of all distributions of LaTeX
%% version 2005/12/01 or later and of this work.
%% 
%% This work has the LPPL maintenance status "author-maintained".
%% 
%% The Current Maintainer and author of this work is Markus Kohm.
%% 
%% This file may only be distributed together with the file
%% `scrwfile.dtx' and `scrlogo.dtx'. You may however distribute the files
%% `scrwfile.dtx' and `scrlogo.dtx' without this file.
%% 
%% If this file is a beta version, you are not allowed to distribute it.
%% 
%% English and German manuals are part of KOMA-Script bundle.
%% ----------------------------------------------------------
%% 
%% The english manual is at `scrwfile.dtx', too.
%% 
%% The KOMA-Script bundle (but not this file) was based upon the LaTeX2.09
%% Script family created by Frank Neukam 1993 and the LaTeX2e standard
%% classes created by The LaTeX3 Project 1994-1996.
%% 
%% THIS IS AN ALPHA VERSION!
%% USAGE OF THIS VERSION IS ON YOUR OWN RISK!
%% EVERYTHING MAY HAPPEN!
%% EVERYTHING MAY CHANGE IN FUTURE!
%% THERE IS NO SUPPORT, IF YOU USE THIS PACKAGE!
%% 
%%% From File: scrwfile.dtx
\ProvidesFile{scrwfile.tex}
  [2011/09/11 v0.1c-alpha LaTeX2e KOMA-Script package (write and clone files)]
\chapter[{Spare and Replace Files Using \Package{scrwfile}}]
{Spare and Replace Files Using \Package{scrwfile}%
  \footnote{This chapter has been generated from \File{scrwfile.dtx}.}%
}
\labelbase{scrwfile}

\TeX{} supports 18 write handles only. Handle 0 is used
by \TeX{} itself (log file). \LaTeX{} needs at least handle 1 for
\Macro{@mainaux}, handle 2 for \Macro{@partaux}, one handle for
\Macro{tableofcontents}, one handle for \Macro{listoffigures}, one
handle for \Macro{listoftables}, one handle for \Macro{makeindex}. So
there are 11 left. Seams a lot and enough. But every new float, every new
index and several other packages, e.g., \Package{hyperref} need write
handles, too. Loading \Package{scrwfile} minimizes the need of write
handles for list of floats or tables of contents. Additionally it allows
to clone entries from one file to another file.

\section{The Idea}
\label{sec:scrwfile.idea}

Table of contents, list of figures, list of tables and other content
directories make use of a small amount of \LaTeX{} kernel macros to open
helper files, write to those helper files and read them. The first macro is
\Macro{@starttoc}. It is used inside of \Macro{tableofcontents},
\Macro{listoffigure}, \Macro{listoftable} and many \Macro{listof} macros of
several packages.

The primary macro \Macro{@starttoc} reads the helper file with the contents
of the directory. But this kernel macro also calls for a new write handle
and even opens the helper file for writing. So every call of this macro
consumes one of the rare write handles.

But while the document is processed nobody writes to that handle until
\Macro{end}\PParameter{document}. Every write operation should be done using
\Macro{addtocontents} or \Macro{addcontentsline}, that internally uses
\Macro{addtocontents}, too. The macro \Macro{addtocontents} does not really
write to the helper file, but writes a \Macro{@writefile} macro to the main
or part \File{aux} file.

At \Macro{end}\PParameter{document} the main \File{aux} file is closed and
after closing \LaTeX{} inputs the main \File{aux} file. While this reading
the \Macro{@writefile} macros are processed and only then the helper
files are written.

You see, there is no need to hold the helper files open while the document
is processed. The helper files need to be opened only before reading the
\File{aux} file at \Macro{end}\PParameter{document}. Even you do not need
one write handle per helper file, if you only could write one after the
other. In this case only one write handle would be needed. And that's the
idea.

\section{Using the Package}
\label{sec:scrwfile.usage}

First of all you have to load the package. This may be simply done using
\begin{lstcode}
  \usepackage{scrwfile}
\end{lstcode}
or if you are a package author by using
\begin{lstcode}
  \RequirePackage{scrwfile}
\end{lstcode}
This also activates the \emph{single file feature}.

\subparagraph*{Note:} The package \Package{scrwfile} may be used with other
files, that redefine \Macro{@starttoc}. But if these files do a complete
new definition of \Macro{@starttoc} you should load them before
\Package{scrwfile} to avoid errors.

\subsection{The Single File Feature}

To activate the single file feature, that means, that \Macro{\@starttoc}
does not longer consumes write handles and every open and write to helper
file action will be done at \Macro{end}\PParameter{document}, you only need
to load package \Package{scrwfile}.

See \autoref{sec:scrwfile.idea} for more information about the idea of this
feature.

\subparagraph*{Note:} Package \Package{scrwfile} uses package
\Package{scrlfile} to redefine \Macro{@writefile} while
\Macro{end}\PParameter{document}. Instead of directly writing to the helper
files \Macro{@writefile} itself will write to a new helper file
\Macro{jobname}\File{.wrt}. To write all the helper files this will file be
input several times. One time for each helper file.

\subsection{The Clone File Write Feature}

Sometimes it is useful to input a file not only once but several times. As
\Macro{@starttoc} does not open files for writing any longer, this may be
done by simply using \Macro{\@starttoc} several times with the same
extension. But sometimes you may have additional entries in only some of the
content directories. Because of this, \Package{scrwfile} allows to copy all
entries of a file to another file, too. We call this cloning.

\begin{Declaration}
  \Macro{TOCclone}%
  \OParameter{heading}\Parameter{source}\Parameter{destination}
\end{Declaration}
\BeginIndex{Cmd}{TOCclone}%
activates the clone feature for files with extensions \PName{source} and
\PName{destination}. All entries to the file
\Macro{jobname}\File{.}\PName{source} will be added to
\Macro{jobname}\File{.}\PName{destination}, too.

If extension \PName{destination} is a new one, \PName{destination} will be
added to the list of known extensions using the \KOMAScript{} package
\Package{tocbasic}.

If the optional argument \PName{heading} is given, a new list-of macro
\Macro{listof}\PName{destination} is defined. \PName{heading} will be used
as section (or chapter) heading of this list. In this case several
\Package{tocbasic} features of the \PName{source} will be copied to
\PName{destination}, if and only if they have been set up when
\Macro{TOCclone} was used. Feature \PName{nobabel} will always be set,
because the language selection commands are part of the helper file and
would be cloned, too.

\begin{Example}
E.g., you want a short table of contents
with only the chapter level but an additional entry with the table of
contents:
\begin{lstcode}
  \usepackage{scrwfile}
  \TOCclone[Short \contentsname]{toc}{stoc}
  \AtBeginDocument{%
    % aux first opened at \begin{document}. So wait until this:
    \addtocontents{toc}{% first toc entry:
      \proctect\addcontentsline{stoc}{% write to Short Contents
        \protect\tableofcontents% Contents
      }%
    }%
  }
  \begin{document}
  \setcounter{tocdepth}{1}% show chapters only
  \listofstoc% Write short table of contents
  \setcounter{tocdepth}{6}% show all levels
  \tableofcontents% Write table of contents
\end{lstcode}
You need at least three \LaTeX{} runs to get a short table of contents and a
detailed table of contents. The detailed one produces an entry at the short
one but this entry will not be part of the detailed table of contents.
\end{Example}
\EndIndex{Cmd}{TOCclone}

\endinput
%%
%% End of file `scrwfile.tex'.