window.sty
Josef Krob
jokr at manwe.phil.muni.cz
Mon Oct 16 09:38:37 CET 1995
Dobry den,
kdysi mi P. Sojka (obracim se tedy zejmena na nej, ale pokud by vedel a
chtel i nekdo jiny ...) nekolikrat zdarne upravoval window.sty, ktery mi
dobre slouzil, a tak jsem se rozhodl ho nasadit ve velkem. Zjistil jsem ale
prisernou vec. Jakmile je do odstavce zabudovano okno a odstavec tak podleha
window.sty, neni mozne tento odstavec zalomit pres stranku. Navic se to deje
dost nestastne: je-li hodnota toplines > 0 pocet radku urceny touto hodnotou
klidne vytece i ze stranky (z papiru) nahoru, zatimco by tyto radky mohly
byt na predchozi strane, kde je mista dost. (Ale jsou natvrdo svazane s
obrazkem a zbyvajicim textem). Podobne text pod obrazkem odmita byt presunut
na dalsi stranu jinak, nez s celym odstavcem.
Dokazal by se nekdo ve zminenem sty, ktery prikladam, zdarne povrtat, tak aby
a) toplines radky mohly byt i na predchozi strane
b) radky od obrazku dolu mohly byt libovolne zalomene podle potreby
???
NEBO
nevite nekdo i jinem sty, ktery by to dokazal?
Delat to pomoci \hangafter a \hangindent pri 165 obrazcich s perspektivou
korektur a predelavani je na vrazdu.
Josef Krob
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% This is WINDOW.STY (Elmar Schal\"uck Apr 1991) %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\message{This is WINDOW.STY by Elmar Schalueck April 1991}
% These routines and macros are mainly due to Alan Hoenig
% I myself found them in a lovely book named
% \TeX: applications, uses, methods (Malcolm Clark, ed.),
% Horwood, New York 1990
% Please report errors, suggestions for better versions, etc. to
% elmar at uni-paderborn.de
% slightly modified by Petr Sojka (sojka at ics.muni.cs) (look for --ps)
%
\newdimen\@totalheight % the height of the included box
\newdimen\@wordskip % interspace between box and text
\newcount\@numberlines % lines corresponding to boxheight
\newdimen\@tempdim % vskip box to have middle height
\def\z at pt{0pt}
\newdimen\point at strut % help dimension
\newdimen\strut at depth \newdimen\strut at height % approximate values
\newcount\n@ % count value for parshaping
\newcount\old at vbadness % backup value
\newcount\@top % number of full lines
\newcount\@window % number of window lines
\newdimen\shave at height % backup values
\newdimen\old at split@top at skip \newdimen\old at prevdepth
\newdimen\old at lineskip
\newdimen\@side % length of windowtext left and right
\newdimen\left at side \newdimen\right at side % text left and right
\newcount\ratio at left % ratio of text left versus right
\newcount\ratio at right
\newcount\ratio at sum
\newcount\ratio at zero % instead of a \newif
\newtoks\parshape at spec % build the wanted parshape
\newbox\window at parbox % the textbox with empty window
\newbox\left at box % help box to reassemble line
\newbox\right at box
\newbox\build at par % text before reassembling
\newbox\in at window % what to put in the window
%
\def\windowbox[toplines: #1][inwindow: #2][ratio: #3 #4]#5\par{%
% #1 number of lines before the window starts
% #2 what will be displayed in the window
% #3 how many parts of the text will be on the left side of the window
% #4 how many parts of the text will be on the right side of the window
% #5 the actual text of the window
\old at vbadness=\vbadness \vbadness=10000
\@top=#1
\setbox\in at window\hbox{#2}
\ratio at left=#3
\ratio at right=#4
\ratio at zero=0 % ratio at zero = 0 iff text appears on
% both sides of the window and cutting
% and reassembling must be done.
\ifnum\ratio at left=0\ratio at zero=1\fi
\ifnum\ratio at right=0\ratio at zero=1\fi
\calculate at dimens % collect all values that are necessary
\create at parshapespec % create the parshape of the text
\setbox\build at par=\vbox{\parshape=\n@ \the\parshape at spec \strut#5}
% build the paragraph
\ifnum\ratio at zero=1
\let\window at parbox=\build at par % the paragraph is ok
\else\open at window\fi % cut and reassemble
\vskip0.5\@tempdim
\vskip\@top\baselineskip % place the box inside the window
\noindent
\ifnum\ratio at left=0
\else\hskip\left at side
\hskip\@wordskip
\fi
\box\in at window % jump back to the normal beginning of
\par\nobreak % the paragraph. Avoid page breaks
\vskip-0.5\@tempdim
\vskip-\@totalheight
\vskip-\@top\baselineskip
\box\window at parbox % place the actual text
\vbadness=\old at vbadness % restore old settings
\splittopskip=\old at split@top at skip
}
%
\def\open at window{% % cut and paste
\old at split@top at skip=\splittopskip \global\splittopskip=0pt
\ifnum\@top=0
\old at prevdepth=\strut at depth\else
\shave at height=\@top\baselineskip
\advance\shave at height by-\strut at depth
\global\setbox\window at parbox=\vsplit\build at par to \shave at height
\old at prevdepth=\dp\window at parbox
\fi
%% \window at parbox contains the top part of the paragraph
\count10=\@numberlines % for lines := 1 to @numberlines do
\shave at height=\strut at height
\loop \setbox\left at box=\vsplit\build at par to\shave at height
\setbox\right at box=\vsplit\build at par to\shave at height
%% the left and the right boxes of one line are built
\advance\count10 by-1 \make at line[\left at box,\right at box]
%% now they are reassembled
\ifnum\@top=0 % if in first line without toplines
\ifnum\count10=\@numberlines
\global\setbox\window at parbox\vbox{\box0} % initiate window at parbox
\else\addline at to@windowpar % else addlines
\fi
\else\addline at to@windowpar
\fi
\ifnum\count10>0 \repeat % end of window-loop
%% \window at parbox has the window part too
%% paste the bottom
\old at lineskip=\lineskip
\global\setbox\window at parbox=\vbox{\prevdepth=\old at prevdepth%
\nointerlineskip %work's better --ps
%\lineskip=1.5pt % This value doesn't seem to fit
% for big fontsizes
\unvbox\window at parbox\box\build at par}
\lineskip=\old at lineskip
}
%
\def\calculate at dimens{%
\setbox0\hbox{\v{C}j} % to calculate strut at height and strut at depth
% consider accents too! --ps
\point at strut=\baselineskip
\advance\point at strut by -\ht0
\advance\point at strut by -\dp0
\divide\point at strut by 2
\global\strut at height=\ht0 % just approximate values
\global\strut at depth=\dp0
\global\advance\strut at height by\point at strut
\global\advance\strut at depth by\point at strut
\global\setbox\strutbox=\hbox{\vrule height\strut at height
depth\strut at depth width0pt} % adjust the \strutbox
\global\@totalheight=\ht\in at window
\global\advance\@totalheight by\dp\in at window % the total height of the
% included window
\global\@numberlines=\@totalheight
\global\divide\@numberlines by\baselineskip
\global\@tempdim=\baselineskip
\global\multiply\@tempdim by-\@numberlines
\global\advance\@tempdim by\@totalheight
\ifdim\@tempdim>-0.3pt%
\global\advance\@numberlines by 2 % horni a dolni okraj
\global\@tempdim=\baselineskip
\global\multiply\@tempdim by\@numberlines
\global\advance\@tempdim by-\@totalheight
\fi % number of lines for the window
% and additional vskip for window
\global\@wordskip=4mm %% sirka okraje \fontdimen2\font
\global\@window=\@numberlines
\global\@side=\hsize
\global\advance\@side by-\wd\in at window
\global\advance\@side by-\@wordskip
\ifnum\ratio at zero=0\global\advance\@side by-\@wordskip\fi
\ratio at sum=\ratio at left
\advance\ratio at sum by\ratio at right
\global\left at side=\@side
\global\multiply\left at side by\ratio at left
\global\divide\left at side by\ratio at sum
\global\right at side=\@side
\global\multiply\right at side by\ratio at right
\global\divide\right at side by\ratio at sum % left side and right side
% according to the chosen ratio
}
%
\def\create at parshapespec{%
\global\n@=\@top % number of lines for parshape
\global\advance\n@ by\@window
\ifnum\ratio at zero=0\global\advance\n@ by\@window\fi
\global\advance\n@ by1
\global\parshape at spec={} % initialize parshape at spec
\count10=\@top % for i := 1 to @top do
\ifnum\@top>0{ % add complete lines to shape
\loop \global\parshape at spec=\expandafter{\the\parshape at spec \z at pt\hsize}
\advance\count10 by-1 \ifnum\count10>0 \repeat
}\fi
\count10=\@window % for i := 1 to @window do
\loop % add two shorter lines
\ifnum\ratio at zero=0 % both ratio values \neq 0
\global\parshape at spec=\expandafter{\the\parshape at spec
\z at pt\left at side \z at pt\right at side}
\else % one ratio value is zero
\ifnum\ratio at left=0
\@side=\hsize\advance\@side by-\right at side % window at the left side
\global\parshape at spec=\expandafter{\the\parshape at spec
\@side\right at side}\fi
\ifnum\ratio at right=0\global\parshape at spec=\expandafter{\the\parshape at spec
\z at pt\left at side}\fi % window at the right side
\fi
\advance\count10 by-1 \ifnum\count10>0 \repeat % end of loop
\global\parshape at spec=\expandafter{\the\parshape at spec \z at pt\hsize}
} % add full line to shape
%
% unwrap the vertical glue and remove the final glue
\def\unwrap#1#2{\unvbox#1 \setbox#1=\lastbox
\setbox#1=\hbox to#2{\strut\unhbox#1 \unskip}%
%
% make a line of two halfs
\def\make at line[#1,#2]{%
\unwrap\left at box\left at side \unwrap\right at box\right at side
\setbox0=\hbox to\hsize{\box#1\hss\box#2}%
}
%
\def\addline at to@windowpar{% add the reassembled lines to the output
\global\setbox\window at parbox=\vbox{\prevdepth=\old at prevdepth
\unvbox\window at parbox \box0}%
\old at prevdepth=\dp\window at parbox
}
%
%
_/ _/_/_/_/ _/ _/ _/_/_/_/_/
_/ _/ _/ _/ _/ _/ _/
_/ _/ _/ _/ _/ _/_/_/_/_/
_/ _/ _/ _/ _/ _/ _/ _/
_/_/_/_/ _/_/_/_/ _/ _/ _/ _/
Josef Krob jokr at phil.muni.cz
jokr at manwe.phil.muni.cz
More information about the csTeX
mailing list