summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/dblfloatfix/dblfloatfix.sty
blob: 63ae97d8668f9e1db5c04ed7f039d9b3c0f54e35 (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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
%% This is the LaTeX package dblfloatfix which solves two problems:
%%   a)~floats in a twocolumn document come out in the right order and
%%   b)~allowed float positions are now [tbp].
%%
%% It may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3c
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%    http://www.latex-project.org/lppl.txt
\ProvidesPackage{dblfloatfix}[2012/12/31 v1.0a (JAW)]
%%
%% USAGE:
%%
%% This package redefines internals of the LaTeX kernel by merging
%% the code of the packages fixltx2e (the fix2col part) and stfloats.
%%
%% If either of the packages stfloats or fix2col are loaded you will
%% get an error message and your document will probably not be able
%% to compile. So don't load them!
%%
%% When the new output routine for LaTeX3 is done, this package will
%% be obsolete. The sooner the better...
%%
%% If you're using the subfigure package this package will provide a
%% fix for \end@dblfloat by Steven Cochran (the author of subfigure).
%%
%% Morten H\o gholm, <moho0...@student.cbs.dk>
\RequirePackage{fixltx2e}
%% An error message for those who didn't read the instructions.
\newcommand*{\DBLFIXerrormessage}[1]{%
  \PackageError{dblfloatfix}{%
  Don't use the #1 package!^^J%
  Didn't you read the instructions in dblfloatfix.sty?!^^J%
  You're in big trouble now...^^J%
  Quit immediately (type `X') and correct the mistake}%
  {Type `X' dammit!}%
}
%% A check for those users who don't read manuals.
\AtBeginDocument{%
  \@ifpackageloaded{stfloats}{\DBLFIXerrormessage{stfloats}}{}%
  \@ifpackageloaded{fix2col}{\DBLFIXerrormessage{fix2col}}{}%
%% Here's a fix by Steven Douglas Cochran (the author of subfigure).
%% It is needed in order to make subfigure work with this package as
%% both packages redefine \end@dblfloat.
  \@ifpackageloaded{subfigure}{%
    \typeout{Redefining \string\end@dblfloat\ for use with subfigure}%
    \def\end@dblfloat{%
      \if@twocolumn
        \@listsubcaptions{\@captype}%
        \@endfloatbox
        \ifnum\@floatpenalty <\z@
          \@largefloatcheck
          \global\dp\@currbox1sp %
          \expandafter\@gobble\subfig@end@float
        \fi
      \else
        \end@float
      \fi}%
  }{}%
}
%% Here we go...
\def\@dblbotlist{}
\newcount\@dblbotnum
\newcounter{dblbotnumber}
\setcounter{dblbotnumber}{2}
\def\@dbflt#1{\@ifnextchar[{\@xdblfloat{#1}}{\@xdblfloat{#1}[tbp]}}

\def \@dblfloatplacement {%
  \global \@dbltopnum \c@dbltopnumber
  \global \@dblbotnum \c@dblbotnumber
  \global \@dbltoproom \dbltopfraction\@colht
  \@textmin \@colht
  \advance \@textmin -\@dbltoproom
  \@fpmin \dblfloatpagefraction\textheight
  \@fptop \@dblfptop
  \@fpsep \@dblfpsep
  \@fpbot \@dblfpbot
  \def\f@depth{1sp}%
}

\def\@addtodblcol{%
  \begingroup
  \@insertfalse
  \@setfloattypecounts
  \@getfpsbit \tw@
  \ifodd\@tempcnta
    \@flsetnum \@dbltopnum
    \ifnum \@dbltopnum>\z@
      \@tempswafalse
      \ifdim \@dbltoproom>\ht\@currbox
        \@tempswatrue
      \else
        \ifnum \@fpstype<\sixt@@n
          \advance \@dbltoproom \@textmin
          \ifdim \@dbltoproom>\ht\@currbox
            \@tempswatrue
          \fi
          \advance \@dbltoproom -\@textmin
        \fi
      \fi
      \if@tempswa
        \@bitor \@currtype \@deferlist
        \@testwrongwidth\@currbox
        \if@test
        \else
          \@bitor \@currtype \@dblbotlist
          \if@test
          \else
            \@tempdima -\ht\@currbox
            \advance\@tempdima
            -\ifx \@dbltoplist\@empty \dbltextfloatsep
            \else \dblfloatsep
            \fi
            \global \advance \@dbltoproom \@tempdima
            \global \advance \@colht \@tempdima
            \global \advance \@dbltopnum \m@ne
            \@cons \@dbltoplist \@currbox
            \@inserttrue
          \fi
        \fi
      \fi
    \fi
  \fi
  \if@insert
  \else
    \@getfpsbit 4\relax
      \ifodd\@tempcnta
        \@flsetnum \@dblbotnum
        \ifnum \@dblbotnum>\z@
          \@tempswafalse
          \ifdim \@dbltoproom>\ht\@currbox
            \@tempswatrue
          \else
            \ifnum \@fpstype<\sixt@@n
              \advance \@dbltoproom \@textmin
              \ifdim \@dbltoproom>\ht\@currbox
                \@tempswatrue
              \fi
              \advance \@dbltoproom -\@textmin
            \fi
          \fi
          \if@tempswa
            \@bitor \@currtype \@deferlist
	    % Test for twocolumn floats (2008/08/21 Mattias Nissler)
            \@testwrongwidth\@currbox
            \if@test
            \else
              \@tempdima -\ht\@currbox
              \advance\@tempdima
              -\ifx \@dblbotlist\@empty \dbltextfloatsep
              \else \dblfloatsep
              \fi
              \global \advance \@dbltoproom \@tempdima
              \global \advance \@colht \@tempdima
              \global \advance \@dblbotnum \m@ne
              \@cons \@dblbotlist \@currbox
              \@inserttrue
            \fi
          \fi
        \fi
      \fi
    \fi
      \if@insert
      \else
        \@cons\@deferlist\@currbox
      \fi
  \endgroup
}

\def\@combinedblfloats{%
    \ifx \@dbltoplist\@empty \else \@cdblflt \fi
    \ifx \@dblbotlist\@empty \else \@cdblflb \fi
}

\def\@cdblflt{%
    \setbox\@tempboxa \vbox{}%
    \let \@elt \@comdblflelt
    \@dbltoplist
    \let \@elt \relax
    \xdef \@freelist {\@freelist\@dbltoplist}%
    \global\let \@dbltoplist \@empty
    \setbox\@outputbox \vbox% to\textheight
      {%\boxmaxdepth\maxdepth   %% probably not needed, CAR
       \unvbox\@tempboxa\vskip-\dblfloatsep
       \ifnum \@dbltopnum>\m@ne
         \dblfigrule
       \fi
       \vskip \dbltextfloatsep
       \unvbox \@outputbox
       }%
}

\def\@cdblflb{%
    \setbox\@tempboxa \vbox{}%
    \let \@elt \@comdblflelt
    \@dblbotlist
    \let \@elt \relax
    \xdef \@freelist {\@freelist\@dblbotlist}%
    \global\let \@dblbotlist \@empty
    \setbox\@outputbox \vbox% to\textheight
      {%\boxmaxdepth\maxdepth   %% probably not needed, CAR
       \unvbox\@outputbox
       \vskip \dbltextfloatsep
       \ifnum \@dblbotnum>\m@ne
         \dblfigrule
       \fi
       \unvbox\@tempboxa
       \vskip -\dblfloatsep
       }%
}

\def \@doclearpage {%
  \ifvoid\footins
    \setbox\@tempboxa\vsplit\@cclv to\z@ \unvbox\@tempboxa
    \setbox\@tempboxa\box\@cclv
    \xdef\@deferlist{\@toplist\@botlist\@deferlist}%
    \global \let \@toplist \@empty
    \global \let \@botlist \@empty
    \global \@colroom \@colht
    \ifx \@currlist\@empty
    \else
      \@latexerr{Float(s) lost}\@ehb
      \global \let \@currlist \@empty
    \fi
    \@makefcolumn\@deferlist
    \@whilesw\if@fcolmade \fi{\@opcol\@makefcolumn\@deferlist}%
    \if@twocolumn
      \if@firstcolumn
        \xdef\@deferlist{\@dbltoplist\@dblbotlist\@deferlist}%
        \global \let \@dbltoplist \@empty
        \global \let \@dblbotlist \@empty
        \global \@colht \textheight
        \begingroup
          \@dblfloatplacement
          \@makefcolumn\@deferlist
          \@whilesw\if@fcolmade \fi{\@outputpage
                                    \@makefcolumn\@deferlist}%
        \endgroup
      \else
        \vbox{}\clearpage
      \fi
    \fi
    \ifx\@deferlist\@empty \else\clearpage \fi
  \else
    \setbox\@cclv\vbox{\box\@cclv\vfil}%
    \@makecol\@opcol
    \clearpage
  \fi
}

\endinput