Debian Codegraph @

docs/sources/psboxit.sty

raw
1 % psboxes.sty
2 %
3 % This package enables to put a PostScript drawing behind a TeX box.
4 % The drawing is parametrized by the position and the size of the
5 % TeX box. To put a gray [rounded] box behind a word use
6 % \PScommands % Once at the begining
7 %
8 % ... text text \psboxit{25 cartouche}{THE WORD} text text
9 % \psboxit{box 0.5 setgray fill}{\spbox{ANOTHER WORD}}
10 % text text ...
11 %
12 % * If your boxes are ill sized try to change 16384 to
13 % something else (original code used 65536).
14 % % 65536 is the internal unit of TeX (scaled point, TeXBook page 57)
15 % Those macros were adapted from Tom Sheffler (CMU)'s psframe.sty style. In
16 % particular, the spacebox macro was just copied from his style.
17 %
18 % Je'ro^me MAILLOT, INRIA
19 % [email protected]
20 % August 1991
21 %
22 %
23 % A Few PostScript definitions to use with \psboxit
24 % Call \PScommands once at the begining of your program, this will
25 % define : box roundedbox rectcartouche and cartouche. They are 4
26 % PostScript programs. Change the values before setlinewidth end
27 % setgray to customize your boxes
28 %
29 % Ex : \psboxit{25 cartouche}{blah blah}
30 % \psboxit{rectcartouche}{blah blah}
31 %
32 \long\def\PScommands{\special{! TeXDict begin
33 /box{% Processes the path of a rectangle.
34 % Needs : x0 y0 x1 y1.
35 newpath 2 copy moveto 3 copy pop exch lineto 4 copy pop pop
36 lineto 4 copy exch pop exch pop lineto closepath } bind def
37 %
38 %
39 /min{ 2 copy gt { exch } if pop } bind def%
40 /max{ 2 copy lt { exch } if pop } bind def%
41 /roundedbox{% Processes the path of a rounded rectangle.
42 % Needs : x0 y0 x1 y1 radius.
43 % The bounding box is augmented by +/- radius to allow easily to
44 % frame several rounded boxes around the same Texture box. Ex:
45 % \psboxit{4 copy 15 roundedbox 25 roundedbox} {\spbox{Some Text}}
46 % draws two scaled boxes arond the same word. Delete the `radius
47 % sub' and `radius add' commands to suppress that enlargement.
48 %
49 /radius exch store
50 3 2 roll % x0 x1 y1 y0
51 2 copy min radius sub /miny exch store
52 max radius add /maxy exch store
53 2 copy min radius sub /minx exch store
54 max radius add /maxx exch store
55 newpath
56 minx radius add miny moveto
57 maxx miny maxx maxy radius arcto
58 maxx maxy minx maxy radius arcto
59 minx maxy minx miny radius arcto
60 minx miny maxx miny radius arcto 16 {pop} repeat
61 closepath
62 }bind def
63 %
64 %
65 /rectcartouche{% Draws a filled and framed box
66 % Needs : x0 y0 x1 y1
67 box gsave .95 setgray fill grestore 1 setlinewidth stroke }bind def
68 %
69 %
70 /cartouche{% Draws a filled and framed rounded box
71 % Needs : x0 y0 x1 y1 radius
72 roundedbox gsave .95 setgray fill grestore 1 setlinewidth stroke }bind def
73 %
74 end }% Closes dictionnary
75 }\PScommands%
76 %%
77 %% PSBOXIT
78 %%
79 %% \psboxit{PS program}{TeX stuff}
80 %%
81 %% The bounding box of the TeX stuff is pushed on the PostScript stack
82 %% and then the program in the first argument is called
83 %%
84 %% EXAMPLE: set some text on a gray background, Use the SPBOX macro to
85 %% give some space around the text.
86 %%
87 %% \psboxit{box 0.5 setgray fill}{\spbox{Some Text}}
88 %%
89 %% See \PScommands for the \box definition
90 %%
91 \chardef \atcode = \the \catcode `\@
92 \catcode `\@ = 11
93
94 \long\def\psboxit#1#2{%
95 \begingroup\setbox0=\hbox{#2}%
96 \dimen0=\ht0 \advance\dimen0 by \dp0%
97 % Write out the PS code to set the current path using HEIGHT,
98 % WIDTH , DEPTH of box0.
99 \hbox{%
100 \special{ps: gsave currentpoint translate
101 0
102 \number\dp0 \space 15800 div % hand tuned for dvips
103 \number\wd0 \space 15800 div % hand tuned for dvips
104 \number\ht0 \space -15800 div % hand tuned for dvips
105 % \number\dp0 \space 16384 div
106 % \number\wd0 \space 16384 div
107 % \number\ht0 \space -16384 div % Bounding box
108 % \number\dp0 \space 65536 div
109 % \number\wd0 \space 65536 div
110 % \number\ht0 \space -65536 div % Bounding box
111 #1 grestore}%
112 \copy0%
113 }%HBOX
114 \endgroup%
115 }%
116
117 % SPACEBOX
118 %
119 % This macro simply takes some TeX stuff, and puts FOUR sides on it
120 % so that the box is the same size as the thing you'd get with
121 % an \fbox{} command. (All I did was modify the code for \fbox{}
122 % so that all rules were replaced with struts).
123 %
124 % USAGE: \spbox{text} is just like \fbox{text} but makes no rules
125 %
126 % REASON: so that if using \pspath{...}{\fbox{stuff}}
127 % there is a way to get another box the same size:
128 % \pspath{...}{\spbox{stuff}}
129 %
130 \long\def\spbox#1{\leavevmode\setbox1\hbox{#1}%
131 \dimen0\fboxrule \advance\dimen0 \fboxsep%
132 \advance\dimen0 \dp1%
133 \hbox{\lower \dimen0\hbox%
134 {\vbox{\hrule height \fboxrule width 0pt%
135 \hbox{\vrule width \fboxrule height 0pt \hskip\fboxsep%
136 \vbox{\vskip\fboxsep \box1\vskip\fboxsep}\hskip%
137 \fboxsep\vrule width \fboxrule height 0pt}%
138 \hrule height \fboxrule width 0pt}}}}%
139
140 \def\Gbox#1{\psboxit{box 0.9 setgray fill}{#1}}
141 %%
142 \newsavebox{\gray@box}%
143 \newdimen\gray@space
144 %
145 \long\def\Beginboxitpara#1{\edef\gray@tmp{#1}%
146 \gray@space=\fboxsep \advance\gray@space by -\fboxrule
147 \par\prevdepth=-1000pt\vskip 0.5\baselineskip\noindent
148 \setbox\gray@box=%
149 \hbox\bgroup \vrule width \fboxrule
150 \vtop\bgroup \hrule
151 \vbox\bgroup
152 \kern\gray@space
153 \hbox\bgroup
154 \kern\gray@space
155 \vtop\bgroup
156 \hsize=\linewidth\advance\hsize-2\fboxsep\noindent
157 \ignorespaces}
158 \def\Endboxitpara{%
159 \egroup
160 \kern\gray@space
161 \egroup
162 \kern\gray@space
163 \egroup \hrule
164 \egroup\vrule width \fboxrule
165 \egroup
166 \psboxit{\gray@tmp}{\box\gray@box}%
167 \vskip 0.5\baselineskip
168 \par}
169
170 \newenvironment{boxitpara}[1]{\Beginboxitpara{#1}}{\Endboxitpara}
171 \newenvironment{boxitpara*}[1]{\Beginboxitpara{#1}\hbox to\hsize{}}%
172 {\Endboxitpara}
173
174 \catcode `\@ = \the \atcode
175 \endinput