-
Notifications
You must be signed in to change notification settings - Fork 128
/
shading.sty
232 lines (227 loc) · 8.87 KB
/
shading.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
%%% ====================================================================
%%% @LaTeX-style-file{
%%% filename = "shading.sty",
%%% version = "1.3",
%%% date = "29 September 1992",
%%% time = "08:23:05 MDT",
%%% author = "Art Mulder",
%%% address = "Department of Computing Science
%%% 615 General Services Building
%%% University of Alberta
%%% Edmonton, Alberta
%%% T6G 2H1, Canada.",
%%% telephone = "n/a",
%%% FAX = "(403) 492-1071",
%%% checksum = "06606 232 1004 9082",
%%% email = "[email protected]",
%%% codetable = "ISO/ASCII",
%%% keywords = "LaTeX style option, shaded background",
%%% supported = "yes",
%%% docstring = "A LaTeX Style file for putting text on a
%%% shaded background. Requires a PostScript
%%% printer and dvi-file converter.
%%%
%%% NOTE: Art Mulder is not the author
%%% of this file, just the most recent
%%% modifier.
%%%
%%% The style file is based upon ideas by
%%% Je'ro^me Maillot, [email protected]
%%% which where turned into TeX code by
%%% Leo, [email protected].
%%% That TeX code was converted into a LaTeX
%%% style file by M.A.R. ( [email protected] )",
%%% }
%%% ====================================================================
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 'Shading.sty'
%
% Art Mulder ( [email protected] ) 28-Sept-1992
% - Changed name of "linewidth" variable to "outlineboxwidth".
% That variable name conflicted with another variable of the same
% name in "latex.tex" when doing miniparagraphs.
% - Wrote accompanying document ``shading.tex'', brief instructions
% in the use of this style file, together with several examples.
%
% M.A.R. ( [email protected] ) 22 Jan 92
% - Modified to work as a LaTeX style:
% - added setting the grayscale as an optional argument.
% - allowed multiple paragraphs in the \parashade command
%
% Leo ?? ( [email protected] )
% - Wrote the original TeX code, based upon some ideas
% from Je'ro^me Maillot ( [email protected] ).
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% USAGE: \textshade[grayscale]{corneroption}{text to be shaded}
% \parashade[grayscale]{corneroption}{paragraph(s) to be shaded}
% where
% grayscale is a number from 0 to 1, the higher the number the
% lighter the shading, if missing it is set to 0.95
% corneroption is either sharpcorners or roundcorners
%
% LIMITATIONS: --can not break the shaded text across lines (\textshade) or
% across pages (both)
% --can not specify the line width of the surrounding box or
% the amount of space between the surrounding
% box and the text to be shaded as arguments
% (Actually you can, see the use of "\gdef" in the example)
% --modifying the xgrayspace and ygrayspace in the argument
% will only affect the space added to the right and
% bottom of the box, respectively
%
% EXAMPLES:
% This is a test of a\ \textshade[1]{roundcorners}{shaded box} routine.
% With a grayscale of 1, we essentially get no shading, and just a box.
%
% This is another test of a\ \textshade{sharpcorners}{shaded box} routine.
% The default shading of .95 is used here.
%
% \parashade[.995]{roundcorners}{\gdef\outlineboxwidth{.5}%
% This is one very long line which I expect will be broken over one or more
% lines. The idea is to have this paragraph enclosed in a shaded box. I'll
% just keep on typing until I can be sure that there are more than two lines
% in this paragraph. I expect that this should be well and truely sufficient
% to test this macro.
% } %This shows an example of changing the outlineboxwidth used, without
% %changing the style
%
% The field equations of General Relativity are\ %
%%
% \textshade{roundcorners}{\hbox{$G_{\mu\nu} = kT_{\mu\nu}$}}
%
% They can also be written as
%
% \parashade{sharpcorners}{$$R_{\mu\nu}-{1\over2}g_{\mu\nu}R = kT_{\mu\nu}$$}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newbox\graybox
\newdimen\xgrayspace
\newdimen\ygrayspace
%----------------------------------------------------------------------------
%
% The following \TeX code was based on previous work by
%
% Je'ro^me Maillot, [email protected]
%
%----------------------------------------------------------------------------
%
% Use the following for one or more words within a line.
%
%MAR-added ability for optional argument for user to set grayscale
\def\textshade{\@ifnextchar[{\@textshade}{\@textshade[0.95]}}
\def\@textshade[#1]#2#3{%
\xgrayspace=4pt%
\ygrayspace=4pt%
\def\grayshade{#1}%
\def\outlineboxwidth{1}%
\def\theradius{5}%
\setbox\graybox=\hbox{\surroundboxa{#3}}%
\hbox{%
\hbox to 0pt{%
\special{"gsave newpath 0 0 moveto %
0 1 copy /xmin exch store %
\number\dp\graybox \space -65536 div 1 copy /ymin exch store %
\number\wd\graybox \space 65536 div 1 copy /xmax exch store %
\number\ht\graybox \space 65536 div 1 copy /ymax exch store %
\theradius\space /radius exch store
\outlineboxwidth\space /linewidth exch store
\grayshade\space /grayshade exch store
#2 grestore}}%
\box\graybox}}%
%
% Use the following for paragraphs.
%
%MAR-added ability for optional argument for user to set grayscale
\def\parashade{\@ifnextchar[{\@parashade}{\@parashade[0.95]}}
%MAR-added \long to allow multiple paragraphs in one shaded block
\long\def\@parashade[#1]#2#3{%
\xgrayspace=3pt%
\ygrayspace=3pt%
\def\grayshade{#1}%
\def\outlineboxwidth{0}%
\def\theradius{10}%
\def\thevskip{15pt}%
\setbox\graybox=\hbox{\surroundboxb{#3}}%
\vskip\thevskip
\hbox{%
\hbox to 0pt{%
\special{"gsave newpath 0 0 moveto %
0 1 copy /xmin exch store %
\number\dp\graybox \space -65536 div 1 copy /ymin exch store %
\number\wd\graybox \space 65536 div 1 copy /xmax exch store %
\number\ht\graybox \space 65536 div 1 copy /ymax exch store %
\theradius\space /radius exch store
\outlineboxwidth\space /linewidth exch store
\grayshade\space /grayshade exch store
#2 grestore}}%
\box\graybox}%
\vskip\thevskip%
}%
%----------------------------------------------------------------------------
%
% A pair of box macros. Each builds a slightly oversized box
% containing the text. The text is centred both in the vertical
% horizontal directions.
%
% Use the following for one or more words within a line.
%
\long\def\surroundboxa#1{\leavevmode\hbox{\vtop{%
\vbox{\kern\ygrayspace%
\hbox{\kern\xgrayspace#1%
\kern\xgrayspace}}\kern\ygrayspace}}}
%
% Use the following for a paragraphs.
%
\long\def\surroundboxb#1{\leavevmode\hbox{\vtop{%
\vbox{\kern\ygrayspace%
\hbox{\kern\xgrayspace\vbox{\advance\hsize-2\xgrayspace#1}%
\kern\xgrayspace}}\kern\ygrayspace}}}
%----------------------------------------------------------------------------
%
% Here are some simple PostScript routines.
%
% The TeX command \PScommands must be called before any of the
% shading routines can be used.
%
\long\def\PScommands{\special{! TeXDict begin
%
/sharpbox{%
newpath
xmin ymin moveto
xmin ymax lineto
xmax ymax lineto
xmax ymin lineto
xmin ymin lineto
closepath
}bind def
%
/roundbox{%
newpath
xmin radius add ymin moveto
xmax ymin xmax ymax radius arcto
xmax ymax xmin ymax radius arcto
xmin ymax xmin ymin radius arcto
xmin ymin xmax ymin radius arcto 16 {pop} repeat
closepath
}bind def
%
/sharpcorners{%
sharpbox gsave grayshade setgray fill grestore
linewidth setlinewidth stroke
}bind def
%
/plainbox{%
sharpbox grayshade setgray fill
}bind def
%
/roundcorners{%
roundbox gsave grayshade setgray fill grestore
linewidth setlinewidth stroke
}bind def
%
end}% Closes dictionnary
}%
\PScommands
\endinput