%%
%% 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, 2018 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 "unmaintained".
%% 
%%   This work consists of the files listed in the README file.
%% ------------------------------------------------------------------

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

 \newif{\ifcontmargin} \contmarginfalse
 \newif{\ifcontword}   \contwordfalse
 \newif{\ifcontallpages} \contallpagesfalse
 \DeclareOption{margin}{\contmargintrue}
 \DeclareOption{word}{\contwordtrue}
 \DeclareOption{allpages}{\contallpagestrue}
 \ProcessOptions

\newif{\ifc@go} \c@gotrue
\newcommand{\contgo}{\c@gotrue}
\newcommand{\contstop}{\c@gofalse}

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

 \mathchardef\LWC@pen 13452
 \newbox\FirstWordBox     \global\setbox\FirstWordBox\hbox{}
 \newbox\NextWordBox      \global\setbox\NextWordBox\hbox{}
 \newbox\LastWordBox      \global\setbox\LastWordBox\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\LastWordBox
      }
      \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\NextWordBox\hbox{}%
        \FWLWCnorm@L@output
        \global\setbox\FirstWordBox\box\NextWordBox
      \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\NextWordBox\hbox{}\else
          \LWC@getfirst@word\LWC@box\NextWordBox
        \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\FirstWordBox\box\NextWordBox
 \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}}

 \newcommand*{\preflagword}{}
 \newcommand*{\postflagword}{}
 \newcommand*{\flagcont}{Continued}
 \newcommand*{\flagend}{End}
 \newcommand*{\flagword}{\preflagword\usebox\NextWordBox\postflagword}
 \newlength{\contsep}\setlength{\contsep}{\marginparsep}
 \newlength{\contdrop}\setlength{\contdrop}{0.5\footskip}
 \ifcontword
  \let\flagcont\flagword
 \fi
 \newcommand{\c@ntoddpagepos}{%
     \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
 }
 \newcommand{\c@ntevenpagepos}{%
     \dimen1=1in
     \advance\dimen1 by \textwidth
     \advance\dimen1 by \evensidemargin
     \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
 }
\newcommand{\c@outcontpage}{%
  \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
}% end of \c@outcontpage
\AtBeginShipout{%
\AtBeginShipoutUpperLeft{%
 \ifc@go
  \ifodd\c@page
    \c@ntoddpagepos
    \c@outcontpage
  \else
    \ifcontallpages
      \c@ntevenpagepos
      \c@outcontpage
    \fi
  \fi
 \fi
} % end AtBeginShipoutUpperLeft
} % end AtBeginShipout

%% \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'.
