This repository was archived by the owner on Jul 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfloatfig.sty
179 lines (179 loc) · 5.69 KB
/
floatfig.sty
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ref.: Thomas J. Reid , Floating Figures at the Right
% TUGboat Volume 8 (1987), No. 3 , p. 315
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% CAVEATs : - \everypar is set globally
% - the coupling to \LaTeX's figure apparatus is done by
% local definition of \@captype
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\message{*** FloatingFigure_Style Vers. 0.4, 08-MAY-1991, Kneser, GWDG ***}
\newenvironment{floatingfigure}[1]%
{% begin of 'begindef'
\expandafter\ifx\csname oldoutput\endcsname\relax% ref. TeXbook Ex.7.7
\typeout{* FLOATFIG * error: not initialized !}\@@end\fi
\global\everypar={\tryfig\oldeverypar}% must be set globally !
\global\advance\ffigcount by 1
\iffigprocessing
{\count0=\ffigcount\advance\count0 by -1
\message{* FLOATFIG * warning : Fl.-Figures \the\count0, \the\ffigcount
\space colliding !}%
}%
\fi
\def\@captype{figure}
\global\figprocessingtrue
\global\setbox\figbox=\vbox\bgroup% begin of figbox
\hrule height 0pt width #1 depth 0pt%
\hsize=#1%
}% end of 'begindef'
%
{% begin of 'enddef'
\egroup% end of \figbox
\figinsert\par%
}% end of 'enddef' of Floating_Figure_environment
%
\newbox\figbox
\newbox\pagebox
%
\newcount\ffigcount
\newcount\fftest
\newcount\hangcount
\newcount\nosuccesstryfig
%
\newdimen\figgutter \figgutter=1truepc
\newdimen\htdone \htdone=0pt
\newdimen\pageht
\newdimen\startpageht
%
\newif\iftryingfig \tryingfigfalse
\newif\ifdoingfig \doingfigfalse
\newif\iffigprocessing \figprocessingfalse
\newif\ifpageafterfig \pageafterfigfalse
\newif\ifoddpages
\newif\ifoutput
%
\newtoks\outputpretest
%
\def\initfloatingfigs{%
\message{** Make sure \string\initfloatingfigs\space being called immediately}
\message{\space\space\space after \string\begin{document} !! **}
\edef\oldoutput{\the\output}%
% ===== The modified output routine ======
\output={\the\outputpretest%
\ifoutput\oldoutput\fi}
\outputpretest={\outputtrue}
\edef\oldeverypar{\the\everypar}
}% end of \initfloatingfigs
%
% =====Controlling the figure placement
%
\def\dofigtest{%
% \message{DOFIGTEST entered +++++++++++++++++++++++++++++}%%$$%%
% \message{OUTPENALTY = \the\outputpenalty ++++++++++++++++++}%%$$%%
% \show\ifdoingfig%%$$%%
\ifnum\outputpenalty=-10005
\setbox\pagebox=\vbox{\unvbox255}%
\global\pageht=\ht\pagebox
\global\outputfalse
\unvbox\pagebox
\else
\global\outputtrue
\ifdoingfig
\global\pageafterfigtrue
\fi
\fi}%
% -----------
\def\tryfig{%
% \message{TRYFIG entered ++++++++++++++++++++++++++}%%$$%%
\iftryingfig% ------------ Section A
% \message{TRYFIG : Section A entered ++++++++++++++++++++++++++}%%$$%%
{\everypar={\relax}\setbox0=\lastbox%
\parindent=\wd0 \parskip=0pt \par%
\penalty-10005 \leavevmode}%
\dimen0=\vsize%
\advance\dimen0 by -\pageht%
\advance\dimen0 by -2\baselineskip%
\ifdim\dimen0>\ht\figbox%
\dimen0=0.3\baselineskip
\vrule depth \dimen0 width 0pt
\vadjust{\kern -\dimen0%
\vtop to \dimen0{%
\baselineskip=\dimen0%
\vss \vbox to 1ex{%
\ifodd\count0%
\hbox to \hsize{\hss\copy\figbox}%
\global\oddpagestrue
\else% leftsetting
\hbox to \hsize{\copy\figbox\hss}%
\global\oddpagesfalse
\fi% \ifodd\count0
\vss}\null}}%
\global\tryingfigfalse%
\global\doingfigtrue
\global\startpageht=\pageht
\global\htdone=0pt
\dohang
\ifnum\nosuccesstryfig>0%
\message{* FLOATFIG * Fl_fig. \the\ffigcount\space set on page
\the\count0, shifted \the\nosuccesstryfig\space par(s) forward}%
\else
\message{* FLOATFIG * Fl_fig. \the\ffigcount\space set on page
\the\count0}%
\fi
\else
\global\advance\nosuccesstryfig by 1
\fi
\else% ------------------- Section B
% \message{TRYFIG : Section B entered ++++++++++++++++++++++++++}%%$$%%
\ifdoingfig
{\everypar={\relax}\setbox0=\lastbox
\parindent=\wd0 \parskip=0pt \par
\penalty-10005 \leavevmode}%
\global\htdone=\pageht
\global\advance\htdone by -\startpageht
\ifpageafterfig
\global\doingfigfalse
\else
\dimen0=\ht\figbox%
\advance\dimen0 by 0.5\baselineskip%
\ifdim\htdone<\dimen0%
\dohang
\else
\global\doingfigfalse
\fi
\fi
\ifdoingfig\relax\else\global\figprocessingfalse\fi
\else% ----------------- Section C
% \message{TRYFIG : Section C entered ++++++++++++++++++++++++++}%%$$%%
\global\outputpretest={\outputtrue}%
\fi
\fi
}
% ---------------
\def\figinsert{%
% \message{FIGINSERT entered ++++++++++++++++++++++++++}%%$$%%
\global\nosuccesstryfig=0%
\global\outputpretest={\dofigtest}%
\global\tryingfigtrue \global\doingfigfalse%
\global\pageafterfigfalse}%
% --------------- %
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\dohang{%
\dimen0=\ht\figbox%
\advance\dimen0 by -\htdone%
\advance\dimen0 by 1.49\baselineskip%
\hangcount=\dimen0%
\divide\hangcount by \baselineskip%
\dimen0=\wd\figbox%
\advance\dimen0 by \figgutter%
\ifoddpages%
\global\hangafter=-\hangcount% placing right
\global\hangindent=-\dimen0%
\else% \ifleftsetting
\global\hangafter=-\hangcount% placing left
\global\hangindent=\dimen0%
\fi% \ifoddpages%
}% end of \dohang