\typeout{ LaTeX2e style: shadethm <95/07/19 jh>}

\NeedsTeXFormat{LaTeX2e}

\ProvidesPackage{shadethm}[1995/07/19]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% ShadeThm.sty

%   Shaded theorem environments in LaTeX with \newshadetheorem instead of

% \newtheorem.

%

% USAGE

%   Used as a LaTeX2e style, with \usepackage{shadethm}, it allows declarations

% of the form \newshadetheorem{theorem}{Theorem}, so that

%      \begin{theorem}  $e=mc^2$  \end{theorem}

% will produce the usual theorem text, only placed in a shaded box.

%   Options.  Two come in this file:

%      bodymargin (default)  The body of the shaded text lines up with the

%        margins.  Just as though you called newtheorem, then colored later.

%        Shading falls outside the margin.

%      shademargin  The shading lines up with the margins, so the body of

%        shaded text comes out a little thinner.

% If you call it with an option not on that list then it will look for a

% file <OptionName>.sth and take the parameters from there.  See the included 

% files shadein.sth and colored.sth, the first of which gives theorems that are

% (like LaTeX quotations) indented left and  right and the second of which 

% gives color shading (expects dvips's color.pro for the color names---see the

% graphics documentation).  

%

% REMARKS

%  (1) You can of course have non-shaded environments, also.  The \newtheorem 

% command still works (but see Remark (2)).

%  (2) Numbering within:

%   LaTeX allows you to say \newtheorem{guess}{Conjecture}[section] so that at 

% each new section the conjectures are numbered starting again at 1.  So does

% \newshadetheorem.  LaTeX also allows you to say 

% \newtheorem{remark}[guess]{Remark} so that remark and guess use the same 

% counter: 

%     \begin{guess} 

%        Dinosaurs are small at one end, large in the middle,

%        and very small again at the other end.

%      \end{guess}

%      \begin{remark}

%         This conjecture is due to me.

%      \end{remark}

% gets printed as

%     Conjecture 1  Dinosaurs are small at one end, large in the middle, and

%     very small again at the other end.

%     Remark 2  This conjecture is due to me.

% \newshadetheorem allows the same thing, but with one change.  If you want to 

% refer to a theorem environment `xxx' that was declared with 

% \newshadetheorem{xxx}{Yyy} then you must call it `shadexxx': e.g.,

%     \newshadetheorem{thm}{Theorem}

%     \newshadetheorem{note}[shadethm]{Note}

% (references to non-shaded theorem environments are unchanged).

%  (3) Uses the graphics package.  Look for it in the CTAN TeX-archive nearest

% you, for instance at pip.shsu.edu.  

%  (4) Works with theorem.sty.

%

% INSTALLATION

%   Put this where your TeX looks for .sty files.  (In emTeX that is probably

% c:\emtex\texinput\shadethm.sty.)

%   There are some parameters you could set the default for (try them as is, 

% first).

%    (i) shadethmcolor  The shading color of the background.  See the 

%      documentation for the color package, but with a `gray' model, I find .97

%      looks good out of my printer, while a darker shade like .92 is needed 

%      to make it copy well.  (Black is  0, white is 1.) 

%    (i*) shaderulecolor  The shading color of the border of the shaded box.  

%      See (i).  If \shadeboxrule is set to 0pt then this won't print anyway.

%    (i**) shadeboxrule  The width of the border around the shading.  Set it to

%      0pt (not just 0) to make it disappear.

%    (i***) shadeboxsep  The length by which the shade box surrounds the text.

%    (ii) shadesetinsideminipage   The theorems are set inside a minipage to

%      get line breaks, but some things, like paragraph indents, are messed 

%      with there, so I have a hook to reset them.  Probably you can just

%      leave this alone.

%     (iii) The default option.  Change the \ExecuteOptions{...} right before

%      the \ProcessOptions.

%  Comment:

%   If you get an error about `undefined color model' then you need to create

% the file color.cfg in the same place as color.sty, and put in it the line

% \ExecuteOptions{dvips} (or whatever is the name of your driver).  See the

