find and correct the real double counting culprit
[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   \dimen@ii\vfuzz
142   \vfuzz\maxdimen
143     \setbox\tw@\copy\z@
144     \setbox\tw@\vsplit\tw@ to \ht\@arstrutbox
145     \setbox\tw@\vbox{\unvbox\tw@}%
146   \vfuzz\dimen@ii
147   \advance\dimen@ \ht
148         \ifdim\ht\@arstrutbox>\ht\tw@\@arstrutbox\else\tw@\fi
149   \advance\dimen@\dp
150         \ifdim\dp\@arstrutbox>\dp\tw@\@arstrutbox\else\tw@\fi
151   \advance\dimen@ -\pagegoal
152   \ifdim \dimen@>\z@\vfil\break\fi
153       \global\@colroom\@colht
154   \ifnum\thepage=1
155     \dimen@\pagegoal\advance\dimen@-\LTextracouponspace\pagegoal\dimen@
156   \fi
157   \ifvoid\LT@foot\else
158     \advance\vsize-\ht\LT@foot
159     \global\advance\@colroom-\ht\LT@foot
160     \dimen@\pagegoal\advance\dimen@-\ht\LT@foot\pagegoal\dimen@
161     \maxdepth\z@
162   \fi
163   \ifvoid\LT@firsthead\copy\LT@head\else\box\LT@firsthead\fi\nobreak
164   \output{\LT@output}}
165 \def\endlongtable{%
166   \crcr
167   \noalign{%
168     \let\LT@entry\LT@entry@chop
169     \xdef\LT@save@row{\LT@save@row}}%
170   \LT@echunk
171   \LT@start
172   \unvbox\z@
173   \LT@get@widths
174   \if@filesw
175     {\let\LT@entry\LT@entry@write\immediate\write\@auxout{%
176       \gdef\expandafter\noexpand
177         \csname LT@\romannumeral\c@LT@tables\endcsname
178           {\LT@save@row}}}%
179   \fi
180   \ifx\LT@save@row\LT@@save@row
181   \else
182     \LT@warn{Column \@width s have changed\MessageBreak
183              in table \thetable}%
184     \LT@final@warn
185   \fi
186   \endgraf\penalty -\LT@end@pen
187   \endgroup
188   \global\@mparbottom\z@
189   \pagegoal\vsize
190   \endgraf\penalty\z@\addvspace\LTpost
191   \ifvoid\footins\else\insert\footins{}\fi}
192 \def\LT@nofcols#1&{%
193   \futurelet\@let@token\LT@n@fcols}
194 \def\LT@n@fcols{%
195   \advance\LT@cols\@ne
196   \ifx\@let@token\LT@nofcols
197     \expandafter\@gobble
198   \else
199     \expandafter\LT@nofcols
200   \fi}
201 \def\LT@tabularcr{%
202   \relax\iffalse{\fi\ifnum0=`}\fi
203   \@ifstar
204     {\def\crcr{\LT@crcr\noalign{\nobreak}}\let\cr\crcr
205      \LT@t@bularcr}%
206     {\LT@t@bularcr}}
207 \let\LT@crcr\crcr
208 \let\LT@setprevdepth\relax
209 \def\LT@t@bularcr{%
210   \global\advance\LT@rows\@ne
211   \ifnum\LT@rows=\LTchunksize
212     \gdef\LT@setprevdepth{%
213       \prevdepth\z@\global
214       \global\let\LT@setprevdepth\relax}%
215     \expandafter\LT@xtabularcr
216   \else
217     \ifnum0=`{}\fi
218     \expandafter\LT@LL@FM@cr
219   \fi}
220 \def\LT@xtabularcr{%
221   \@ifnextchar[\LT@argtabularcr\LT@ntabularcr}
222 \def\LT@ntabularcr{%
223   \ifnum0=`{}\fi
224   \LT@echunk
225   \LT@start
226   \unvbox\z@
227   \LT@get@widths
228   \LT@bchunk}
229 \def\LT@argtabularcr[#1]{%
230   \ifnum0=`{}\fi
231   \ifdim #1>\z@
232     \unskip\@xargarraycr{#1}%
233   \else
234     \@yargarraycr{#1}%
235   \fi
236   \LT@echunk
237   \LT@start
238   \unvbox\z@
239   \LT@get@widths
240   \LT@bchunk}
241 \def\LT@echunk{%
242   \crcr\LT@save@row\cr\egroup
243   \global\setbox\@ne\lastbox
244     \unskip
245   \egroup}
246 \def\LT@entry#1#2{%
247   \ifhmode\@firstofone{&}\fi\omit
248   \ifnum#1=\c@LT@chunks
249   \else
250     \kern#2\relax
251   \fi}
252 \def\LT@entry@chop#1#2{%
253   \noexpand\LT@entry
254     {\ifnum#1>\c@LT@chunks
255        1}{0pt%
256      \else
257        #1}{#2%
258      \fi}}
259 \def\LT@entry@write{%
260   \noexpand\LT@entry^^J%
261   \@spaces}
262 \def\LT@kill{%
263   \LT@echunk
264   \LT@get@widths
265   \expandafter\LT@rebox\LT@bchunk}
266 \def\LT@rebox#1\bgroup{%
267   #1\bgroup
268   \unvbox\z@
269   \unskip
270   \setbox\z@\lastbox}
271 \def\LT@blank@row{%
272   \xdef\LT@save@row{\expandafter\LT@build@blank
273     \romannumeral\number\LT@cols 001 }}
274 \def\LT@build@blank#1{%
275   \if#1m%
276     \noexpand\LT@entry{1}{0pt}%
277     \expandafter\LT@build@blank
278   \fi}
279 \def\LT@make@row{%
280   \global\expandafter\let\expandafter\LT@save@row
281     \csname LT@\romannumeral\c@LT@tables\endcsname
282   \ifx\LT@save@row\relax
283     \LT@blank@row
284   \else
285     {\let\LT@entry\or
286      \if!%
287          \ifcase\expandafter\expandafter\expandafter\LT@cols
288          \expandafter\@gobble\LT@save@row
289          \or
290          \else
291            \relax
292          \fi
293         !%
294      \else
295        \aftergroup\LT@blank@row
296      \fi}%
297   \fi}
298 \let\setlongtables\relax
299 \def\LT@get@widths{%
300   \setbox\tw@\hbox{%
301     \unhbox\@ne
302     \let\LT@old@row\LT@save@row
303     \global\let\LT@save@row\@empty
304     \count@\LT@cols
305     \loop
306       \unskip
307       \setbox\tw@\lastbox
308     \ifhbox\tw@
309       \LT@def@row
310       \advance\count@\m@ne
311     \repeat}%
312   \ifx\LT@@save@row\@undefined
313     \let\LT@@save@row\LT@save@row
314   \fi}
315 \def\LT@def@row{%
316   \let\LT@entry\or
317   \edef\@tempa{%
318     \ifcase\expandafter\count@\LT@old@row
319     \else
320       {1}{0pt}%
321     \fi}%
322   \let\LT@entry\relax
323   \xdef\LT@save@row{%
324     \LT@entry
325     \expandafter\LT@max@sel\@tempa
326     \LT@save@row}}
327 \def\LT@max@sel#1#2{%
328   {\ifdim#2=\wd\tw@
329      #1%
330    \else
331      \number\c@LT@chunks
332    \fi}%
333   {\the\wd\tw@}}
334 \def\LT@hline{%
335   \noalign{\ifnum0=`}\fi
336     \penalty\@M
337     \futurelet\@let@token\LT@@hline}
338 \def\LT@@hline{%
339   \ifx\@let@token\hline
340     \global\let\@gtempa\@gobble
341     \gdef\LT@sep{\penalty-\@medpenalty\vskip\doublerulesep}%
342   \else
343     \global\let\@gtempa\@empty
344     \gdef\LT@sep{\penalty-\@lowpenalty\vskip-\arrayrulewidth}%
345   \fi
346   \ifnum0=`{\fi}%
347   \multispan\LT@cols
348      \unskip\leaders\hrule\@height\arrayrulewidth\hfill\cr
349   \noalign{\LT@sep}%
350   \multispan\LT@cols
351      \unskip\leaders\hrule\@height\arrayrulewidth\hfill\cr
352   \noalign{\penalty\@M}%
353   \@gtempa}
354 \def\LT@caption{%
355   \noalign\bgroup
356     \@ifnextchar[{\egroup\LT@c@ption\@firstofone}\LT@capti@n}
357 \def\LT@c@ption#1[#2]#3{%
358   \LT@makecaption#1\fnum@table{#3}%
359   \def\@tempa{#2}%
360   \ifx\@tempa\@empty\else
361      {\let\\\space
362      \addcontentsline{lot}{table}{\protect\numberline{\thetable}{#2}}}%
363   \fi}
364 \def\LT@capti@n{%
365   \@ifstar
366     {\egroup\LT@c@ption\@gobble[]}%
367     {\egroup\@xdblarg{\LT@c@ption\@firstofone}}}
368 \def\LT@makecaption#1#2#3{%
369   \LT@mcol\LT@cols c{\hbox to\z@{\hss\parbox[t]\LTcapwidth{%
370     \sbox\@tempboxa{#1{#2: }#3}%
371     \ifdim\wd\@tempboxa>\hsize
372       #1{#2: }#3%
373     \else
374       \hbox to\hsize{\hfil\box\@tempboxa\hfil}%
375     \fi
376     \endgraf\vskip\baselineskip}%
377   \hss}}}
378 \def\LT@output{%
379   \ifnum\outputpenalty <-\@Mi
380     \ifnum\outputpenalty > -\LT@end@pen
381       \LT@err{floats and marginpars not allowed in a longtable}\@ehc
382     \else
383       \setbox\z@\vbox{\unvbox\@cclv}%
384       \ifdim \ht\LT@lastfoot>\ht\LT@foot
385         \dimen@\pagegoal
386         \advance\dimen@-\ht\LT@lastfoot
387         \ifdim\dimen@<\ht\z@
388           \setbox\@cclv\vbox{\unvbox\z@\copy\LT@foot\vss}%
389           \@makecol
390           \@outputpage
391           \setbox\z@\vbox{\box\LT@head}%
392         \fi
393       \fi
394       \global\@colroom\@colht
395       \global\vsize\@colht
396       \vbox
397         {\unvbox\z@\box\ifvoid\LT@lastfoot\LT@foot\else\LT@lastfoot\fi}%
398     \fi
399   \else
400     \setbox\@cclv\vbox{\unvbox\@cclv\copy\LT@foot\vss}%
401     \@makecol
402     \@outputpage
403       \global\vsize\@colroom
404     \copy\LT@head\nobreak
405   \fi}
406 \def\LT@end@hd@ft#1{%
407   \LT@echunk
408   \ifx\LT@start\endgraf
409     \LT@err
410      {Longtable head or foot not at start of table}%
411      {Increase LTchunksize}%
412   \fi
413   \setbox#1\box\z@
414   \LT@get@widths
415   \LT@bchunk}
416 \def\endfirsthead{\LT@end@hd@ft\LT@firsthead}
417 \def\endhead{\LT@end@hd@ft\LT@head}
418 \def\endfoot{\LT@end@hd@ft\LT@foot}
419 \def\endlastfoot{\LT@end@hd@ft\LT@lastfoot}
420 \def\LT@startpbox#1{%
421   \bgroup
422     \let\@footnotetext\LT@p@ftntext
423     \setlength\hsize{#1}%
424     \@arrayparboxrestore
425     \vrule \@height \ht\@arstrutbox \@width \z@}
426 \def\LT@endpbox{%
427   \@finalstrut\@arstrutbox
428   \egroup
429   \the\LT@p@ftn
430   \global\LT@p@ftn{}%
431   \hfil}
432 \def\LT@p@ftntext#1{%
433   \edef\@tempa{\the\LT@p@ftn\noexpand\footnotetext[\the\c@footnote]}%
434   \global\LT@p@ftn\expandafter{\@tempa{#1}}}%
435 \endinput
436 %%
437 %% End of file `longtable.sty'.