fc936a18d1253f03ba04f113b746fc419ced2d8c
[freeside.git] / etc / fslongtable.sty
1 %%
2 %% This is file `fslongtable.sty',
3 %%
4 %% Copyright 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003
5 %% The LaTeX3 Project and any individual authors listed elsewhere
6 %% in this file.
7 %% 
8 %% This file was forked from file(s) of the Standard LaTeX `Tools Bundle'.
9 %% This file includes a new length LTextracouponspace which modifies
10 %% the behavior of the package at the end of a page.  This feature 
11 %% and package is not supported or acknowledged by Dave Carlisle.
12 %% Do not contact him for such support.
13 %% --------------------------------------------------------------------------
14 %% 
15 %% It may be distributed and/or modified under the
16 %% conditions of the LaTeX Project Public License, either version 1.3
17 %% of this license or (at your option) any later version.
18 %% The latest version of this license is in
19 %%    http://www.latex-project.org/lppl.txt
20 %% and version 1.3 or later is part of all distributions of LaTeX
21 %% version 2003/12/01 or later.
22 %% 
23 %% File: longtable.dtx Copyright (C) 1990-2001 David Carlisle
24 %% File: fslongtable.sty Copyright (C) 2008 Jeff Finucane
25 \NeedsTeXFormat{LaTeX2e}[1995/06/01]
26 \ProvidesPackage{longtable}
27           [2004/02/01 v4.11 Multi-page Table package (DPC)]
28 \def\LT@err{\PackageError{longtable}}
29 \def\LT@warn{\PackageWarning{longtable}}
30 \def\LT@final@warn{%
31   \AtEndDocument{%
32     \LT@warn{Table \@width s have changed. Rerun LaTeX.\@gobbletwo}}%
33   \global\let\LT@final@warn\relax}
34 \DeclareOption{errorshow}{%
35   \def\LT@warn{\PackageInfo{longtable}}}
36 \DeclareOption{pausing}{%
37   \def\LT@warn#1{%
38     \LT@err{#1}{This is not really an error}}}
39 \DeclareOption{set}{}
40 \DeclareOption{final}{}
41 \ProcessOptions
42 \newskip\LTleft       \LTleft=\fill
43 \newskip\LTright      \LTright=\fill
44 \newskip\LTpre        \LTpre=\bigskipamount
45 \newskip\LTpost       \LTpost=\bigskipamount
46 \newcount\LTchunksize \LTchunksize=20
47 \let\c@LTchunksize\LTchunksize
48 \newdimen\LTcapwidth  \LTcapwidth=4in
49 \newlength\LTextracouponspace
50 \newbox\LT@head
51 \newbox\LT@firsthead
52 \newbox\LT@foot
53 \newbox\LT@lastfoot
54 \newcount\LT@cols
55 \newcount\LT@rows
56 \newcounter{LT@tables}
57 \newcounter{LT@chunks}[LT@tables]
58 \ifx\c@table\undefined
59   \newcounter{table}
60   \def\fnum@table{\tablename~\thetable}
61 \fi
62 \ifx\tablename\undefined
63   \def\tablename{Table}
64 \fi
65 \newtoks\LT@p@ftn
66 \mathchardef\LT@end@pen=30000
67 \def\longtable{%
68   \par
69   \ifx\multicols\@undefined
70   \else
71      \ifnum\col@number>\@ne
72        \@twocolumntrue
73      \fi
74   \fi
75   \if@twocolumn
76     \LT@err{longtable not in 1-column mode}\@ehc
77   \fi
78   \begingroup
79   \@ifnextchar[\LT@array{\LT@array[x]}}
80 \def\LT@array[#1]#2{%
81   \refstepcounter{table}\stepcounter{LT@tables}%
82   \if l#1%
83     \LTleft\z@ \LTright\fill
84   \else\if r#1%
85     \LTleft\fill \LTright\z@
86   \else\if c#1%
87     \LTleft\fill \LTright\fill
88   \fi\fi\fi
89   \let\LT@mcol\multicolumn
90   \let\LT@@tabarray\@tabarray
91   \let\LT@@hl\hline
92   \def\@tabarray{%
93     \let\hline\LT@@hl
94     \LT@@tabarray}%
95   \let\\\LT@tabularcr\let\tabularnewline\\%
96   \def\newpage{\noalign{\break}}%
97   \def\pagebreak{\noalign{\ifnum`}=0\fi\@testopt{\LT@no@pgbk-}4}%
98   \def\nopagebreak{\noalign{\ifnum`}=0\fi\@testopt\LT@no@pgbk4}%
99   \let\hline\LT@hline \let\kill\LT@kill\let\caption\LT@caption
100   \@tempdima\ht\strutbox
101   \let\@endpbox\LT@endpbox
102   \ifx\extrarowheight\@undefined
103     \let\@acol\@tabacol
104     \let\@classz\@tabclassz \let\@classiv\@tabclassiv
105     \def\@startpbox{\vtop\LT@startpbox}%
106     \let\@@startpbox\@startpbox
107     \let\@@endpbox\@endpbox
108     \let\LT@LL@FM@cr\@tabularcr
109   \else
110     \advance\@tempdima\extrarowheight
111     \col@sep\tabcolsep
112     \let\@startpbox\LT@startpbox\let\LT@LL@FM@cr\@arraycr
113   \fi
114   \setbox\@arstrutbox\hbox{\vrule
115     \@height \arraystretch \@tempdima
116     \@depth \arraystretch \dp \strutbox
117     \@width \z@}%
118   \let\@sharp##\let\protect\relax
119    \begingroup
120     \@mkpream{#2}%
121     \xdef\LT@bchunk{%
122        \global\advance\c@LT@chunks\@ne
123        \global\LT@rows\z@\setbox\z@\vbox\bgroup
124        \LT@setprevdepth
125        \tabskip\LTleft \noexpand\halign to\hsize\bgroup
126       \tabskip\z@ \@arstrut \@preamble \tabskip\LTright \cr}%
127   \endgroup
128   \expandafter\LT@nofcols\LT@bchunk&\LT@nofcols
129   \LT@make@row
130   \m@th\let\par\@empty
131   \everycr{}\lineskip\z@\baselineskip\z@
132   \LT@bchunk}
133 \def\LT@no@pgbk#1[#2]{\penalty #1\@getpen{#2}\ifnum`{=0\fi}}
134 \def\LT@start{%
135   \let\LT@start\endgraf
136   \endgraf\penalty\z@\vskip\LTpre
137   \dimen@\pagetotal
138   \advance\dimen@ \ht\ifvoid\LT@firsthead\LT@head\else\LT@firsthead\fi
139   \advance\dimen@ \dp\ifvoid\LT@firsthead\LT@head\else\LT@firsthead\fi
140   \advance\dimen@ \ht\LT@foot
141   \advance\dimen@ \LTextracouponspace
142   \dimen@ii\vfuzz
143   \vfuzz\maxdimen
144     \setbox\tw@\copy\z@
145     \setbox\tw@\vsplit\tw@ to \ht\@arstrutbox
146     \setbox\tw@\vbox{\unvbox\tw@}%
147   \vfuzz\dimen@ii
148   \advance\dimen@ \ht
149         \ifdim\ht\@arstrutbox>\ht\tw@\@arstrutbox\else\tw@\fi
150   \advance\dimen@\dp
151         \ifdim\dp\@arstrutbox>\dp\tw@\@arstrutbox\else\tw@\fi
152   \advance\dimen@ -\pagegoal
153   \ifdim \dimen@>\z@\vfil\break\fi
154       \global\@colroom\@colht
155   \ifnum\thepage=1
156     \advance\vsize-\LTextracouponspace
157     \dimen@\pagegoal\advance\dimen@-\LTextracouponspace\pagegoal\dimen@
158   \fi
159   \ifvoid\LT@foot\else
160     \advance\vsize-\ht\LT@foot
161     \global\advance\@colroom-\ht\LT@foot
162     \dimen@\pagegoal\advance\dimen@-\ht\LT@foot\pagegoal\dimen@
163     \maxdepth\z@
164   \fi
165   \ifvoid\LT@firsthead\copy\LT@head\else\box\LT@firsthead\fi\nobreak
166   \output{\LT@output}}
167 \def\endlongtable{%
168   \crcr
169   \noalign{%
170     \let\LT@entry\LT@entry@chop
171     \xdef\LT@save@row{\LT@save@row}}%
172   \LT@echunk
173   \LT@start
174   \unvbox\z@
175   \LT@get@widths
176   \if@filesw
177     {\let\LT@entry\LT@entry@write\immediate\write\@auxout{%
178       \gdef\expandafter\noexpand
179         \csname LT@\romannumeral\c@LT@tables\endcsname
180           {\LT@save@row}}}%
181   \fi
182   \ifx\LT@save@row\LT@@save@row
183   \else
184     \LT@warn{Column \@width s have changed\MessageBreak
185              in table \thetable}%
186     \LT@final@warn
187   \fi
188   \endgraf\penalty -\LT@end@pen
189   \endgroup
190   \global\@mparbottom\z@
191   \pagegoal\vsize
192   \endgraf\penalty\z@\addvspace\LTpost
193   \ifvoid\footins\else\insert\footins{}\fi}
194 \def\LT@nofcols#1&{%
195   \futurelet\@let@token\LT@n@fcols}
196 \def\LT@n@fcols{%
197   \advance\LT@cols\@ne
198   \ifx\@let@token\LT@nofcols
199     \expandafter\@gobble
200   \else
201     \expandafter\LT@nofcols
202   \fi}
203 \def\LT@tabularcr{%
204   \relax\iffalse{\fi\ifnum0=`}\fi
205   \@ifstar
206     {\def\crcr{\LT@crcr\noalign{\nobreak}}\let\cr\crcr
207      \LT@t@bularcr}%
208     {\LT@t@bularcr}}
209 \let\LT@crcr\crcr
210 \let\LT@setprevdepth\relax
211 \def\LT@t@bularcr{%
212   \global\advance\LT@rows\@ne
213   \ifnum\LT@rows=\LTchunksize
214     \gdef\LT@setprevdepth{%
215       \prevdepth\z@\global
216       \global\let\LT@setprevdepth\relax}%
217     \expandafter\LT@xtabularcr
218   \else
219     \ifnum0=`{}\fi
220     \expandafter\LT@LL@FM@cr
221   \fi}
222 \def\LT@xtabularcr{%
223   \@ifnextchar[\LT@argtabularcr\LT@ntabularcr}
224 \def\LT@ntabularcr{%
225   \ifnum0=`{}\fi
226   \LT@echunk
227   \LT@start
228   \unvbox\z@
229   \LT@get@widths
230   \LT@bchunk}
231 \def\LT@argtabularcr[#1]{%
232   \ifnum0=`{}\fi
233   \ifdim #1>\z@
234     \unskip\@xargarraycr{#1}%
235   \else
236     \@yargarraycr{#1}%
237   \fi
238   \LT@echunk
239   \LT@start
240   \unvbox\z@
241   \LT@get@widths
242   \LT@bchunk}
243 \def\LT@echunk{%
244   \crcr\LT@save@row\cr\egroup
245   \global\setbox\@ne\lastbox
246     \unskip
247   \egroup}
248 \def\LT@entry#1#2{%
249   \ifhmode\@firstofone{&}\fi\omit
250   \ifnum#1=\c@LT@chunks
251   \else
252     \kern#2\relax
253   \fi}
254 \def\LT@entry@chop#1#2{%
255   \noexpand\LT@entry
256     {\ifnum#1>\c@LT@chunks
257        1}{0pt%
258      \else
259        #1}{#2%
260      \fi}}
261 \def\LT@entry@write{%
262   \noexpand\LT@entry^^J%
263   \@spaces}
264 \def\LT@kill{%
265   \LT@echunk
266   \LT@get@widths
267   \expandafter\LT@rebox\LT@bchunk}
268 \def\LT@rebox#1\bgroup{%
269   #1\bgroup
270   \unvbox\z@
271   \unskip
272   \setbox\z@\lastbox}
273 \def\LT@blank@row{%
274   \xdef\LT@save@row{\expandafter\LT@build@blank
275     \romannumeral\number\LT@cols 001 }}
276 \def\LT@build@blank#1{%
277   \if#1m%
278     \noexpand\LT@entry{1}{0pt}%
279     \expandafter\LT@build@blank
280   \fi}
281 \def\LT@make@row{%
282   \global\expandafter\let\expandafter\LT@save@row
283     \csname LT@\romannumeral\c@LT@tables\endcsname
284   \ifx\LT@save@row\relax
285     \LT@blank@row
286   \else
287     {\let\LT@entry\or
288      \if!%
289          \ifcase\expandafter\expandafter\expandafter\LT@cols
290          \expandafter\@gobble\LT@save@row
291          \or
292          \else
293            \relax
294          \fi
295         !%
296      \else
297        \aftergroup\LT@blank@row
298      \fi}%
299   \fi}
300 \let\setlongtables\relax
301 \def\LT@get@widths{%
302   \setbox\tw@\hbox{%
303     \unhbox\@ne
304     \let\LT@old@row\LT@save@row
305     \global\let\LT@save@row\@empty
306     \count@\LT@cols
307     \loop
308       \unskip
309       \setbox\tw@\lastbox
310     \ifhbox\tw@
311       \LT@def@row
312       \advance\count@\m@ne
313     \repeat}%
314   \ifx\LT@@save@row\@undefined
315     \let\LT@@save@row\LT@save@row
316   \fi}
317 \def\LT@def@row{%
318   \let\LT@entry\or
319   \edef\@tempa{%
320     \ifcase\expandafter\count@\LT@old@row
321     \else
322       {1}{0pt}%
323     \fi}%
324   \let\LT@entry\relax
325   \xdef\LT@save@row{%
326     \LT@entry
327     \expandafter\LT@max@sel\@tempa
328     \LT@save@row}}
329 \def\LT@max@sel#1#2{%
330   {\ifdim#2=\wd\tw@
331      #1%
332    \else
333      \number\c@LT@chunks
334    \fi}%
335   {\the\wd\tw@}}
336 \def\LT@hline{%
337   \noalign{\ifnum0=`}\fi
338     \penalty\@M
339     \futurelet\@let@token\LT@@hline}
340 \def\LT@@hline{%
341   \ifx\@let@token\hline
342     \global\let\@gtempa\@gobble
343     \gdef\LT@sep{\penalty-\@medpenalty\vskip\doublerulesep}%
344   \else
345     \global\let\@gtempa\@empty
346     \gdef\LT@sep{\penalty-\@lowpenalty\vskip-\arrayrulewidth}%
347   \fi
348   \ifnum0=`{\fi}%
349   \multispan\LT@cols
350      \unskip\leaders\hrule\@height\arrayrulewidth\hfill\cr
351   \noalign{\LT@sep}%
352   \multispan\LT@cols
353      \unskip\leaders\hrule\@height\arrayrulewidth\hfill\cr
354   \noalign{\penalty\@M}%
355   \@gtempa}
356 \def\LT@caption{%
357   \noalign\bgroup
358     \@ifnextchar[{\egroup\LT@c@ption\@firstofone}\LT@capti@n}
359 \def\LT@c@ption#1[#2]#3{%
360   \LT@makecaption#1\fnum@table{#3}%
361   \def\@tempa{#2}%
362   \ifx\@tempa\@empty\else
363      {\let\\\space
364      \addcontentsline{lot}{table}{\protect\numberline{\thetable}{#2}}}%
365   \fi}
366 \def\LT@capti@n{%
367   \@ifstar
368     {\egroup\LT@c@ption\@gobble[]}%
369     {\egroup\@xdblarg{\LT@c@ption\@firstofone}}}
370 \def\LT@makecaption#1#2#3{%
371   \LT@mcol\LT@cols c{\hbox to\z@{\hss\parbox[t]\LTcapwidth{%
372     \sbox\@tempboxa{#1{#2: }#3}%
373     \ifdim\wd\@tempboxa>\hsize
374       #1{#2: }#3%
375     \else
376       \hbox to\hsize{\hfil\box\@tempboxa\hfil}%
377     \fi
378     \endgraf\vskip\baselineskip}%
379   \hss}}}
380 \def\LT@output{%
381   \ifnum\outputpenalty <-\@Mi
382     \ifnum\outputpenalty > -\LT@end@pen
383       \LT@err{floats and marginpars not allowed in a longtable}\@ehc
384     \else
385       \setbox\z@\vbox{\unvbox\@cclv}%
386       \ifdim \ht\LT@lastfoot>\ht\LT@foot
387         \dimen@\pagegoal
388         \advance\dimen@-\ht\LT@lastfoot
389         \ifdim\dimen@<\ht\z@
390           \setbox\@cclv\vbox{\unvbox\z@\copy\LT@foot\vss}%
391           \@makecol
392           \@outputpage
393           \setbox\z@\vbox{\box\LT@head}%
394         \fi
395       \fi
396       \global\@colroom\@colht
397       \global\vsize\@colht
398       \vbox
399         {\unvbox\z@\box\ifvoid\LT@lastfoot\LT@foot\else\LT@lastfoot\fi}%
400     \fi
401   \else
402     \setbox\@cclv\vbox{\unvbox\@cclv\copy\LT@foot\vss}%
403     \@makecol
404     \@outputpage
405       \global\vsize\@colroom
406     \copy\LT@head\nobreak
407   \fi}
408 \def\LT@end@hd@ft#1{%
409   \LT@echunk
410   \ifx\LT@start\endgraf
411     \LT@err
412      {Longtable head or foot not at start of table}%
413      {Increase LTchunksize}%
414   \fi
415   \setbox#1\box\z@
416   \LT@get@widths
417   \LT@bchunk}
418 \def\endfirsthead{\LT@end@hd@ft\LT@firsthead}
419 \def\endhead{\LT@end@hd@ft\LT@head}
420 \def\endfoot{\LT@end@hd@ft\LT@foot}
421 \def\endlastfoot{\LT@end@hd@ft\LT@lastfoot}
422 \def\LT@startpbox#1{%
423   \bgroup
424     \let\@footnotetext\LT@p@ftntext
425     \setlength\hsize{#1}%
426     \@arrayparboxrestore
427     \vrule \@height \ht\@arstrutbox \@width \z@}
428 \def\LT@endpbox{%
429   \@finalstrut\@arstrutbox
430   \egroup
431   \the\LT@p@ftn
432   \global\LT@p@ftn{}%
433   \hfil}
434 \def\LT@p@ftntext#1{%
435   \edef\@tempa{\the\LT@p@ftn\noexpand\footnotetext[\the\c@footnote]}%
436   \global\LT@p@ftn\expandafter{\@tempa{#1}}}%
437 \endinput
438 %%
439 %% End of file `longtable.sty'.