Debian Codegraph @

texmf-dist/source/latex/fix2col/fix2col.dtx

raw
1 % \iffalse
2 %% Source File: fix2col.dtx Copyright 1997 1998 David Carlisle
3 %%
4 %% This file may be distributed under the terms of the LPPL.
5 %% See 00readme.txt for details.
6 %
7 %<*dtx>
8 \ProvidesFile{fix2col.dtx}
9 %</dtx>
10 %<package>\NeedsTeXFormat{LaTeX2e}
11 %<package>\ProvidesPackage{fix2col}
12 %<driver> \ProvidesFile{fix2col.drv}
13 % \fi
14 % \ProvidesFile{fix2col.dtx}
15 [2015/11/13 v0.04 Output Routine fixes for two column mode (DPC,FMi)]
16 %
17 % \iffalse
18 %<*driver>
19 \documentclass{ltxdoc}
20 \begin{document}
21 \DocInput{fix2col.dtx}
22 \end{document}
23 %</driver>
24 % \fi
25 %
26 % \GetFileInfo{fix2col.dtx}
27 % \CheckSum{583}
28 %
29 % \changes{v0.01}{1997/11/07}
30 % {Initial version}
31 %
32 % \changes{v0.02}{1997/11/11}
33 % {\cs{@ztryfc}}
34 %
35 % \title{The \textsf{fix2col} package\thanks{This file
36 % has version number \fileversion, last
37 % revised \filedate.}}
38 % \author{David Carlisle\thanks{%^^A
39 % Part one is essentially a copy of the fixmarks package by
40 % Piet van Oostrum, itself based on earlier work by Joe Pallas.
41 % Part two is loosely based on the fixfloats package, originally
42 % by Ed Sznyter, with some modifications by Bil Kleb.}}
43 %
44 % \date{\filedate}
45 %
46 % \let\package\textsf
47 % \let\env\textsf
48 % \let\url\texttt
49 %
50 % \maketitle
51 %
52 % \section{Introduction}
53 %
54 % \textbf{Note:} This package is obsolete, the fixes described here are
55 % incorporated into \LaTeX\ formats from 2015/01/01 onwards.
56 %
57 % This package makes two independent changes to \LaTeX's two column
58 % output routine to fix the following two longstanding `features'.
59 %
60 % \begin{itemize}
61 % \item
62 % If the \TeX\ mark system is used (for example using the
63 % `headings' page style in the standard \LaTeX\ classes) then any marks
64 % that originate on the first column are `lost' as \LaTeX\ constructs
65 % the second column. An example document showing how this can result
66 % in incorrect page headings may be found in the latex bug database:\\
67 % \url{http://www.uni-mainz.de/cgi-bin/ltxbugs2html?pr=latex/2613}
68 %
69 % \item
70 % The second feature is documented in the \LaTeX\ book. By default
71 % \LaTeX\ does not attempt to keep double and single column floats in
72 % sequence, so if `Figure 1' is a double column float produced with
73 % |figure*|, then it may float
74 % after `Figure 2' if that is a single column, |figure|, float.
75 % Further correspondence about this may also be found in the
76 % bug database:\\
77 % \url{http://www.uni-mainz.de/cgi-bin/ltxbugs2html?pr=latex/2346}
78 % \end{itemize}
79 %
80 % \StopEventually{}
81 %
82 % \section{Notes on the Implementation Strategies}
83 %
84 % \subsection{Preserving Marks}
85 %
86 % The standard \LaTeX\ twocolumn system works internally by making
87 % each column a separate `page' that is passed independently to \TeX's
88 % pagebreaker. (Unlike say the \package{multicol} package, where all
89 % columns are gathered together and then split into columns later,
90 % using |\vsplit|.) This means that the primitive \TeX\ marks that are
91 % normally used for header information, are globally reset after the
92 % first column. By default \LaTeX\ does nothing about this.
93 % A good solution is provided by Piet van Oostrum (building on earlier
94 % work of Joe Pallas) in his \package{fixmarks} package.
95 %
96 % After the first column box has been collected the mark information
97 % for that box is saved, so that any |\firstmark| can be
98 % `artificially' used to set the page-level marks after the second
99 % column has been collected. (The second column |\firstmark| is not
100 % normally required.) Unfortunately \TeX\ does not provide a direct
101 % way of knowing if any marks are in the page, |\firstmark| always has a
102 % value from previous pages, even if there is no mark in this page.
103 % The solution is to make a copy of the box and then |\vsplit| it
104 % so that any marks show up as |\splitfirstmark|.
105 %
106 % The use of |\vsplit| does mean that the output routine will globally
107 % change the value of |\splitfirstmark| and
108 % |\splitbotmark|. The \package{fixmarks} package goes to some trouble
109 % to save and restore these values so that the output routine does
110 % \emph{not} change the values. This part of \package{fixmarks} is not
111 % copied here as it is quite costly (having to be run on every page) and
112 % there is no reason why anyone writing code using |\vsplit| should
113 % allow the output routine to be triggered before the split marks have
114 % been accessed.
115 %
116 % \subsection{Preserving Float Order}
117 %
118 % The standard output routine maintains two lists of floats that have
119 % been `deferred' for later consideration. One list for single column
120 % floats, and one for double column floats (which are always
121 % immediately put onto their deferred list). This mechanism means
122 % that \LaTeX\ `knows' which type of float is contained in each box
123 % by the list that it is processing, but having two lists means
124 % that there is no mechanism for preserving the order between the
125 % floats in each list.
126 %
127 % The solution to this problem consists of two small changes to
128 % the output routine.
129 %
130 % Firstly, abandon the `double column float list' |\@dbldeferlist|
131 % and change every command where it is used so that instead the
132 % same |\@deferlist| is used as for single column floats.
133 % That one change ensures that double and single column floats
134 % stay in the same sequence, but as \LaTeX\ no longer `knows'
135 % whether a float is double or single column, it will happily
136 % insert a double float into a single column, overprinting the
137 % other column, or the margin.
138 %
139 % The second change is to provide an alternative mechanism for
140 % recording the two column floats. \LaTeX\ already has a compact
141 % mechanism for recording float information, an integer count register
142 % assigned to each float records information about the `type' of float
143 % `figure', `table' and the position information `htp' etc.
144 %
145 % The type information is stored in the `high' bits, one bit position
146 % (above `32') allocated to each float type. The `low' bits store
147 % information about the allowed positions, one bit each allocated for
148 % |h t b p|. In the \LaTeX2.09 system, the bit corresponding to `16'
149 % formed a `boundary' between these two sets of information, and it
150 % was never actually used by the system. Ed Sznyter's
151 % \package{fixfloats} package not unreasonably used this position to
152 % store the double column information, setting the bit for double
153 % column floats. Then at each point in the output routine at which a
154 % float is committed to a certain region, an additional check must be
155 % made to check that the float is (or is not) double column. If it
156 % spans the wrong number of columns it is deferred rather than being
157 % added.
158 %
159 % Unfortunately the bit `16' is not available in \LaTeXe. It is used
160 % to encode the extra float position possibility `|!|' that was added
161 % in that system. It would be possible to use position `32' and to
162 % move the flags for `table', `figure',\ldots\ up one position, to
163 % start at 64, but this would mean that in principle one less float
164 % type would be supported, and more importantly is likely to break
165 % any other packages that assume anything about the output routine
166 % internals. So here I instead use another mechanism for flagging
167 % double column floats: By default all floats have depth 0pt.
168 % This package arranges that double column ones have depth 1sp.
169 % This information may then be used in the same manner as in
170 % the \package{fixfloats} package, to defer any floats that are not of
171 % the correct column spanning type.
172 %
173 % Use of the package showed that one also has to change the way
174 % \LaTeX{} handles star-form floats: if they are immediately deferred
175 % (as done normally) certain situations can still result in the float
176 % sequence getting out of order. This happens when a floats are placed
177 % in the middle of a paragraph. In that case the wide float is
178 % deferred immediately while a column wide float early on in the same
179 % paragraph might not be handled until the end of the paragraph when
180 % it is finally seen by the output routine. Since by that time the
181 % wide float is already on the |\@deferlist| the column float will
182 % also end up there (which is not only incorrect because it may have
183 % fitted onto the page but also because it is then placed at the end
184 % of this list). Version v0.03 now fixes this problem.
185 %
186 %
187 % \section{Implementation}
188 % \begin{macrocode}
189 %<*package>
190 % \end{macrocode}
191 %
192 % \subsection{Do nothing on current releases}
193 %
194 % \changes{v0.04}{2015/11/03}
195 % {Abort on new formats}
196 % \begin{macrocode}
197 \@ifl@t@r\fmtversion{2014/12/31}
198 {\PackageWarningNoLine{fix2col}{Obsolete package: ignored}\endinput}
199 {}
200 % \end{macrocode}
201 %
202 % \subsection{Preserving Marks}
203 %
204 % This is just a change to the single command |\@outputdblcol|
205 % so that it saves mark information for the first column and restores
206 % it in the second column.
207 % \begin{macrocode}
208 \def\@outputdblcol{%
209 \if@firstcolumn
210 \global\@firstcolumnfalse
211 % \end{macrocode}
212 % Save the left column
213 % \begin{macrocode}
214 \global\setbox\@leftcolumn\copy\@outputbox
215 % \end{macrocode}
216 %
217 % Remember the marks from the first column
218 % \begin{macrocode}
219 \splitmaxdepth\maxdimen
220 \vbadness\maxdimen
221 \setbox\@outputbox\vsplit\@outputbox to\maxdimen
222 % \end{macrocode}
223 %
224 % One minor difference from the current \package{fixmarks}, pass the
225 % marks through a token register to stop any |#| tokens causing an
226 % error in a |\def|.
227 % \begin{macrocode}
228 \toks@\expandafter{\topmark}%
229 \xdef\@firstcoltopmark{\the\toks@}%
230 \toks@\expandafter{\splitfirstmark}%
231 \xdef\@firstcolfirstmark{\the\toks@}%
232 % \end{macrocode}
233 %
234 % This test does not work if truly empty marks have been inserted, but
235 % \LaTeX\ marks should always have (at least) two brace groups.
236 % (Except before the first mark is used, when the marks are empty,
237 % but that is OK here.)
238 % \begin{macrocode}
239 \ifx\@firstcolfirstmark\@empty
240 \global\let\@setmarks\relax
241 \else
242 \gdef\@setmarks{%
243 \let\firstmark\@firstcolfirstmark
244 \let\topmark\@firstcoltopmark}%
245 \fi
246 % \end{macrocode}
247 %
248 % End of change
249 % \begin{macrocode}
250 \else
251 \global\@firstcolumntrue
252 \setbox\@outputbox\vbox{%
253 \hb@xt@\textwidth{%
254 \hb@xt@\columnwidth{\box\@leftcolumn \hss}%
255 \hfil
256 \vrule \@width\columnseprule
257 \hfil
258 \hb@xt@\columnwidth{\box\@outputbox \hss}}}%
259 \@combinedblfloats
260 % \end{macrocode}
261 % Override current first and top with those of first column if necessary
262 % \begin{macrocode}
263 \@setmarks
264 % \end{macrocode}
265 % End of change
266 % \begin{macrocode}
267 \@outputpage
268 \begingroup
269 \@dblfloatplacement
270 \@startdblcolumn
271 \@whilesw\if@fcolmade \fi{\@outputpage\@startdblcolumn}%
272 \endgroup
273 \fi}
274 % \end{macrocode}
275 %
276 % \subsection{Preserving Float Order}
277 %
278 % Changes |\@dbldeferlist| to |\@deferlist| are not explicitly noted
279 % but are flagged by blank comment lines around the changed line.
280 %
281 %
282 % \begin{macrocode}
283 \def\end@dblfloat{%
284 \if@twocolumn
285 \@endfloatbox
286 \ifnum\@floatpenalty <\z@
287 \@largefloatcheck
288 % \end{macrocode}
289 %
290 % Force the depth of two column float boxes.
291 % \begin{macrocode}
292 \global\dp\@currbox1sp %
293 % \end{macrocode}
294 %
295 % \changes{v0.03}{1998/08/17}{FMi: use output routine to
296 % defer float}
297 % Next line assumes that first token of |\end@float| is
298 % |\@endfloatbox| so we gobble that.
299 % \begin{macrocode}
300 % \@cons\@deferlist\@currbox
301 \expandafter\@gobble\end@float
302 % \end{macrocode}
303 % |\@Esphack| is then added by |\@endfloat| above.
304 % \begin{macrocode}
305 \fi
306 % \ifnum \@floatpenalty =-\@Mii \@Esphack\fi
307 \else
308 \end@float
309 \fi
310 }
311 % \end{macrocode}
312 %
313 % Test if the float box has the wrong width. (Actually as noted above
314 % the test is for a conventional depth setting rather than for the
315 % width of the float).
316 % \begin{macrocode}
317 \def\@testwrongwidth #1{%
318 \ifdim\dp#1=\f@depth
319 \else
320 \global\@testtrue
321 \fi}
322 % \end{macrocode}
323 %
324 % Normally looking for single column floats, which have zero depth.
325 % \begin{macrocode}
326 \let\f@depth\z@
327 % \end{macrocode}
328 %
329 % but when making two column float area, look for floats with 1sp
330 % depth.
331 % \begin{macrocode}
332 \def\@dblfloatplacement{\global\@dbltopnum\c@dbltopnumber
333 \global\@dbltoproom \dbltopfraction\@colht
334 \@textmin \@colht
335 \advance \@textmin -\@dbltoproom
336 \@fpmin \dblfloatpagefraction\textheight
337 \@fptop \@dblfptop
338 \@fpsep \@dblfpsep
339 \@fpbot \@dblfpbot
340 % \end{macrocode}
341 %
342 % \begin{macrocode}
343 \def\f@depth{1sp}}
344 % \end{macrocode}
345 %
346 % All the remaining changes are replacing the double column defer list
347 % or insering the extra test |\@testwrongwidth|\marg{box} at suitable
348 % places. That is at plces where a box is taken off the deferlist.
349 % \begin{macrocode}
350 \def \@doclearpage {%
351 \ifvoid\footins
352 \setbox\@tempboxa\vsplit\@cclv to\z@ \unvbox\@tempboxa
353 \setbox\@tempboxa\box\@cclv
354 \xdef\@deferlist{\@toplist\@botlist\@deferlist}%
355 \global \let \@toplist \@empty
356 \global \let \@botlist \@empty
357 \global \@colroom \@colht
358 \ifx \@currlist\@empty
359 \else
360 \@latexerr{Float(s) lost}\@ehb
361 \global \let \@currlist \@empty
362 \fi
363 \@makefcolumn\@deferlist
364 \@whilesw\if@fcolmade \fi{\@opcol\@makefcolumn\@deferlist}%
365 \if@twocolumn
366 \if@firstcolumn
367 % \end{macrocode}
368 %
369 % \begin{macrocode}
370 \xdef\@deferlist{\@dbltoplist\@deferlist}%
371 % \end{macrocode}
372 %
373 % \begin{macrocode}
374 \global \let \@dbltoplist \@empty
375 \global \@colht \textheight
376 \begingroup
377 \@dblfloatplacement
378 % \end{macrocode}
379 %
380 % \begin{macrocode}
381 \@makefcolumn\@deferlist
382 \@whilesw\if@fcolmade \fi{\@outputpage
383 \@makefcolumn\@deferlist}%
384 % \end{macrocode}
385 %
386 % \begin{macrocode}
387 \endgroup
388 \else
389 \vbox{}\clearpage
390 \fi
391 \fi
392 % \end{macrocode}
393 % the next line is needed to avoid losing floats in certain
394 % circumstances a single call to the original |\doclearpage|
395 % will now no longer output all floats.
396 % \changes{v0.03}{1998/08/17}{FMi: ensure \cs{doclearpage} is called again
397 % until all floats are output}
398 % \begin{macrocode}
399 \ifx\@deferlist\@empty \else\clearpage \fi
400 \else
401 \setbox\@cclv\vbox{\box\@cclv\vfil}%
402 \@makecol\@opcol
403 \clearpage
404 \fi
405 }
406 % \end{macrocode}
407 %
408 % \begin{macrocode}
409 \def \@startdblcolumn {%
410 \@tryfcolumn \@deferlist
411 \if@fcolmade
412 \else
413 \begingroup
414 \let \reserved@b \@deferlist
415 \global \let \@deferlist \@empty
416 \let \@elt \@sdblcolelt
417 \reserved@b
418 \endgroup
419 \fi
420 }
421 % \end{macrocode}
422 %
423 % \begin{macrocode}
424 \def\@addtonextcol{%
425 \begingroup
426 \@insertfalse
427 \@setfloattypecounts
428 \ifnum \@fpstype=8
429 \else
430 \ifnum \@fpstype=24
431 \else
432 \@flsettextmin
433 \@reqcolroom \ht\@currbox
434 \advance \@reqcolroom \@textmin
435 \ifdim \@colroom>\@reqcolroom
436 \@flsetnum \@colnum
437 \ifnum\@colnum>\z@
438 \@bitor\@currtype\@deferlist
439 \@testwrongwidth\@currbox
440 \if@test
441 \else
442 \@addtotoporbot
443 \fi
444 \fi
445 \fi
446 \fi
447 \fi
448 \if@insert
449 \else
450 \@cons\@deferlist\@currbox
451 \fi
452 \endgroup
453 }
454 % \end{macrocode}
455 %
456 % \begin{macrocode}
457 \def\@addtodblcol{%
458 \begingroup
459 \@insertfalse
460 \@setfloattypecounts
461 \@getfpsbit \tw@
462 \ifodd\@tempcnta
463 \@flsetnum \@dbltopnum
464 \ifnum \@dbltopnum>\z@
465 \@tempswafalse
466 \ifdim \@dbltoproom>\ht\@currbox
467 \@tempswatrue
468 \else
469 \ifnum \@fpstype<\sixt@@n
470 \advance \@dbltoproom \@textmin
471 \ifdim \@dbltoproom>\ht\@currbox
472 \@tempswatrue
473 \fi
474 \advance \@dbltoproom -\@textmin
475 \fi
476 \fi
477 \if@tempswa
478 \@bitor \@currtype \@deferlist
479 % \end{macrocode}
480 %
481 % not in fixfloats?
482 % \begin{macrocode}
483 \@testwrongwidth\@currbox
484 % \end{macrocode}
485 %
486 % \begin{macrocode}
487 \if@test
488 \else
489 \@tempdima -\ht\@currbox
490 \advance\@tempdima
491 -\ifx \@dbltoplist\@empty \dbltextfloatsep \else
492 \dblfloatsep \fi
493 \global \advance \@dbltoproom \@tempdima
494 \global \advance \@colht \@tempdima
495 \global \advance \@dbltopnum \m@ne
496 \@cons \@dbltoplist \@currbox
497 \@inserttrue
498 \fi
499 \fi
500 \fi
501 \fi
502 \if@insert
503 \else
504 \@cons\@deferlist\@currbox
505 \fi
506 \endgroup
507 }
508 % \end{macrocode}
509 %
510 % \begin{macrocode}
511 \def \@addtocurcol {%
512 \@insertfalse
513 \@setfloattypecounts
514 \ifnum \@fpstype=8
515 \else
516 \ifnum \@fpstype=24
517 \else
518 \@flsettextmin
519 \advance \@textmin \@textfloatsheight
520 \@reqcolroom \@pageht
521 \ifdim \@textmin>\@reqcolroom
522 \@reqcolroom \@textmin
523 \fi
524 \advance \@reqcolroom \ht\@currbox
525 \ifdim \@colroom>\@reqcolroom
526 \@flsetnum \@colnum
527 \ifnum \@colnum>\z@
528 \@bitor\@currtype\@deferlist
529 % \end{macrocode}
530 % We need to defer the float also if its width
531 % doesn't fit.
532 % \changes{v0.03}{1998/08/17}{FMi: test for wide float was
533 % in wrong place}
534 % \begin{macrocode}
535 \@testwrongwidth\@currbox
536 % \end{macrocode}
537 %
538 % \begin{macrocode}
539 \if@test
540 \else
541 \@bitor\@currtype\@botlist
542 \if@test
543 \@addtobot
544 \else
545 \ifodd \count\@currbox
546 \advance \@reqcolroom \intextsep
547 \ifdim \@colroom>\@reqcolroom
548 \global \advance \@colnum \m@ne
549 \global \advance \@textfloatsheight \ht\@currbox
550 \global \advance \@textfloatsheight 2\intextsep
551 \@cons \@midlist \@currbox
552 \if@nobreak
553 \nobreak
554 \@nobreakfalse
555 \everypar{}%
556 \else
557 \addpenalty \interlinepenalty
558 \fi
559 \vskip \intextsep
560 \box\@currbox
561 \penalty\interlinepenalty
562 \vskip\intextsep
563 \ifnum\outputpenalty <-\@Mii \vskip -\parskip\fi
564 \outputpenalty \z@
565 \@inserttrue
566 \fi
567 \fi
568 \if@insert
569 \else
570 \@addtotoporbot
571 \fi
572 \fi
573 \fi
574 \fi
575 \fi
576 \fi
577 \fi
578 \if@insert
579 \else
580 \@resethfps
581 \@cons\@deferlist\@currbox
582 \fi
583 }
584 % \end{macrocode}
585 %
586 % \begin{macrocode}
587 \def\@xtryfc #1{%
588 \@next\reserved@a\@trylist{}{}%
589 \@currtype \count #1%
590 \divide\@currtype\@xxxii
591 \multiply\@currtype\@xxxii
592 \@bitor \@currtype \@failedlist
593 \@testfp #1%
594 % \end{macrocode}
595 %
596 % \begin{macrocode}
597 \@testwrongwidth #1%
598 % \end{macrocode}
599 %
600 % \begin{macrocode}
601 \ifdim \ht #1>\@colht
602 \@testtrue
603 \fi
604 \if@test
605 \@cons\@failedlist #1%
606 \else
607 \@ytryfc #1%
608 \fi}
609 % \end{macrocode}
610 %
611 % \begin{macrocode}
612 \def\@ztryfc #1{%
613 \@tempcnta\count #1%
614 \divide\@tempcnta\@xxxii
615 \multiply\@tempcnta\@xxxii
616 \@bitor \@tempcnta {\@failedlist \@flfail}%
617 \@testfp #1%
618 % \end{macrocode}
619 %
620 % not in fixfloats?
621 % \begin{macrocode}
622 \@testwrongwidth #1%
623 % \end{macrocode}
624 %
625 % \begin{macrocode}
626 \@tempdimb\@tempdima
627 \advance\@tempdimb\ht #1%
628 \advance\@tempdimb\@fpsep
629 \ifdim \@tempdimb >\@colht
630 \@testtrue
631 \fi
632 \if@test
633 \@cons\@flfail #1%
634 \else
635 \@cons\@flsucceed #1%
636 \@tempdima\@tempdimb
637 \fi}
638 % \end{macrocode}
639 %
640 % \begin{macrocode}
641 %</package>
642 % \end{macrocode}
643 %
644 % \Finale
645 %