%
%  shadedbx.sty        to shade a string box
%
%    direct copy and modification of "loval.sty" by Elmar Schal\"{u}ck
%
%                      bear@hashi1.civil.tohoku.ac.jp (Tetsuo IWAKUMA)
%                      Jan 13, 1993          An example is at the end.
%
\typeout{\space\space\space
shadedb[o]x.sty : Jan 13, 1993 : using TPIC specials}
\def\shadensity#1{\gdef\@shadensity{#1}} \shadensity{0.1}
%   copied from eepic.sty
\def\@paspecial#1#2{\special{pa #1 #2}}
%
\newbox\@tmpbox           % to save a box
\newdimen\@tmpdimd        % dimen of depth
\newdimen\@tmpdimh        % dimen of height
\newdimen\@tmpdimw        % dimen of width
\newdimen\@oldunitl                 \newcount\@textw%
\newcount\@texth                    \newcount\@textd%
\newcount\@xoval                    \newcount\@yoval%
\newcount\@totalwidth               \newcount\@totalheight%
\newcount\@ytextoffs                \newcount\@xtextoffs%
\newcount\@fboxcount                \newcount\@wholecount
\newcount\@stdoffs                  %
\newdimen\@em%
%
\def\shadedbox{\@ifstar{\def\@shading@frame{fp}\@shadedbox}%
 {\def\@shading@frame{ip}\@shadedbox}}
\long\def\@shadedbox#1{\relax\leavevmode %
 \@oldunitl=\unitlength                  % save old unitlength
 \unitlength.01pt                        % interim value for precision
 \@em=1em                                % 1 em
 \@stdoffs=\@em                          %
 \divide\@stdoffs by \unitlength         % to avoid unwanted glues
 \divide\@stdoffs by10                   %
 \multiply\@stdoffs by 3                 % 0.3em
 \setbox\@tmpbox\hbox{#1}                % make #1 a box
 \@tmpdimd=\dp\@tmpbox                   % depth of box, i.e. the part beneath
                                         % the baseline
 \@tmpdimh=\ht\@tmpbox                   % part above baseline
 \@tmpdimw=\wd\@tmpbox                   % width of box
 \@textw=\@tmpdimw\divide\@textw by\unitlength
 \@texth=\@tmpdimh\divide\@texth by\unitlength
 \@textd=\@tmpdimd\divide\@textd by\unitlength
 \@fboxcount=\fboxsep\divide\@fboxcount by\unitlength
 \@wholecount=\@wholewidth\divide\@wholecount by\unitlength
 \advance\@texth by \@textd
 \advance\@tmpdimh by\@tmpdimd           % total height of original box
 \advance\@tmpdimd by\fboxsep            %
 \advance\@tmpdimd by\@wholewidth        % total depth of box
 \@ytextoffs=\@textd                     %
 \advance\@ytextoffs  by\@wholecount     % baseline in picturevalues
 \advance\@ytextoffs  by\@fboxcount      %
 \@xtextoffs=\@fboxcount                 % where to put original text
 \advance\@xtextoffs by -\@stdoffs       %
 \@totalwidth=\@wholecount               %
 \advance\@totalwidth by \@fboxcount     %
 \advance\@totalwidth by \@totalwidth    %
 \advance\@totalwidth by \@textw         %
 \advance\@totalwidth by -\@stdoffs      %
 \@xoval=\@totalwidth                    %
 \advance\@totalwidth by -\@stdoffs      % width of picture enviroment
 \@totalheight=\@wholecount              %
 \advance\@totalheight by \@fboxcount    %
 \advance\@totalheight by \@totalheight  %
 \advance\@totalheight by \@texth        % height of picture enviroment
 \@yoval=\@totalheight                   %
%
 \multiply\@xoval by 1000\multiply\@yoval by 1000%
 \divide\@xoval by 7227\divide\@yoval by 7227%        pt --> m-inch
 \multiply\@stdoffs by 1000\divide\@stdoffs by 7227%
 \hbox{\lower\@tmpdimd                   % put a box beneath baseline
  \hbox%
   {\relax%
    \begin{picture}(\@totalwidth,\@totalheight)           %
    \special{sh \@shadensity}\@paspecial{-\the\@stdoffs}{0}%
    \@paspecial{\the\@xoval}{0}%
    \@paspecial{\the\@xoval}{-\the\@yoval}%
    \@paspecial{-\the\@stdoffs}{-\the\@yoval}%
    \@paspecial{-\the\@stdoffs}{0}\special{\@shading@frame}%
    \put(\@xtextoffs,\@ytextoffs){#1}                     % original box
    \end{picture}\relax                                   %
   }                                                      %
      }%
 \unitlength=\@oldunitl                  % restore unitlength
}                                                         %
%
% end of shadedbx.sty
%
\endinput
%
% an example
%
\documentstyle[shadedbx]{article}
\begin{document}
\title{Shaded Strings}
\author{An Author}
\date{January 13, 1993}
\maketitle\thispagestyle{empty}

A simple ``shading'' of strings or boxes by use of {\tt TPIC}
\verb+\special+'s.

For example, a string can be in the shaded box by
\verb+\shadedbox{string}+ to obtain \shadedbox{string}.
The macro is a simple modification of `{\tt loval.sty}'
by Elmar Schal\"{u}ck.

One can put a `{\tt minipage}' in the shaded area as\vspace{1em}

\begin{minipage}[c]{.45\textwidth}
\begin{quote}\begin{verbatim}
\shadedbox{%
\begin{minipage}{3cm}
....
\end{minipage}}
\end{verbatim}\end{quote}
\end{minipage}\hfill
\shadedbox{\begin{minipage}[c]{.45\textwidth}\parindent=10pt
This is an example of a shaded minipage.
This is an example of a shaded minipage.

This is an example of a shaded minipage.
This is an example of a shaded minipage.
\end{minipage}}

The shading pattern can be changed by a command `\verb+\shadensity+'.
The default is {\tt 0.1}, but, for example, if one sets
\begin{quote}\begin{verbatim}
\shadensity{0.6}
\end{verbatim}\end{quote}
\shadensity{0.6}
then the example above becomes\vspace{1em}
\begin{center}
\shadedbox{\begin{minipage}{.47\textwidth}
This is an example of a shaded minipage.
This is an example of a shaded minipage.
This is an example of a shaded minipage.
This is an example of a shaded minipage.
\end{minipage}}
\end{center}
\shadensity{0.1}

For better boxes, consult with the style file `{\tt fancybox.sty}'
by Timothy Van Zandt (e.g. including \verb+\verb+).

If one needs a frame around the shaded box, use
\verb+\shadedbox*{string}+ to obtain \shadedbox*{string}.

\begin{minipage}[c]{.45\textwidth}
\begin{quote}\begin{verbatim}
\shadedbox*{%
\begin{minipage}{3cm}
....
\end{minipage}}
\end{verbatim}\end{quote}
\end{minipage}\hfill
\shadedbox*{\begin{minipage}[c]{.45\textwidth}
This is an example of a shaded minipage.
This is an example of a shaded minipage.
This is an example of a shaded minipage.
This is an example of a shaded minipage.
\end{minipage}}
\end{document}