% documentation for the graphics package.  I needed this under Linux's NTeX.

%

% BUGS

%  (1) Page breaks are a problem since it sets the theorem before it is shaded.

% The theorem is put into a minipage in order to have the right line breaks

% put in, but then can't be broken across pages.  I'd be interested in any

% fixes for this.

%  (2) If you do not follow a shaded theorem with a blank line, that is not

% handled right, in that a new paragraph is made anyway.  I think this is 

% as in bug (1), but I don't know how to fix it.

%

% AUTHOR'S NOTE

%  If you find this useful, I would appreciate a short email message saying so.

% My address is hefferon@smcvax.smcvt.edu.  Thank you.

%

% HISTORY

%  95VI19 jh Adapted for LaTeX2e.  Now uses the graphics package, and all

%    the neat 2e package stuff.  Still haven't rewritten the parsing code to

%    use the new optional arguments to \newcommand, though.  Ah well.

%  94VII11 jim hefferon hefferon@smcvax.smcvt.edu.  First written (after lots

%    of sporadic tries, over months; I couldn't get any of the extant shading 

%    macros to work with theorems) from a hint in TvZ's Fancybox writeup. 

%    It's all so easy once you know how.

%

\DeclareOption{bodymargin}{

  \AtEndOfPackage{

  \setlength{\shadeboxsep}{2pt}  

  \setlength{\shadeboxrule}{0pt}  

  \setlength{\shadedtextwidth}{\textwidth}

  \setlength{\shadeleftshift}{-\shadeboxsep} 

  \setlength{\shaderightshift}{-\shadeboxsep}

  \definecolor{shadethmcolor}{gray}{.97}

  \definecolor{shaderulecolor}{gray}{.97}

  }

}

\DeclareOption{shademargin}{

  \AtEndOfPackage{

  \setlength{\shadeboxsep}{2pt}  

  \setlength{\shadeboxrule}{0pt}  

  \setlength{\shadedtextwidth}{\textwidth}

  \addtolength{\shadedtextwidth}{-2\shadeboxsep}

  \setlength{\shadeleftshift}{0pt} 

  \setlength{\shaderightshift}{0pt}

  \definecolor{shadethmcolor}{gray}{.97}  

  \definecolor{shaderulecolor}{gray}{.97}

  }

}

\DeclareOption*{\InputIfFileExists{\CurrentOption.sth}{}{%

  \typeout{shadethm warning: option \CurrentOption\space not known.}}}



\ExecuteOptions{bodymargin}  \ProcessOptions



\RequirePackage{color}



% Save the document paragraph indents so they can be reasserted inside the

% minipage into which the theorems get put.

\newlength{\saveparindent}              %to have paragraphs default to their 

\setlength{\saveparindent}{\parindent}  %usual indent inside the minipage

\newcommand{\shadesetinsideminipage}{%    %To reset this inside an option,

  \setlength{\parindent}{\saveparindent}} %or a document, \renewcommand{...} 



% Declare the lengths we need.  Set in the package options.

%  Here is a diagram:

%        text text text text text text text text text text text text

%           ------------------------------------------------------

%           | Theorem.  My bonnie lies over the ocean.  My bonnie |

%           | lies over the sea.                                  |

%           ------------------------------------------------------

%    --->|  |<----                                          --->| |<--

%           \shadeleftshift                                     \shadeboxsep

%                                                              (all four sides)

%

%             |<-------------- \shadetextwidth ---------------->|

% 

\newlength{\shadeboxsep} %start of color to start of text; four sides  

\newlength{\shadeboxrule} %width of bordering rule  

\newlength{\shadedtextwidth} %width of the text body

\newlength{\shadeleftshift}  %margin to start of shading (may be negative)

\newlength{\shaderightshift} %makes total line width come out (may be negative)





% MAIN CODE

% see LaTeXbook (second edition) pp 108 and 132

