%
%  WRAPFIG.STY  to use environments "wrapfigure" as well as "wraptable"
%
%    This is a modified version (by T.Kugo 15/7/1995) of 
%       T.Iwakuma's modified version WRAPFLOAT.STY (3/11/1992) of 
%       the original D.Arseneau's WRAPFIG.STY (1991)
%
%
% ---------------- from here, the original WRAPFIG.STY -----------------
%
%      W R A P F I G . S T Y
%
%  Copyright (C) 1991 by Donald Arseneau
%  These macros may be freely transmitted, reproduced, or modified for
%  non-commercial purposes provided that this notice is left intact.
%
%  Environment "wrapfigure" to manually place a figure at the side 
%  of the page and wrap text around it.
%
%  \begin{wrapfigure}[36]{r}{3in} <figure> <\caption> etc. \end{wrapfigure}
%                     --  -  ---
%  [number of narrow lines] {left or right} {width of figure}
%
% Usage:
% This is a different type of *non-floating* figure environment for LaTeX.
% A figure of the specified width appears on the left or right (as specified)
% of the page. LaTeX will try to wrap text around the figure leaving a gap of 
% \columsep by producing a number of short lines of text.  LaTeX calculates 
% the number of short lines needed based on the height of the figure plus 
% the length \intextsep.  You can override this guess by giving the optional 
% argument specifying the number of shortened lines (counting each displayed 
% equation as 3 lines).  Cautions:
%  o Wrapfigure should not be used inside another environment (e.g., list)
%  o It does work in two-column format, but that would be silly.
%  o Since it does not float, it may be out of sequence with floated figures.
%  o The automatic rules (lines) that may be placed above or below floats
%    are ignored here.  You must insert the rules manually.
%
% Placement:
% LaTeX will not move a wrapfigure to the best place, so it is up to YOU
% to position it well.  Any changes to the document can ruin your careful
% positioning so wrapfigures should be positioned just before printing a
% final copy. Here are the rules for good placement:
%  o The environment  should be placed so as to not run over a page boundary.
%  o Only ordinary text should have to flow past the figure; no section
%    titles please.  Equations are acceptable if they fit.
%  o It is convenient to give \begin{wrapfigure} just after a paragraph has
%    ended.  But if you want to start in the middle of a paragraph, you must
%    put the environment between two words where there is a natural linebreak 
%    (like "must" and "put" above).
%
% -------------- from here, note by T.Kugo ----------------------
%
%   Environments  "wrapfigure"   and   "wraptable" 
%
%  They are used to place a figure or a table at the side of the page 
%  and wrap text around it. The usage of these are quite the same as 
%  the original "wrapfigure" environment explained in the above: 
%
%  \begin{wrapfigure}[number]{position}{width} 
%     <figure> etc.  
%    \caption{ <caption> }
%  \end{wrapfigure}
%                     --  -  ---
%  Here the arguments are
%    [number]:  fix the number of narrow text lines at the side of the figure. 
%               e.g., like [15]. But usually skip this part [..] at all 
%               like    \begin{wrapfigure}{position}{width} 
%               since the number is automatically calculated. 
%  {position}:  {r} or {l}, to place the figure at the right or left side.
%                or {c},  to place the figure at the center with no wrapping.
%     {width}:  width (with unit) of the figure, like {10cm}.
%
%  You can also specify the vertical spacing and put even two or more figures 
%  with the same width in the environment: e.g.,
%
%      \begin{wrapfigure}{r}{6cm}
%          \epsfxsize=6cm
%          \centerline{\epsffile{FILENAME.eps}}    %first figure by epsf file
%        \caption{First figure}
%          \vspace{20pt}                %to make v-space between two figures
%           \unitlength 1cm
%           \begin{center}    
%           \begin{picture}(3,1.4)      %to draw second figure by picture env.
%             \put(0.7,0.7){\circle*{0.2}}     \put(0.7,0.7){\circle{1.2}}
%             \put(0.7,0.7){\vector(0,1){0.6}} \put(2.5,0.7){\circle*{0.5}}
%           \end{picture}
%           \end{center}
%        \caption{Figure drawn by picture environment}
%      \end{wrapfigure}
%
% The option {c} (center) for the {positon} is added such that it gives the 
% figure (table) exactly at the place specified, otherwise it is essentially 
% the same as the ordinary figure (table) environments. In this case, the 
% argument {WIDTH} is in fact irrelevant.      
%
% The "wraptable" environment is used in quite the same way; e.g.,
%
%      \begin{wraptable}{l}{5cm}
%         \begin{center}
%         \begin{tabular}{|l|l|} \hline
%           test & test \\ \hline
%           test & This is test \\
%           test & This is test \\ \hline
%         \end{tabular}
%         \end{center}
%         \caption{This is caption.}
%      \end{wraptable}
%
% ----------------------------------------------------
\newcount \WF@wrappedlines % used globally
\newdimen\WF@size
\newbox\WF@box
\newdimen\WF@hsep %horizontal separation between fig and text (T.Kugo)
\newdimen\WF@tsep %vspace on the top of the figure (T.Kugo)
\WF@hsep=1.4\columnsep 
\WF@tsep=\intextsep

