summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/genmisc/shadebox.tex
blob: 3044d631f701874a4e63f22fed9d13f6853c332a (plain)
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
%% Save file as: SHADEBOX.TEX           Source: FILESERV@SHSU.BITNET  
%% Author: Leo@vaxc.cc.monash.edu.au 
%% Original Source: Posted by Jim Hefferon <HEFFERON@SMCVAX.BITNET> to
%%                  INFO-TeX on Thu, 16 Jan 1992 11:21 EST

%% Small (and subtle) bug correction on 25 July 2002
%%   by Danilo {\v S}egan <mm01142@alas.matf.bg.ac.yu>
%%
%% The mysterious factor of 65782 is number of sp in 1bp, or 1bp/1pt * 65536.
%%   1pt - printer point 1/72.27"
%%   1bp - ps point aka bigpoint 1/72"
%%   65536 - a number of TeX's scaled points (sp) in 1pt.
%%
%% The other solution is to use temporary registers for dividing all
%% dimensions by 1bp, but who would want to do that?


%----------------------------------------------------------------------------
\newbox\graybox
\newdimen\xgrayspace
\newdimen\ygrayspace
%----------------------------------------------------------------------------
%
% The following \TeX code was based on previous work by
%
%            Je'ro^me Maillot, maillot@bora.inria.fr
%
%----------------------------------------------------------------------------
%
% Use the following for one or more words within a line.
%
\def\textshade#1#2{%
    \xgrayspace=4pt%
    \ygrayspace=4pt%
    \def\grayshade{0.95}%
    \def\linewidth{1}%
    \def\theradius{5}%
    \setbox\graybox=\hbox{\surroundboxa{#2}}%
    \hbox{%
    \hbox to 0pt{%
    \special{"gsave newpath 0 0 moveto                                %
        0                                    1 copy /xmin exch store  %
        \number\dp\graybox \space -65782 div 1 copy /ymin exch store  %
        \number\wd\graybox \space  65782 div 1 copy /xmax exch store  %
        \number\ht\graybox \space  65782 div 1 copy /ymax exch store  %
        \theradius\space                            /radius exch store
        \linewidth\space                            /linewidth exch store
        \grayshade\space                            /grayshade exch store
        #1 grestore}}%
    \box\graybox}}%
%
% Use the following for paragraphs.
%
\def\parashade#1#2{%
    \xgrayspace=10pt%
    \ygrayspace=10pt%
    \def\grayshade{0.95}%
    \def\linewidth{2}%
    \def\theradius{10}%
    \def\thevskip{15pt}%
    \setbox\graybox=\hbox{\surroundboxb{#2}}%
    \vskip\thevskip
    \hbox{%
    \hbox to 0pt{%
    \special{"gsave newpath 0 0 moveto                                %
        0                                    1 copy /xmin exch store  %
        \number\dp\graybox \space -65782 div 1 copy /ymin exch store  %
        \number\wd\graybox \space  65782 div 1 copy /xmax exch store  %
        \number\ht\graybox \space  65782 div 1 copy /ymax exch store  %
        \theradius\space                            /radius exch store
        \linewidth\space                            /linewidth exch store
        \grayshade\space                            /grayshade exch store
        #1 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

This is a test of a\ \textshade{roundcorners}{shaded box} routine.
%
This is another test of a\ \textshade{sharpcorners}{shaded box} routine

\parashade{roundcorners}{%
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.
}
\parashade{sharpcorners}{%
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.
}

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}$$}

\bye