%%
%% This is file `continue.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% continue.dtx  (with options: `usc')
%% ------------------------------------------------------------------
%%   Author: Peter Wilson (Herries Press) herries dot press at earthlink dot net
%%   Copyright 2015 Peter R. Wilson, Donald Arseneau, Luca Merciadri
%% 
%%   This work may be distributed and/or modified under the
%%   conditions of the Latex Project Public License, either
%%   version 1.3 of this license or (at your option) any
%%   later version.
%%   The latest version of the license is in
%%     http://www.latex-project.org/lppl.txt
%%   and version 1.3 or later is part of all distributions of
%%   LaTeX version 2003/06/01 or later.
%% 
%%   This work has the LPPL maintenance status "author-maintained".
%% 
%%   This work consists of the files listed in the README file.
%% ------------------------------------------------------------------

 \NeedsTeXFormat{LaTeX2e}
 \ProvidesPackage{continue}[2015/12/04 v0.1 Continues on the following page]
 \PackageInfo{continue}{This is continue using e-TeX.}

 \newif{\ifcontmargin} \contmarginfalse
 \newif{\ifcontword}   \contwordfalse
 \DeclareOption{margin}{\contmargintrue}
 \DeclareOption{word}{\contwordtrue}
 \ProcessOptions

 \RequirePackage{atbegshi}
 \RequirePackage{picture}
 \RequirePackage{zref-abspage}
 \RequirePackage{zref-lastpage}

 \ifcontword
 \mathchardef\LWC@pen 13452
 \newbox\FirstWordBoxC     \global\setbox\FirstWordBoxC\hbox{}
 \newbox\NextWordBoxC      \global\setbox\NextWordBoxC\hbox{}
 \newbox\LastWordBoxC      \global\setbox\LastWordBoxC\hbox{}
 \newbox\LWC@box           \global\setbox\LWC@box\hbox{}
 \newbox\LWC@saved
 \edef\FWLWCnorm@L@output{\the\output}

 \output{\@tempswafalse
 \ifnum \outputpenalty>-\@MM \ifnum\outputpenalty<-\@M \@tempswatrue\fi\fi
 \if@tempswa % special (float) output
    \FWLWCnorm@L@output
 \else
   \ifvoid\LWC@saved % end of real page
      \global\setbox\LWC@saved\copy\@cclv % save page
      \setbox\@tempboxa\vbox{\unvbox\@cclv \unskip\unkern\unpenalty%
       \unskip\unkern\unpenalty \unskip\unkern\unpenalty
        \setbox\@tempboxa\lastbox
        \LWC@getlast@word\@tempboxa\LastWordBoxC
      }
      \ifnum\outputpenalty>-\@MM % not \supereject
        \xdef\LWC@vsize{\global\vsize\the\vsize
           \global\holdinginserts\the\holdinginserts}%
        \global\vsize\z@ \global\holdinginserts\@ne
      \else % \supereject, just output, don't look for word on next page
        \global\setbox\@cclv\box\LWC@saved
        \global\setbox\NextWordBoxC\hbox{}%
        \FWLWCnorm@L@output
        \global\setbox\FirstWordBoxC\box\NextWordBoxC
      \fi
   \else % saved page => just did tiny page to get next word
      \setbox\@tempboxa\vbox{\penalty\LWC@pen\unvcopy\@cclv \LWC@getall@boxes
        \ifvbox\LWC@box \penalty\LWC@pen\unvbox\LWC@box \LWC@getall@boxes\fi
        \ifvbox\LWC@box \global\setbox\NextWordBoxC\hbox{}\else
          \LWC@getfirst@word\LWC@box\NextWordBoxC
        \fi}%  Return tiny page to page list:
      \unvbox\@cclv \ifnum\outputpenalty<\@M \penalty\outputpenalty\fi
      \LWC@vsize\relax
      \global\setbox\@cclv\box\LWC@saved
      \FWLWCnorm@L@output
      \global\setbox\FirstWordBoxC\box\NextWordBoxC
 \fi\fi}

 \def\LWC@getlast@word#1#2{\setbox\@tempboxa\vbox{\hsize\maxdimen \@parboxrestore
   \hyphenpenalty\@M \exhyphenpenalty\@M
   \rightskip\fill \looseness\@M \linepenalty\z@
   \noindent\unhbox#1\endgraf
   \unskip\unkern\unpenalty \global\setbox\LWC@box\lastbox
   }\LWC@repack{#2}}

 \def\LWC@getfirst@word#1#2{\setbox\@tempboxa\vbox{\@parboxrestore
   \parshape\thr@@ \z@\z@ \z@\z@ \z@\maxdimen \parfillskip\fill
   \hyphenpenalty\@M \exhyphenpenalty\@M
   \hbadness\@MM \overfullrule\z@ \hfuzz\maxdimen
   \ifhbox#1\noindent
    \vadjust{\penalty\LWC@pen}\penalty-\@M\unhbox#1% eliminate previous \leftskip
   \else\ifvbox#1\penalty\LWC@pen\unvbox#1\fi\fi
   \endgraf
   \@tempcnta\z@  \LWC@getall@boxes}\LWC@repack{#2}}

 \def\LWC@getall@boxes{\global\setbox\LWC@box\lastbox \unskip\unkern \unskip\unkern
   \let\@tempa\relax
   \ifvoid \LWC@box \advance\@tempcnta\@ne \else \@tempcnta\z@ \fi
   \ifnum\lastpenalty=\LWC@pen \else \unpenalty\fi
   \ifnum\lastpenalty=\LWC@pen \else \unpenalty\fi
   \ifnum\lastpenalty=\LWC@pen \else \ifnum\@tempcnta<5
     \let\@tempa\LWC@getall@boxes \fi \fi \unpenalty \@tempa}

 \def\LWC@repack#1{\global\setbox#1\hbox{\ifhbox\LWC@box
    \unhbox\LWC@box\unskip\unskip\unpenalty\unskip
   \else\ifvbox\LWC@box\box\LWC@box\fi\fi}}
 \fi

 \newcommand*{\preflagword}{}
 \newcommand*{\postflagword}{}
 \newcommand*{\flagcont}{Continued}
 \newcommand*{\flagend}{End}
 \newcommand*{\flagword}{\preflagword\usebox\NextWordBoxC\postflagword}
 \newlength{\contsep}\setlength{\contsep}{\marginparsep}
 \newlength{\contdrop}\setlength{\contdrop}{0.5\footskip}
 \ifcontword
  \let\flagcont\flagword
 \fi
 \AtBeginShipout{%
 \AtBeginShipoutUpperLeft{%
     \ifodd\c@page
         \dimen1=1in
         \advance\dimen1 by \textwidth
         \advance\dimen1 by \oddsidemargin
         \dimen3=1in
         \advance\dimen3 by \topmargin
         \advance\dimen3 by \headheight
         \advance\dimen3 by \headsep
         \advance\dimen3 by \textheight
         \ifcontmargin
           \advance\dimen1 by \contsep
         \else
           \advance\dimen3 by \contdrop
         \fi
      \ifnum\zref@extract{LastPage}{abspage}>\c@abspage
        \ifcontmargin
          \put(\dimen1,-\dimen3){{\flagcont}}%
        \else
          \put(\dimen1,-\dimen3){\llap{\flagcont}}%
        \fi
      \else
        \ifcontmargin
          \put(\dimen1,-\dimen3){{\flagend}}%
        \else
          \put(\dimen1,-\dimen3){\llap{\flagend}}%
        \fi
      \fi%
    \fi%
}}

%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
\endinput
%%
%% End of file `continue.sty'.