\def\wrapfigure{\def\@captype{figure}\@ifnextchar[{\WF@raptfig}{\WF@raptfig[-1]}
}
%               ^^^^^^^^^^^^^^^^^^^^^ added by T.I.
\def\wraptable{\def\@captype{table}\@ifnextchar[{\WF@raptfig}{\WF@raptfig[-1]}}
%^^^^^^^^^^^^^^ added by T.I.

%\long\def\@caption#1[#2]#3{\addcontentsline{\csname
%  ext@#1\endcsname}{#1}{\protect\numberline{\csname 
%  the#1\endcsname}{\ignorespaces #2}}\par
%  \begingroup
%    \@parboxrestore
%    \footnotesize %\normalsize
%    \@makecaption%
%    {{\bf \csname fnum@#1\endcsname}}{\ignorespaces \ #3}\par
%  \endgroup}

\def\WF@raptfig[#1]#2#3{\relax\ifx\par\@@par\else\typeout
  {WARNING: wrapfigure used inside another environment.}\fi
  \ifnum#10>\z@ % 10*num. lines specified (0 if blank)
    \global\WF@wrappedlines#1\global\advance\WF@wrappedlines\@ne
  \else % calc num. lines later
    \global\WF@wrappedlines\z@
  \fi
  \xdef\WF@place{\string`\@car#2r\@nil}%
%
  \ifnum `c=\WF@place % fig in the center
    \@tempdima\hsize \advance\@tempdima-#3 \divide\@tempdima\tw@
    \vskip\WF@tsep
    \noindent \hspace*{\@tempdima}\begin{minipage}[t]{#3} \else
%     \bgroup \noindent \setlength\textwidth{#3} \else
%
  \global\setbox\WF@box\vtop\bgroup \setlength\hsize{#3}
\vskip\WF@tsep %T.Kugo
\@parboxrestore
\fi}

\def\endwrapfigure{%
  \ifnum `c=\WF@place % fig in the center
    \end{minipage} \vskip\WF@tsep \else
%   \egroup \vskip\WF@tsep \else
%
  \par\hrule\@width\hsize\@height\z@ % force width
  \egroup % end the \vtop; width is known so now is "later"
  \def\width{\wd\WF@box}% 
  \ifdim\ht\WF@box>\topskip \ht\WF@box\z@ \fi %too much height,set flag.
  \ifdim\ht\WF@box<.5\p@ %too tall (starts with \vbox) or too short
   \global\setbox\WF@box\vtop{\vskip-1.4ex\unvbox\WF@box}\fi
  \global\WF@size\dp\WF@box % box is guaranteed to have little height.
  \global\advance\WF@size1.5\baselineskip \global\advance\WF@size1.2\intextsep
%  \global\advance\WF@size1.5\baselineskip \global\advance\WF@size\tw@\intextsep
%  
  \ifvmode % Between paragraphs: Start new one. Text will be indented...
   \noindent \aftergroup\indent %after the \endgroup of \end{wrapfigure}
  \else % In paragraph: End this one so it doesn't look ended; start new one.
    {\unskip\parfillskip\z@skip\par\penalty\interlinepenalty 
    \parskip\z@skip\noindent}%  text will start with no indentation
  \fi 
  \hbox to \z@{% llap or rlap depending on {l} or {r} parameter.
   \@tempdima\wd\WF@box \advance\@tempdima\WF@hsep %\columnsep-->\WF@hsep
   \@tempdimb\hsize \advance\@tempdimb-\@tempdima
   \ifnum `l=\WF@place % fig on left
    \hss % figure overlaps space to the left
    \def\@tempa{\kern\WF@hsep}% position to left of the gap
   \else  %  fig on right
    \@tempdima\z@ % no left indentation
    \kern\@tempdimb \kern\WF@hsep % position to the right of the text, past 
gutter
    \def\@tempa{\hss}% figure overlaps space to the right
   \fi
  \xdef\WF@wrapil{\the\@tempdima \the\@tempdimb}%indentation and length 
  \dp\WF@box\z@ \box\WF@box % put the figure
  \@tempa}% end \hbox to 0pt
  \aftergroup\WF@startwrapping \global\@ignoretrue
\fi}

\let\endwraptable\endwrapfigure  % <----------- added by T.I.

\def\WF@startwrapping{%
  \ifnum \WF@wrappedlines=\z@ % measure figure box to count lines
  {\advance\WF@size1.1\baselineskip
  \divide\WF@size\baselineskip \global\WF@wrappedlines\WF@size}%
  \fi 
  \everypar{\WF@setwrapping}\WF@setwrapping
  \def\WF@savedclubp{\the\clubpenalty}\clubpenalty\@M % prevent bad pagebreak
  \def\WF@restoretol{\tolerance\the\tolerance}\tolerance\@M
  \def\par{\@@par \clubpenalty\WF@savedclubp  % will wrap more than one
    \global\advance\WF@wrappedlines-\prevgraf % paragraph if necessary
    \ifnum\WF@wrappedlines<\tw@ \everypar{}\let\par\@@par\WF@restoretol\fi
  }}
% Create \parshape command
\def\WF@setwrapping{\@tempcnta\@ne \let\@tempb\relax \def\@tempc{}%
  \@whilenum \@tempcnta<\WF@wrappedlines\do{% repeated indentation, length
    \edef\@tempc{\@tempc\@tempb}\advance\@tempcnta\@ne
  }\let\@tempb\WF@wrapil \parshape \WF@wrappedlines \@tempc \z@ \hsize}
%
% Send problem reports to asnd@triumfcl.bitnet or asnd@Jack.TRIUMF.CA
%
% test integrity:
% brackets: round, square, curly, angle:   () [] {} <>
% backslash, slash, vertical, hat, tilde:   \ / | ^ ~








