\iffalse%

          LaTeX Style: editbar.sty  1.1

          Written by:  Michael R. Van Geest
                       Unisys Corp.
                       M.S. 4522
                       2276 Highcrest Road
                       Roseville, MN 55113

          Internet:    mrv@unirsvl.rsvl.unisys.com

          Date:        October 8, 1993

          TeX Drivers Supported: DVIPS    


          General Information:

             editbar.sty is a LaTeX style to be used to print edit bars
             (change bars) with PostScript as the final output.

             DVIPS is the only driver currently supported, but others could
             be used.

             Generation of edit bars on one page and/or spanning 
             multiple pages.

             The output routine of LaTeX is modified to include the edit
             bar commands to span multiple pages.


          Macro usage:

             ebarsetup   - Place before \begin{document}

             ebarcleanup - Place before \end{document}
                           It is adviseable to put a \clearpage before
                           \ebarcleanup.

             genebaron   - Start generating edit bars.

             genebaroff  - End generating edit bars.


          Counters that can be modified are:

             \ebaroddside   - Distance in points from the left side of the
                              paper to where the edit bar on the odd side
                              of the paper is placed.

                              Currently set to 508.
      
             \ebarevenside  - Distance in points from the left side of the
                              paper to where the edit bar on the even side
                              of the paper is placed.

                              Currently set to -30.

             \ebarbarheight - Height of edit bar in points on current line. 
                              Currently set to 12 (1 pica).
              
             \ebarbarwidth  - Edit bar width in points, currently set to 2.


          Auxilary files that are created are: 

            \jobname.ebo - Edit bar out file.

                           \count0 is written to this file in the output
                           routine by the \write command.

            \jobname.ebi - Edit bar in file.  The contents of \jobname.ebo
                           are copied to this file after 1 pass of LaTeX.
                           This file is used as input to the genebaron
                           and genebaroff macros to find out which page(s)
                           to place the edit bars.


          Restrictions:

             -  Does not span multiple chapters.  The edit bar must
                end at the chapter.  This is because count0 is used 
                as the edit bar counter to place on odd or even sides 
                if two sided styles are used.  If one sided styles
                are used, the odd side edit bar code is used.

             -  Nested edit bars are not supported.

                Examples:

                   \genebaron Text \genebaron text \genebaroff
     
                   \genebaron Text \genebaroff text \genebaroff

             -  Does support paper resolution.  The DVIPS
                PostScript def Resolution is used.

             -  Edit bars in Longtable.sty should work.


          Sample Usage:

             \documentstyle[editbar]{book}
             %
             \ebarsetup{}%
             %
             \begin{document}
             %
             Paragraph on page 1
             %
             \newpage 
             This paragraph \genebaron{}has an edit bar on it.
             %  
             \newpage
             %
             This is a paragraph that has an edit bar around it.
             %
             This \genebaroff{}is a paragraph with end edit bar that ends it.
             More stuff.
             More stuff.
             More stuff.
             More stuff.
             More stuff.
             More stuff.
             More stuff.
             More stuff.
             More stuff.
             More stuff.
             More stuff.
             More stuff.
             More stuff.
             More stuff.
             %
             \clearpage\ebarcleanup{}%
             \end{document}

\fi%

