| 1 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2 |
% INSBOX --- macros for inserting pictures into paragraphs % |
| 3 |
% Micha\l{} Gulczy\'nski, Szczecin, Jan 1996 / Feb 1998 % |
| 4 |
% [email protected] % |
| 5 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 6 |
% |
| 7 |
% version 2.2 |
| 8 |
% |
| 9 |
% available macros: |
| 10 |
% * \InsertBoxC{anybox} |
| 11 |
% insert a centered box (use int _inside_ a paragraph) |
| 12 |
% * \InsertBoxL{after_line}{anybox}[correction] |
| 13 |
% * \InsertBoxR{after_line}{anybox}[correction] |
| 14 |
% insert a box in the left/right after specified number of lines; |
| 15 |
% correction specified in square brackets is optional; |
| 16 |
% both macros should be called _before_ a paragraph |
| 17 |
% * \MoveBelowBox |
| 18 |
% start a new paragraph just below the current frame |
| 19 |
% |
| 20 |
% see the demo.tex file for more information |
| 21 |
% |
| 22 |
|
| 23 |
\catcode`\@ = 11 |
| 24 |
% |
| 25 |
% Margin between the text and the box: |
| 26 |
\newdimen\@InsertBoxMargin |
| 27 |
\@InsertBoxMargin = 2mm |
| 28 |
% |
| 29 |
% definition of \ParShape, an inproved version of plain \parshape |
| 30 |
% |
| 31 |
\newcount\@numlines % sum: m_1+...+m_n |
| 32 |
\newcount\@linesleft % counter used when reading lines of \ParShape |
| 33 |
\def\ParShape{% |
| 34 |
\@numlines = 0 |
| 35 |
\def\@parshapedata{ }% here we'll collect data for plain \parshape |
| 36 |
\afterassignment\@beginParShape |
| 37 |
\@linesleft |
| 38 |
}% |
| 39 |
\def\@beginParShape{% |
| 40 |
\ifnum \@linesleft = 0 |
| 41 |
\let\@whatnext = \@endParShape |
| 42 |
\else |
| 43 |
\let\@whatnext = \@readnextline |
| 44 |
\fi |
| 45 |
\@whatnext |
| 46 |
}% |
| 47 |
\def\@endParShape{% |
| 48 |
\global\parshape = \@numlines \@parshapedata |
| 49 |
}% |
| 50 |
\def\@readnextline#1 #2 #3 {% #1 #2 #3 are: m_i, leftskip_i, rightskip_i |
| 51 |
\ifnum #1 > 0 |
| 52 |
\bgroup % I want to keep changes of \dimen0 and \count0 local |
| 53 |
\dimen0 = \hsize |
| 54 |
\advance \dimen0 by -#2 % \parshape requires left skip and |
| 55 |
\advance \dimen0 by -#3 % _length_of_line_ (not right skip!) |
| 56 |
\count0 = 0 |
| 57 |
\loop |
| 58 |
\global\edef\@parshapedata{% |
| 59 |
\@parshapedata % add to \@parshapedata: |
| 60 |
#2 % left skip |
| 61 |
\space % a space |
| 62 |
\the\dimen0 % length of line |
| 63 |
\space % another space |
| 64 |
}% |
| 65 |
\advance \count0 by 1 |
| 66 |
\ifnum \count0 < #1 |
| 67 |
\repeat |
| 68 |
\egroup |
| 69 |
\advance \@numlines by #1 |
| 70 |
\fi |
| 71 |
\advance \@linesleft by -1 |
| 72 |
\@beginParShape |
| 73 |
}% |
| 74 |
% |
| 75 |
% \InsertBoxC, \InsertBoxL, \InsertBoxR |
| 76 |
% |
| 77 |
\newbox\@boxcontent % box containing the picture to be inserted |
| 78 |
\newcount\@numnormal % number of leading lines to typeset normally |
| 79 |
\newdimen\@framewidth % width of the frame |
| 80 |
\newdimen\@wherebottom % position of frame's bottom |
| 81 |
\newif\if@byframe % true if we are just beside the frame |
| 82 |
\@byframefalse |
| 83 |
% |
| 84 |
% |
| 85 |
\def\InsertBoxC#1{% |
| 86 |
\leavevmode |
| 87 |
\vadjust{ |
| 88 |
\vskip \@InsertBoxMargin |
| 89 |
\hbox to \hsize{\hss#1\hss} |
| 90 |
\vskip \@InsertBoxMargin |
| 91 |
}% |
| 92 |
}% |
| 93 |
\def\InsertBoxL#1#2{% |
| 94 |
\@numnormal = #1 |
| 95 |
\setbox\@boxcontent = \hbox{#2}% |
| 96 |
\let\@side = 0 |
| 97 |
\futurelet \@optionalparameter \@InsertBox |
| 98 |
} |
| 99 |
\def\InsertBoxR#1#2{% |
| 100 |
\@numnormal = #1 |
| 101 |
\setbox\@boxcontent = \hbox{#2}% |
| 102 |
\let\@side = 1 |
| 103 |
\futurelet \@optionalparameter \@InsertBox |
| 104 |
}% |
| 105 |
\def\@InsertBox{% |
| 106 |
\ifx \@optionalparameter [ |
| 107 |
\let\@whatnext = \@@InsertBoxCorrection |
| 108 |
\else |
| 109 |
\let\@whatnext = \@@InsertBoxNoCorrection |
| 110 |
\fi |
| 111 |
\@whatnext |
| 112 |
}% |
| 113 |
\def\@@InsertBoxCorrection[#1]{% |
| 114 |
\ifx \@side 0 |
| 115 |
\@@InsertBox{#1}{0}{{\the\@framewidth} 0cm}% |
| 116 |
\else |
| 117 |
\@@InsertBox{#1}{1}{0cm {\the\@framewidth}}% |
| 118 |
\fi |
| 119 |
}% |
| 120 |
\def\@@InsertBoxNoCorrection{% |
| 121 |
\@@InsertBoxCorrection[0]% |
| 122 |
}% |
| 123 |
\def\@@InsertBox#1#2#3{% |
| 124 |
\MoveBelowBox |
| 125 |
\@byframetrue |
| 126 |
% \@wherebottom = \pagetotal + (\@numnormal * \baselineskip) + |
| 127 |
% (height of \@boxcontent) + (2 * \@InsertBoxMargin) |
| 128 |
\@wherebottom = \baselineskip |
| 129 |
\multiply \@wherebottom by \@numnormal |
| 130 |
\advance \@wherebottom by 2\@InsertBoxMargin |
| 131 |
\advance \@wherebottom by \ht\@boxcontent |
| 132 |
\advance \@wherebottom by \pagetotal |
| 133 |
% I have no idea why, but \InsertBox called at the top of a page |
| 134 |
% calculates space for the box one line too big |
| 135 |
\ifdim \pagetotal = 0cm |
| 136 |
\advance \@wherebottom by -\baselineskip % ^ reduction |
| 137 |
\fi |
| 138 |
% add the correction |
| 139 |
\advance \@wherebottom by #1\baselineskip |
| 140 |
% \@framewidth = (width of \@boxcontent} + \@InsertboxMargin |
| 141 |
\@framewidth = \wd\@boxcontent |
| 142 |
\advance \@framewidth by \@InsertBoxMargin |
| 143 |
% |
| 144 |
\bgroup % to keep changes of \dimen0 local |
| 145 |
% check if the box fits in the page |
| 146 |
\ifdim \pagetotal = 0cm |
| 147 |
\dimen0 = \vsize |
| 148 |
\else |
| 149 |
\dimen0 = \pagegoal |
| 150 |
\fi |
| 151 |
\ifdim \@wherebottom > \dimen0 |
| 152 |
% print a warning message ... |
| 153 |
\immediate\write16{+--------------------------------------------------------------+}% |
| 154 |
\immediate\write16{| The box will not fit in the page. Please, re-edit your text. |}% |
| 155 |
\immediate\write16{+--------------------------------------------------------------+}% |
| 156 |
% ... and mark this place in document with a black box |
| 157 |
\vrule width \overfullrule |
| 158 |
\fi |
| 159 |
\egroup |
| 160 |
\prevgraf = 0 |
| 161 |
% insert the box in the left (if #2 = 0) or in the right (if #2 = 1) |
| 162 |
\vbox to 0cm{% |
| 163 |
\dimen0 = \baselineskip |
| 164 |
\multiply \dimen0 by \@numnormal |
| 165 |
\advance \dimen0 by -\baselineskip |
| 166 |
\setbox0 = \hbox{y}% |
| 167 |
\vskip \dp0 |
| 168 |
\vskip \dimen0 |
| 169 |
\vskip \@InsertBoxMargin |
| 170 |
\ifnum #2 = 1 |
| 171 |
\vtop{\noindent \hbox to \hsize{\hss \box\@boxcontent}}% |
| 172 |
\else |
| 173 |
\vtop{\noindent \box\@boxcontent}% |
| 174 |
\fi |
| 175 |
\vss |
| 176 |
}% |
| 177 |
% I have no idea why, but this is really necessary |
| 178 |
\vglue -\parskip |
| 179 |
\vskip -\baselineskip |
| 180 |
% each following paragraph needs to be formatted properly |
| 181 |
\everypar = {% |
| 182 |
% are we already below the bottom of the box? |
| 183 |
\ifdim \pagetotal < \@wherebottom |
| 184 |
% no... |
| 185 |
\bgroup % to keep some changes local |
| 186 |
% let's calculate parameters for \ParShape |
| 187 |
\dimen0 = \@wherebottom |
| 188 |
\advance \dimen0 by -\pagetotal |
| 189 |
\divide \dimen0 by \baselineskip |
| 190 |
\count1 = \dimen0 |
| 191 |
\advance \count1 by 1 |
| 192 |
\advance \count1 by -\@numnormal |
| 193 |
\ifnum #2 = 1 |
| 194 |
\ParShape = 3 |
| 195 |
{\the\@numnormal} 0cm 0cm |
| 196 |
{\the\count1} 0cm {\the\@framewidth} |
| 197 |
1 0cm 0cm |
| 198 |
\else |
| 199 |
\ParShape = 3 |
| 200 |
{\the\@numnormal} 0cm 0cm |
| 201 |
{\the\count1} {\the\@framewidth} 0cm |
| 202 |
1 0cm 0cm |
| 203 |
\fi |
| 204 |
\egroup |
| 205 |
\else |
| 206 |
% yes! |
| 207 |
\@restore@ % it's time to end everything |
| 208 |
\fi |
| 209 |
}% |
| 210 |
% this definition isn't very necessary --- just in case the paragraph |
| 211 |
% following \InsertBoxL or \InsertBoxR has fewer lines that the |
| 212 |
% first argument of the macro |
| 213 |
\def\par{% |
| 214 |
\endgraf |
| 215 |
\global\advance \@numnormal by -\prevgraf |
| 216 |
\ifnum \@numnormal < 0 |
| 217 |
\global\@numnormal = 0 |
| 218 |
\fi |
| 219 |
\prevgraf = 0 |
| 220 |
}% |
| 221 |
}% |
| 222 |
% |
| 223 |
% call this macro to move the current position just below the |
| 224 |
% current frame |
| 225 |
% |
| 226 |
\def\MoveBelowBox{% |
| 227 |
\par |
| 228 |
\if@byframe |
| 229 |
\global\advance \@wherebottom by -\pagetotal |
| 230 |
\ifdim \@wherebottom > 0cm |
| 231 |
\vskip \@wherebottom |
| 232 |
\fi |
| 233 |
\@restore@ |
| 234 |
\fi |
| 235 |
}% |
| 236 |
% |
| 237 |
% normal settings are as follows: |
| 238 |
% |
| 239 |
\def\@restore@{% |
| 240 |
\global\@wherebottom = 0cm |
| 241 |
\global\@byframefalse |
| 242 |
\global\everypar = {}% |
| 243 |
\global\let \par = \endgraf |
| 244 |
\global\parshape = 1 0cm \hsize |
| 245 |
}% |
| 246 |
% |
| 247 |
% someone told me that in LaTeX there is no \pageno counter; |
| 248 |
% the counterpart is \c@page |
| 249 |
% |
| 250 |
\ifx \documentclass \@Dont@Know@What@It@Is@ |
| 251 |
\else |
| 252 |
\let \pageno = \c@page |
| 253 |
\fi |
| 254 |
|
| 255 |
|
| 256 |
\catcode`\@ = 12 |