\newsavebox{\shadesavebox}   % no `@'; users can redefine shadebox if they want

\newenvironment{shadebox}%   % shadow boxes or something. 

{\begin{lrbox}{\shadesavebox}\begin{minipage}{\shadedtextwidth}%

\shadesetinsideminipage}%

{\end{minipage}\end{lrbox}%

{\begin{trivlist}\item[]% In a trivlist because theorems are in trivlists.

\setlength{\fboxsep}{\shadeboxsep}%

\setlength{\fboxrule}{\shadeboxrule}%

\mbox{\hspace{\shadeleftshift}\fcolorbox{shaderulecolor}{shadethmcolor}{\usebox{\shadesavebox}}\hspace{\shaderightshift}}%

\end{trivlist}}}



%PARSING CODE

%  The definition of \newshadetheorem is modelled on the one for \newtheorem

% in latex.tex.

%  The invocation possibilities are:

%   \newshadetheorem{NAME}{TEXT}[COUNTER]

%      e.g., \newshadetheorem{theorem}{Theorem}[section] meaning to allow

%      one to say \begin{theorem} $e=mc^2$ \end{theorem} to produce

%        Theorem 1.1.1 e=mc2

%      shaded and numbered by section.

%   \newshadetheorem{NAME}[OLDNAME]{TEXT}

%      e.g., \newshadetheorem{remark}[theorem]{Remark} meaning to allow

%      one to say \begin{remark} Obvious. \end{remark} to produce

%        Remark 1.1.2  Obvious.

%      shaded and numbered with the same counter used for theorems.

% The flowchart for parsing the arguments goes like this.

%   1) \newshadetheorem{#1}    (note  #1<--NAME)

%   2) If the next character is `[' then we have the second case.  This

%       is handled by \shade@othm

%   3) If not, go to \shade@nthm.  There are two cases here, either there

%       is an optional argument (this is handled by \shade@xnthm) or there is

%       not (this is handled by \shade@ynthm).

% (Possibly these cases could be folded somewhat as all use the same tail.)

% Notice I have to have different names for the theorem and the environment.

% I call the theorem `xxx' by the name `shadexxx' so the user just says 

%    `\begin{xxx} ...'

% for the environment.   (All this is, of course, just adapted from Lamport's 

% code.)  Can be fixed?

\def\newshadetheorem#1{\@ifnextchar[{\shade@othm{#1}}{\shade@nthm{#1}}}



\def\shade@othm#1[#2]#3{%

\newtheorem{shade#1}[#2]{#3}%

\newenvironment{#1}%

{\begin{shadebox}\begin{shade#1}}%  

{\end{shade#1}\end{shadebox}}}



\def\shade@nthm#1#2{\@ifnextchar[{\shade@xnthm{#1}{#2}}{\shade@ynthm{#1}{#2}}}



\def\shade@xnthm#1#2[#3]{%

\newtheorem{shade#1}{#2}[#3]%

\newenvironment{#1}%

{\begin{shadebox}\begin{shade#1}}%

{\end{shade#1}\end{shadebox}}}



\def\shade@ynthm#1#2{%

\newtheorem{shade#1}{#2}%

\newenvironment{#1}%

{\begin{shadebox}\begin{shade#1}}%

{\end{shade#1}\end{shadebox}}}



\endinput %end shadethm.sty

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-test.tex-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

\documentclass{article}

\usepackage{shadethm}



\newshadetheorem{theorem}{Theorem}

\newshadetheorem{cor}[shadetheorem]{Corollary}

\newtheorem{remark}[shadetheorem]{Remark}



\begin{document}

Here is some initial text before the shaded box.



\begin{theorem}

This is the text to be shaded.

\end{theorem}



This is some text after the first shade.

It is separated from the environments by a blank line; that is 

all handled as usual in \LaTeX.



\begin{cor}

This is more text to be shaded.

It is numbered with the same counter as the environment above.



Multiple paragraphs will be handled with the usual paragraph indentation,

unless of course the user asks for a different paragraph indentation inside

the environment.

\end{cor}



\begin{remark}

More text.

This time not set in shade, however it is numbered in the same sequence.

\end{remark}



Finishing text.

\end{document}



