Debian Codegraph @

texmf-dist/tex/latex/picinpar/picinpar.sty

raw
1 \typeout{%
2 Pictures in Paragraphs. Version 1.3a, November 2, 2025}
3 % This is picinpar.sty version 1.3a as of November 2, 2025
4 % Macros for making windows with LaTeX
5 %
6 % By Friedhelm Sowa, Heinrich-Heine-University D\"usseldorf,
7 % Computing Center
8 % In case of emergency try to get the email adress
9 % after having checked the input :-)
10 % Okay, for those who are too lazy:
11 % [email protected]
12 % Updated for LaTeX2e 2025-11-01 by David Carlisle at
13 % https://github.com/LaTeX-Package-Repositories/picinpar/
14 %
15 % Distributed under the terms of the GNU General Public License.
16 % This program is free software; you can redistribute it and/or
17 % modify it under the terms of the GNU General Public License as
18 % published by the Free Software Foundation; either version 2, or (at your
19 % option) any later version.
20 %
21 % Incorporated are basic ideas of Alan Hoenig (Thanks Alan!)
22 % Thanks to Phil Taylor, who gave some useful hints during his
23 % tutorial at the EURO TeX 92 in Prague.
24 %
25 % Also thanks to Ulrik Vieth, who incorporated the macros for
26 % generating captions within the windows.
27 %
28 %----------------
29 % Known problems:
30 %
31 % - Don't use \samepage
32 % - Use \footnotemark within and \footnotetext outside the
33 % window-environment instead of \footnote
34 % - When using the epic-package load picinpar before epic
35 % like \documentstyle[...,picinpar,epic]{...}
36 %----------------
37 % Changes:
38 %
39 % 1.1 If \brokenpenalty\maxdimen then it's set to 9999 within the
40 % window's group
41 %
42 % Reported by [email protected]
43 %
44 % 1.2 When centering a window and the right column contains less
45 % lines than the left column then the right lines are raised
46 % by using \vfill
47 %
48 % Reported by Wolfgang Riedel, TU Chemnitz
49 %
50 % 1.2a A better way to shift the right box. There was some trouble
51 % when the window is on the left. I don't know why I didn't
52 % notice TeX's overfull \vbox
53 %
54 % Reported by Stephan Seidl, [email protected]
55
56 %
57 % 1.3 An option to insert the picture/table without a caption (Argument #4 in \figwindow[.., #4] or \tabwindow[.., #4] is empty.
58 % see https://tex.stackexchange.com/questions/656810/using-if-with-an-empty-argument
59 %
60 %
61 % Changed by Stefan Blochwitz, [email protected]
62 %
63 % 1.3a Update to end vertical mode with \endgraf for LaTeX2e 2025-11-01
64 %
65 % Here we go
66 %
67 % Counts
68 \newcount\br
69 \newcount\bl
70 \newcount\na
71 \newcount\nb
72 \newcount\tcdsav
73 \newcount\tcl
74 \newcount\tcd
75 \newcount\tcn
76 \newcount\cumtcl
77 \newcount\cumpartcl
78 % Dimens
79 \newdimen\lftside
80 \newdimen\rtside
81 \newdimen\hpic
82 \newdimen\vpic
83 \newdimen\strutilg
84 \newdimen\picwd
85 \newdimen\topheight
86 \newdimen\ilg
87 \newdimen\lpic
88 \newdimen\lwindowsep \newdimen\rwindowsep % VK 10 Feb 93
89 \lwindowsep0.5\baselineskip % "
90 \rwindowsep0.5\baselineskip % "
91 \newdimen\cumpar
92 % Tokens
93 \newtoks\twa
94 \newtoks\la
95 \newtoks\ra
96 \newtoks\ha
97 \newtoks\pictoc
98 % Boxes
99 \newbox\rawtext
100 \newbox\holder
101 \newbox\windowbox
102 \newbox\wartext
103 \newbox\finaltext
104 \newbox\aslice
105 \newbox\bslice
106 \newbox\wbox
107 \newbox\wstrutbox
108 \newbox\picbox
109 \newbox\waslice
110 \newbox\wbslice
111 \newbox\fslice
112 % Another strut
113 \def\wstrut{\relax\ifmmode\copy\wstrutbox\else\unhcopy\wstrutbox\fi}
114 %
115 \long\def\window[#1,#2,#3,#4] {%
116 % #1 is an integer---no. of lines down from par top
117 % #2 is l, r or c what means left, right or centered
118 % default is, that the picture is printed at the left side
119 % #3 is the material for setting a graphic box
120 % #4 is the explanation for the graphic (if empty, then no caption)
121 \vskip\parskip\everypar{}
122 \global\cumpar=0pt
123 \global\cumpartcl=0
124 \global\cumtcl=0
125 \tcd=#1
126 \lftside=0pt \rtside=0pt
127 % \hpic=\linewidth
128 \twa={} \la={} \ra={} \ha={}
129 \setbox\wbox=\hbox{(}
130 \computeilg
131 \pictoc={#3}
132 \setbox\windowbox=\vbox{\hbox{#3}}
133 \setbox\wbox=\vbox{\hbox{\noindent#4}}
134 %\setbox\wbox=\vbox{\hbox{\noindent#4}}
135 \picwd=\wd\windowbox
136 \hpic=\picwd
137 \vpic=\ht\windowbox\advance\vpic\dp\windowbox
138 \if #2c\lftside=\linewidth\advance\lftside-\picwd\rtside=0.5\lftside
139 \lftside=\rtside
140 \else \if #2r\lftside=\linewidth\advance\lftside-\picwd
141 \rtside=0pt
142 \else\rtside=\linewidth\advance\rtside-\picwd
143 \lftside=0pt
144 \fi
145 \fi
146 %
147 % In case of a centered picture, that does not allow text beside
148 % we have to add some glue between preceding text, window and
149 % following text.
150 %
151 \if #2c
152 \ifdim\rtside<72pt
153 \rtside=0pt\lftside=0pt
154 \setbox\windowbox=\vbox{%
155 \hrule width\picwd height0pt depth0pt
156 \vskip.5\parskip\box\windowbox\vskip.5\parskip
157 \hrule width\picwd height0pt depth0pt}
158 \vpic=\ht\windowbox\advance\vpic\dp\windowbox
159 \fi
160 \parskip0pt % Within the window area a \parskip>0pt may look ugly
161 \fi
162 \ifnum\picwd=0\setbox\picbox=\vbox{\hbox{\noindent#4}} % without picture
163 \hpic=\wd\picbox % calculate dimensions
164 \ifnum\lftside=0\rtside=\linewidth\advance\rtside-\hpic
165 \else\ifnum\rtside=0\lftside=\linewidth\advance\lftside-\hpic
166 \else\rtside=0.5\linewidth\advance\rtside-0.5\hpic
167 \lftside=\rtside
168 \fi\fi
169 \else\setbox\picbox=\vbox{\hsize=\hpic\vbox to\vpic{\box\windowbox\vfill}%
170 \ifdim\ht\wbox>0pt\vskip\ilg\vbox{\hsize=\hpic\noindent#4
171 %
172 % See above, this is the second part of glue
173 %
174 \if #2c
175 \ifdim\rtside=0pt \ifdim\lftside=0pt
176 \vskip\parskip\hrule width\hpic height0pt depth0pt
177 \fi \fi
178 \fi
179 }
180 \fi}\fi
181 \vpic=\ht\picbox\advance\vpic\dp\picbox
182 %\ifdim\lftside>0pt\advance\lftside-0.5\baselineskip\fi % put in a distance
183 %\ifdim\rtside>0pt\advance\rtside-0.5\baselineskip\fi % between text and
184 % % window
185 \ifdim\lftside>0pt\advance\lftside-\lwindowsep\fi % VK 10 Feb 93
186 \ifdim\rtside>0pt\advance\rtside-\rwindowsep\fi % "
187 \global\br=\rtside \global\bl=\lftside
188 \ifnum\picwd=0
189 \ifdim\vpic>0pt\picwd=\hpic
190 \else\vpic=\ht\picbox\advance\vpic\dp\picbox
191 \fi
192 \fi
193 \global\tcl=0 \lpic=0pt
194 \loop\global\advance\tcl by 1 \lpic=\tcl\baselineskip
195 \ifdim\lpic<\vpic\repeat
196 \vpic=\lpic
197 \global\cumtcl=\tcl
198 %
199 % Here we know exactly the number of indented lines and
200 % are able to generate the tokens for the \parshape list
201 %
202 \ifnum\bl>0\la={ 0pt \lftside}\fi
203 \ifnum\br>0\ra={ 0pt \rtside}\fi
204 \ifnum\tcd>0\ha={ 0pt \linewidth}\fi
205 \ifnum\tcl<1\global\tcl=1\fi
206 \createparshapespec
207 \tcd=#1 % restore the lintel
208 \global\tcdsav=#1
209 %
210 % This is a very tricky part of the package. Some day there
211 % will exist a detailed documentation.
212 %
213 \ifdim\parskip>0pt
214 \def\par{\hfill\vadjust{\vskip0pt\vbox to\parskip{\vss}}
215 \global\advance\cumpartcl by 1
216 \global\advance\cumpar by \parskip
217 \global\lpic=\ht\wstrutbox
218 \global\advance\lpic by \dp\wstrutbox
219 \ifdim\cumpar<\lpic
220 \else\advance\cumpar by -\lpic
221 \advance\cumtcl by -1
222 \fi
223 \endgraf % ensure vertical mode ends, even if \partokencontext is set
224 \egroup\global\tcd=\tcdsav
225 \setbox\wartext=\vbox{\unvbox\rawtext}
226 \setbox\rawtext=\vbox\bgroup
227 \clubpenalty=0\widowpenalty=0
228 \ifnum\brokenpenalty<\maxdimen\else\brokenpenalty=9999\fi
229 \tolerance=1000
230 \global\lpic=\ht\wstrutbox
231 \global\advance\lpic by \dp\wstrutbox
232 %
233 % Pick up header lines
234 %
235 \ifnum\tcd>0\vbadness=10000\splittopskip0pt
236 \loop\setbox\holder=\vsplit\wartext to \lpic
237 \hpic=\wd\holder\prune\holder\hpic
238 \ifdim\ht\holder=\parskip
239 \hbox{\vrule height\parskip width0pt depth0pt}
240 \typeout{A paragraph ended within headlines! Please change }
241 \typeout{the number of headlines for the window environment!}
242 \global\advance\tcd by -1
243 \else\hbox{\vbox{\box\holder\unskip}}
244 \global\advance\tcd by -1
245 \fi
246 \ifnum\tcd>0\repeat
247 \global\tcd=0
248 \ifdim\ht\wartext>0pt
249 \ifdim\ht\wartext=\parskip\global\advance\tcdsav by 1
250 \setbox\holder=\vsplit\wartext to \lpic
251 \hbox{\vrule height\parskip width0pt depth0pt}
252 \global\advance\cumpar by -\parskip
253 \global\advance\cumpartcl by -1
254 \fi\fi
255 \fi
256 %
257 % Pick up lines beside window, the rest too
258 %
259 \global\tcn=0
260 \topheight=0pt
261 \ifdim\ht\wartext>0pt\vbadness=10000\splittopskip0pt
262 \loop\setbox\holder=\vsplit\wartext to \lpic
263 \hpic=\wd\holder\prune\holder\hpic
264 \ifdim\ht\holder=\parskip
265 \hbox{\vrule height\parskip width0pt depth0pt}
266 \global\advance\topheight by \parskip
267 \else
268 \setbox\fslice=\hbox{\box\holder}
269 \hpic=\ht\fslice
270 \advance\hpic by\dp\fslice
271 \ifdim\hpic>\lpic
272 \global\advance\topheight by\hpic
273 \hbox{\vbox{\box\fslice\vss}}
274 \else\ifdim\hpic=0pt\relax
275 \else\global\advance\topheight by \lpic
276 \hbox{\vbox{\box\fslice}}\fi\fi
277 \fi
278 \ifdim\ht\wartext>0pt\repeat
279 \tcn=0
280 \loop\advance\tcn by 1
281 \advance\topheight by -\lpic
282 \ifdim\topheight>0pt\repeat
283 \hpic=\topheight
284 \ifdim\hpic<0pt\advance\tcn by -1\fi
285 \global\topheight=\tcn\lpic
286 \fi
287 %
288 % If the indented part is not completed we have to generate a
289 % new token for the \parshape list
290 %
291 \ifnum\tcn<\cumtcl
292 \global\tcl=\cumtcl
293 \global\advance\topheight by\cumpartcl\parskip
294 \global\advance\tcl by -\tcn \global\twa={}
295 \ifnum\tcl>0
296 \global\vpic=\topheight
297 \global\topheight=\tcl\lpic
298 \global\advance\vpic by \topheight
299 \global\advance\vpic by \lpic
300 \createparshapespec
301 \parshape=\tcn \the\twa
302 \else\parshape=0
303 \fi
304 \else\parshape=0\fi}
305 \else\def\par{\\}
306 \fi % new definition of \par in case of \parskip>0 ends here
307 %
308 % This is where we start to pick up the paragraph(s)
309 %
310 \setbox\rawtext=\vbox\bgroup\unvbox\rawtext\unskip
311 \clubpenalty=0\widowpenalty=0
312 \ifnum\brokenpenalty<\maxdimen\else\brokenpenalty=9999\fi
313 \tolerance=1000
314 \parshape=\tcn \the\twa }
315 %
316 \def\endwindow{%
317 \global\tcd=\tcdsav
318 \endgraf % ensure vertical mode ends, even if \partokencontext is set
319 \egroup\vskip\parskip\parshape=0 % reset parshape; end \box\rawtext
320 \vbadness=10000
321 \splittopskip=0pt
322 %
323 % Typeset the lines above the window
324 %
325 \ifnum\tcd>0\setbox\holder=\vsplit\rawtext to \tcd\baselineskip
326 \tcn=\tcd
327 \loop\advance\tcn -1
328 \setbox\fslice=\vsplit\holder to\baselineskip
329 \prune\fslice\linewidth
330 \topheight=0pt
331 \ifnum\dp\fslice>\dp\wstrutbox
332 \advance\topheight-\dp\fslice
333 \advance\topheight\dp\wstrutbox
334 \advance\topheight\ilg\fi
335 \hbox to\linewidth{\box\fslice}
336 \vskip-\topheight
337 \ifdim\ht\holder>0pt\repeat
338 \fi
339 %
340 % Now we build the boxes beside the window
341 %
342 \global\topheight=\tcl\baselineskip
343 \ifnum\cumpartcl>0\global\tcl=\cumtcl
344 \global\topheight=\vpic
345 \fi
346 \ifnum\bl>0 \ifnum\br>0 \multiply\topheight by 2\fi\fi
347 \ifnum\bl>0\setbox\holder=\vsplit\rawtext to\topheight
348 \else\ifnum\br>0\setbox\holder=\vsplit\rawtext to\topheight\fi\fi
349 \tcn=\tcl \na=0 \nb=0
350 \ifnum\bl>0 \ifnum\br>0 \multiply\tcn by 2\fi\fi
351 \ifnum\bl>0\na=\tcn\ifnum\br>0\divide\na by 2\fi\fi
352 \ifnum\br>0\nb=\tcn\ifnum\bl>0\divide\nb by 2\fi\fi
353 \ifnum\na=0\ifnum\nb=0
354 \setbox\waslice=\vbox to\vpic{\vss}
355 \setbox\wbslice=\vbox to\vpic{\vss}
356 \bl=1\br=1
357 \vskip\ilg
358 \fi\fi
359 %
360 % both sides
361 %
362 \ifnum\na>0 \ifnum\nb>0
363 \loop\advance\nb -1
364 \advance\na -1
365 \setbox\aslice=\vsplit\holder to\baselineskip
366 \prune\aslice\lftside
367 \setbox\waslice=\vbox{\unvbox\waslice\hbox
368 to\lftside{\box\aslice\hfil}}
369 \setbox\bslice=\vsplit\holder to\baselineskip
370 \prune\bslice\rtside
371 \setbox\wbslice=\vbox{\unvbox\wbslice\hbox
372 to\rtside{\box\bslice\hfil}}
373 \ifnum\nb>0\repeat
374 \fi\fi
375 %
376 % only text on the left side
377 %
378 \ifnum\na>0
379 \loop\advance\na -1
380 \setbox\aslice=\vsplit\holder to\baselineskip
381 \prune\aslice\lftside
382 \setbox\waslice=\vbox{\unvbox\waslice\hbox
383 to\lftside{\box\aslice\hfil}}
384 \ifdim\ht\holder>0pt\repeat
385 \fi
386 %
387 % only text on the right side
388 %
389 \ifnum\nb>0
390 \loop\advance\nb -1
391 \setbox\bslice=\vsplit\holder to\baselineskip
392 \prune\bslice\rtside
393 \setbox\wbslice=\vbox{\unvbox\wbslice\hbox
394 to\rtside{\box\bslice\hfil}}
395 \ifdim\ht\holder>0pt\repeat
396 \fi
397 %
398 % fixing the dimensions of the window part
399 %
400 \ifnum\bl=0\topheight=\ht\wbslice
401 \else\ifnum\br=0\topheight=\ht\waslice
402 \else\ifdim\ht\waslice>\ht\wbslice\topheight=\ht\waslice
403 \else\topheight=\ht\wbslice\fi\fi\fi
404 %
405 % ship out the window material to the main vertical list
406 %
407 \ifnum\bl>0 \ifnum\br>0 \ifdim\ht\wbslice<\topheight
408 \setbox\wbslice=\vbox to\topheight{\box\wbslice\vfill}
409 \fi\fi\fi
410 \setbox\windowbox=\vbox{\hbox to\linewidth{%
411 \ifnum\bl>0\box\waslice\hfill\fi%
412 \vbox to\topheight{\hrule width\picwd height0pt depth0pt\vskip0pt%
413 \vfill\unvbox\picbox%
414 \ifnum\picwd>0\vfill\fi%
415 \vss}\ifnum\br>0\hfill\vbox{\box\wbslice}\fi}}%
416 \unvbox\windowbox%
417 \loop
418 \setbox\bslice=\vsplit\rawtext to\baselineskip
419 \prune\bslice\linewidth
420 \setbox\wbslice=\vbox{\hbox to\linewidth{\box\bslice\hfil}}
421 \unvbox\wbslice
422 \ifdim\ht\rawtext>0pt
423 \repeat
424 }% FINITO
425 %
426 % What else do we need?
427 %
428 \def\prune#1#2{
429 % take a \vbox containing a single \hbox,
430 % \unvbox it, and cancel the \lastskip
431 % put in a \hbox of width #2
432 \unvbox#1 \setbox#1=\lastbox % \box#1 now is an \hbox
433 \ifdim\ht#1=\parskip
434 \setbox#1=\hbox to#2{\vrule height\parskip depth0pt width0pt\hfill}
435 \else\ifdim\ht#1=0pt\relax
436 \else\setbox#1=\hbox to#2{\wstrut\unhbox#1\unskip}\fi\fi}
437 %
438 % Here the token \twa is generated.
439 % It's not so difficult as it looks like.
440 %
441 \def\createparshapespec{%
442 \global\tcn=0
443 \ifnum\bl>0\global\tcn=\tcl\else\ifnum\br>0\global\tcn=\tcl\fi\fi
444 \na=0 \nb=0
445 \ifnum\bl>0 \ifnum\br>0 \multiply\tcn by 2\fi\fi
446 \ifnum\bl>0\na=\tcn\ifnum\br>0\divide\na by 2\fi\fi
447 \ifnum\br>0\nb=\tcn\ifnum\bl>0\divide\nb by 2\fi\fi
448 \global\advance\tcn by\tcd \global\advance\tcn by1
449 \ifnum\tcd>0
450 \loop\twa=\expandafter{\the\twa\the\ha}\advance\tcd -1
451 \ifnum\tcd>0\repeat
452 \fi
453 \ifnum\bl>0 \ifnum\br>0
454 \loop\twa=\expandafter{\the\twa\the\la}\advance\na -1
455 \twa=\expandafter{\the\twa\the\ra}\advance\nb -1
456 \ifnum\na>0\repeat
457 \fi\fi
458 \ifnum\na>0
459 \loop\twa=\expandafter{\the\twa\the\la}\advance\na -1
460 \ifnum\na>0\repeat
461 \fi
462 \ifnum\nb>0
463 \loop\twa=\expandafter{\the\twa\the\ra}\advance\nb -1
464 \ifnum\nb>0\repeat
465 \fi
466 \global\twa=\expandafter{\the\twa 0pt \the\linewidth}}
467 %
468 \def\computeilg{% compute the interline glue
469 \tcl=0\ilg=0pt\strutilg=0pt
470 \loop\setbox\wbox=\hbox{\char\tcl}
471 \ifdim\ht\wbox>\ilg\ilg=\ht\wbox\fi
472 \ifdim\dp\wbox>\strutilg\strutilg=\dp\wbox\fi
473 \advance\tcl by 1
474 \ifnum\tcl<128\repeat
475 \ht\wbox=\ilg
476 \dp\wbox=\strutilg
477 \strutilg=\ht\wbox %\advance\strutilg by\ilg
478 \ifdim\strutilg>\baselineskip
479 \typeout{character with height greater baselineskip found in font}
480 \typeout{baselineskip changed to 1.5 of that height!}
481 \baselineskip=1.5\strutilg
482 \fi
483 \global\ilg=\baselineskip
484 \global\advance\ilg-\ht\wbox \global\advance\ilg-\dp\wbox
485 \strutilg=\ht\wbox \advance\strutilg by\ilg
486 \setbox\wstrutbox=\hbox{\vrule height\strutilg depth\dp\wbox width0pt}}
487 %
488 % frames
489 %
490 \def\framepic#1{\vbox{%
491 \hsize\expandafter\wd\csname #1box\endcsname
492 \advance\hsize .8pt \hrule%
493 \hbox to\hsize%
494 {\vrule\hfill\vbox to\expandafter\ht\csname #1box\endcsname{%
495 \expandafter\box\csname #1box\endcsname }\hfill\vrule}\hrule\vss}}
496 %
497 \def\wframepic#1{\vbox{%
498 \hsize\expandafter\wd\csname #1box\endcsname
499 \advance\hsize 3.8pt\hrule%
500 \hbox to\hsize%
501 {\vrule\hfill\vbox{\kern1.5pt%
502 \expandafter\box\csname #1box\endcsname
503 \kern1.5pt}\hfill\vrule}\hrule\vss}}
504 %
505 % caption
506 %
507 \def\winstepcounter#1{\global\advance\csname c@#1\endcsname 1
508 {\let\@elt\@stpelt \csname cl@#1\endcsname}}
509
510 \def\winrefstepcounter#1{\winstepcounter{#1}\let\@tempa\protect
511 \def\protect{\noexpand\protect\noexpand}%
512 \edef\@currentlabel{\csname p@#1\endcsname\csname the#1\endcsname}%
513 \let\protect\@tempa}
514 \long\def\w@dblarg#1{\@ifnextchar[{#1}{\w@xdblarg{#1}}}
515 \long\def\w@xdblarg#1#2\par{#1[{#2}]#2\par}
516
517 \def\wincaption{\winrefstepcounter\@captype \w@dblarg{\@wincaption\@captype}}
518
519 \long\def\@wincaption#1[#2]#3\par{\par\addcontentsline{\csname
520 ext@#1\endcsname}{#1}{\protect\numberline{\csname
521 the#1\endcsname}{\ignorespaces #2}}\begingroup
522 \@parboxrestore
523 \normalsize
524 \@makewincaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par
525 \endgroup}
526
527 \long\def\@makewincaption#1#2{%
528 \setbox\@tempboxa\hbox{\footnotesize{\bf #1:\enspace}{#2}}%
529 \ifdim\wd\@tempboxa>\picwd
530 {\footnotesize{\bf #1:\enspace}{#2\par}}
531 \else
532 \hbox to\picwd{\hfil\box\@tempboxa\hfil}
533 \fi}
534
535 \long\def\figwindow[#1,#2,#3,#4] {%
536 \advance\c@figure -1
537 \begin{window}[#1,#2,{#3},\if\relax\detokenize{#4}\relax {} \else {\def\@captype{figure}%
538 \wincaption#4\par}\fi]
539 }
540
541
542 \long\def\tabwindow[#1,#2,#3,#4] {%
543 \advance\c@table -1
544 \begin{window}[#1,#2,{#3},\if\relax\detokenize{#4}\relax {} \else {\def\@captype{table}%
545 \wincaption#4\par}\fi]
546 }
547
548 \def\endfigwindow{\end{window}}
549 \def\endtabwindow{\end{window}}
550 \endinput