\def\fileversion{v1.1}
\def\filedate{08OCT93}
\wlog{Style-Option: `editbar' \fileversion \space\space <\filedate> (M.R.V.G.)}

% Read Register - ebarin
% Edit Bar read in file
%
\newread\ebarin

% Write Register - ebarout
% Edit Bar write out file
%
\newwrite\ebarout

% Count Register - ebarnest
%
\newcount\ebarnest
\ebarnest=0

% Count Register - ebaronpagedelay
%
\newcount\ebaronpagedelay
\ebaronpagedelay=0

% Count Register - ebaroddside
%
\newcount\ebaroddside
\ebaroddside=508

% Count Register - ebarevenside
%
\newcount\ebarevenside
\ebarevenside=-30

% Count Register - ebarbarwidth
%
\newcount\ebarbarwidth
\ebarbarwidth=2

% Count Register - ebarbarheight
%
\newcount\ebarbarheight
\ebarbarheight=12

% Count Register - ebarpagesspan
%
\newcount\ebarpagesspan
\ebarpagesspan=0

% Count Register - ebaroncapture
%
\newcount\ebaroncapture
\ebaroncapture=0

% Count Register - ebaroncapturesave
%
\newcount\ebaroncapturesave
\ebaroncapturesave=0

% Count Register - ebaroffcapture
%
\newcount\ebaroffcapture
\ebaroffcapture=0

% Count Register - ebarsubtract
%
\newcount\ebarsubtract
\ebarsubtract=0

% If - ifebarfileopen
% Checks to see if the ebarfile is open
%
\newif\ifebarfileopen
%
%    ebarsetup
%
%    Sets up the input and output ebar files     
%
%    Place at the top of the document
%
\globaldefs1%
\def\ebarsetup{% 
\immediate\openin\ebarin=\jobname.ebi %
\ifeof\ebarin%
   \typeout{No file \jobname.ebi}%
   \global\ebarfileopenfalse%
\else%
   \global\ebarfileopentrue%
\fi%
\immediate\openout\ebarout=\jobname.ebo %
}%
%
%    ebarcleanup
%
%    Closes the ebar output file, then opens the ebar output file for read,
%    then copies the ebar output file to the ebar input file for the next
%    pass to read the ebar input file
%
%    Place at the end of the document
%
\def\ebarcleanup{%
\immediate\closein\ebarin%
\immediate\closeout\ebarout%
%%
\immediate\openin\ebarin=\jobname.ebo %
\immediate\openout\ebarout=\jobname.ebi %
%%
\ebarfileopentrue%
%%
\loop%
   \immediate\read\ebarin to \ebarinin%
   \ifeof\ebarin%
     \ebarfileopenfalse%
   \fi%
   \ifebarfileopen%
     \immediate\write\ebarout{\ebarinin}%
\repeat%
%%
\closein\ebarin%
\closeout\ebarout%
}%
%
%    ebargeton
%
%    Gets the next ebar reference from the ebar input file
%
%    Specifically, gets the relative page number output from the prior
%    pass of genebar macro
%
\def\ebargeton{%
\immediate%
\ifeof\ebarin%
%
\else%
   \immediate\read\ebarin to \ebarinon%
   \global\ebaroncapture=\ebarinon%
   \global\ebaroncapturesave=\ebarinon%
\fi%
}
%
%    ebargetoff
%
%    Gets the next ebar reference from the ebar input file
%
%    Specifically, gets the relative page number output from the prior
%    pass of genebar macro
%
\def\ebargetoff{%
\immediate%
\ifeof\ebarin%
%
\else%
   \immediate\read\ebarin to \ebarinoff%
   \global\ebaroffcapture=\ebarinoff%
\fi%
}
%
%    endebarthispage
%
%    Check edit bar status to end an edit bar on this page
%
\def\endebarthispage{%
   \ifnum\ebarpagesspan=0%
   \else%
      \ifnum\ebaroncapturesave>\count0%
         \global\ebaronpagedelay=1%
      \else%
         \genebaroffpage{}%
      \fi%
   \fi%
}%
%
%    beginebarnextpage
%
%    Check edit bar status to begin an edit bar on next page
%
\def\beginebarnextpage{%
   \ifnum\ebarpagesspan>0%
      \ifnum\ebaronpagedelay=1%
          \global\ebaronpagedelay=0%
      \else
         \genebaronpage{}%
         \global\advance\ebarpagesspan by -1%
      \fi%
   \fi%
}%
%
%    ebarspecialstart, ebarspecialodd, ebarspecialeven, and ebarspecialend
%
%    Start, Odd and even pages, and end special macros
%                              
\newtoks\ebarendline
\ebarendline={ }%
%
%
\def\ebarspecialstart{%
   \special{ps:%
      /SPECIALSTART pop                    %  FOR DEBUGGING PostScript
      Resolution 72 div /Point exch def    %  Get points conversion
      currentpoint                         %  Get current Y point       
      Point \the\ebarbarheight\the\ebarendline %
      mul sub  /Y1point exch def           %  Get current Y point 
                                           %    minus ebar height
      }%
}%
%
\def\ebarspecialodd{%
      \special{ps:%
      /SPECIALODD pop                           %  FOR DEBUGGING PostScript
         Point \the\ebaroddside\the\ebarendline %
         mul   /Xpoint exch def                 %  Get X point
         }%
}%
%
\def\ebarspecialeven{%
      \special{ps:%
      /SPECIALEVEN pop                           %  FOR DEBUGGING PostScript
         Point \the\ebarevenside\the\ebarendline %
         mul  /Xpoint exch def                   %  Get X point
         }%
}%
%
\def\ebarspecialend{%
   \special{ps:%
      /SPECIALEND pop                          %  FOR DEBUGGING PostScript
      gsave                                    %
      Point \the\ebarbarwidth\the\ebarendline  %
      mul setlinewidth                         %  Edit Bar width
      currentpoint \the\ebarsubtract\the\ebarendline % Get current Y point
      Point mul sub /Y2point exch def          %  minus adjustment
      Xpoint Y1point moveto                    %
      Xpoint Y2point lineto stroke             %
      grestore}%
}%
%
%    genebaron
%
%    Writes the relative page number to the ebar output file,
%    reads from the ebar input file if open and generates the ebar on
%
%    Place where the ebar will occur
%
\def\genebaron{%
   \write\ebarout{\the\count0}%
\ifeof\ebarin%
\else%
   \global\advance\ebarnest by 1 %
%
   \ifnum\ebarnest=1 %
   \else%
     \@latexerr{Edit bar are nested, bad results can occur.}%
               {Please use genebaroff before using genebaron}%
   \fi%
%
   \ebargeton%                                        % Get ebar on page
   \ebargetoff%                                       % Get ebar off page
%
   \global\ebarpagesspan=\ebaroffcapture%             % Get page span
   \global\advance\ebarpagesspan by -\ebaroncapture%
%
   \special{ps:%
   /GENEBARON pop                    %  FOR DEBUGGING PostScript
   }%
%
   \ebarspecialstart%
%
   \if@twoside%
      \ifodd\ebaroncapture%
         \ebarspecialodd%
      \else%
         \ebarspecialeven%
      \fi%
   \else%
      \ebarspecialodd%
   \fi%
\fi%
}%
%
%    genebaronpage
%
%    Fake ebar on for page begin
%
%
\def\genebaronpage{%
\ifeof\ebarin%
\else%
   \special{ps:%
   /GENEBARONPAGE pop                    %  FOR DEBUGGING PostScript
   }%
   \ebarspecialstart%
%
   \if@twoside%
      \ifodd\count0%
         \ebarspecialodd%
      \else%
         \ebarspecialeven%
      \fi%
   \else%
      \ebarspecialodd%
   \fi%
\fi%
}%
%
%    genebaroff
%
%    Writes the relative page number to the ebar output file, and
%    generates special code for end
%
%    Place where the ebar will occur
%
\def\genebaroff{\write\ebarout{\the\count0}%
\ifeof\ebarin%
\else%
   \global\ebarsubtract=0 %
   \global\advance\ebarnest by -1 %
%
   \ifnum\ebarnest=0 %
   \else%
     \@latexerr{Edit bar are nested, bad results can occur.}%
               {Please use genebaron before using genebaroff}%
   \fi%
%
   \special{ps:%
   /GENEBAROFF pop                    %  FOR DEBUGGING PostScript
   }%
   \ebarspecialend%
\fi%
}%
%
%    genebaroffpage
%
%    Fake ebar off for page end
%
\def\genebaroffpage{%
\ifeof\ebarin%
\else%
   \global\ebarsubtract=\pagegoal % Get pagegoal
   \global\advance\ebarsubtract by -\pagetotal % subtract pagetotal
   \global\divide\ebarsubtract by 65536 % Divide by scaled points
%
   \special{ps:%
   /GENEBAROFFPAGE   pop              %  FOR DEBUGGING PostScript
   }%
   \ebarspecialend%
\fi%
}%
%
%
\globaldefs0%
%
% Sample shipout routine changes
%
\def\@outputpage{\begingroup\catcode`\ =10
     \let\-\@dischyph \let\'\@acci \let\`\@accii \let\=\@acciii
    \if@specialpage
     \global\@specialpagefalse\@nameuse{ps@\@specialstyle}\fi
     \if@twoside
       \ifodd\count\z@ \let\@thehead\@oddhead \let\@thefoot\@oddfoot
            \let\@themargin\oddsidemargin
          \else \let\@thehead\@evenhead
          \let\@thefoot\@evenfoot \let\@themargin\evensidemargin
     \fi\fi
     \shipout
     \vbox{\normalsize \baselineskip\z@ \lineskip\z@
           \let\par\@@par %% 15 Sep 87
           \vskip \topmargin \moveright\@themargin
           \vbox{\setbox\@tempboxa
                   \vbox to\headheight{\vfil \hbox to\textwidth
                                       {\let\label\@gobble \let\index\@gobble
                                         \@thehead}} %% 22 Feb 87
                 \dp\@tempboxa\z@
                 \box\@tempboxa
                 \vskip \headsep
%
                 \box\@outputbox
%
                 \endebarthispage%
%
                 \baselineskip\footskip
                 \hbox to\textwidth{\let\label\@gobble
                           \let\index\@gobble  %% 22 Feb 87
                           \@thefoot}}}\global\@colht\textheight
           \endgroup\stepcounter{page}\let\firstmark\botmark%
%
           \beginebarnextpage{}}
