%%
%% This is file `notespages.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% notespages.dtx  (with options: `package')
%% 
%% Copyright 2016 Mike Kaufmann
%%                m.km@gmx.de
%% 
%% 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 this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%% 
%% This work has the LPPL maintenance status `maintained'.
%% 
%% The Current Maintainer of this work is Mike Kaufmann.
%% 
%% This work consists of the files notespages.dtx and notespages.ins
%% and the derived files notespages.sty and np-test.tex.
%% 
%% \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         \~}
%%
%%
\def\fileversion{0.8.1}
\def\filedate{2016/08/21}

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{notespages}[\filedate\space
    v\fileversion\space filling documents, so the total number of pages
    is a multiple of a given number]
\RequirePackage{xkeyval}
\newcommand*{\npnotesname}{Notes}
\newcommand*{\npnotestext}{This page is intentionally left blank.}
\newcommand*{\remainingtextheight}{}
\newdimen\remainingtextheight
\newcommand*{\notestitletext}{}
\newcommand*{\notesareatext}{}
\newcommand*{\np@startnotes}{}
\newcommand*{\np@pagestyle}{}
\newcommand*{\np@notesstyle}{}
\newcommand*{\np@titlestyle}{}
\newcommand*{\np@titleskip}{}
\newdimen\np@titleskip
\newcommand*{\np@notesalign}{}
\newcommand*{\np@mark}{}
\newcommand*{\np@marktext}{}
\newcommand*{\np@hparts}{}
\newcount\np@hparts
\newcommand*{\np@vparts}{}
\newcount\np@vparts
\newcommand*{\np@height}{}
\newdimen\np@height
\newcommand*{\np@width}{}
\newdimen\np@width
\newcommand*{\np@save@marks@tokens}{}
\newtoks\np@save@marks@tokens
\newcommand*{\ifnp@marktext@set}{}
\newif\ifnp@marktext@set\np@marktext@setfalse
\newcommand*{\ifnp@mark@new}{}
\newif\ifnp@mark@new\np@mark@newfalse
\newcommand*{\ifnp@std@class}{}
\newif\ifnp@std@class\np@std@classfalse
\@ifclassloaded{article}{\np@std@classtrue}{}
\@ifclassloaded{report}{\np@std@classtrue}{}
\@ifclassloaded{book}{\np@std@classtrue}{}
\@ifclassloaded{memoir}{\np@std@classtrue}{}
\newcommand*{\np@minpages}{}
\newcount\np@minpages
\newcommand*{\np@endpages}{}
\newcount\np@endpages
\newcommand*{\np@multiple}{}
\newcount\np@multiple
\newcommand*{\np@notepages}{}
\newcount\np@notepages
\newcommand*{\ifnp@started@on@new@page}{}
\newif\ifnp@started@on@new@page
\newcommand*{\ifnp@started@on@full@page}{}
\newif\ifnp@started@on@full@page
\newcommand*{\np@fill@minspace}{}
\newdimen\np@fill@minspace
\newcommand*{\np@fill@maxspace}{}
\newdimen\np@fill@maxspace
\newcommand*{\np@fill@topskip}{}
\newdimen\np@fill@topskip
\newcommand*{\np@tempcnta}{}
\newcount\np@tempcnta
\newcommand*{\np@tempcntb}{}
\newcount\np@tempcntb
\newcommand*{\np@tempdima}{}
\newdimen\np@tempdima
\newcommand*{\np@tempa}{}
\newcommand*{\np@check@num@range}[4]{\relax
  \ifnum#2<#3\relax
    \PackageWarning{notespages}{%
      Value for #1 to small, set to #3\MessageBreak}#2=#3\relax
  \else\ifnum#2>#4\relax
    \PackageWarning{notespages}{%
      Value for #1 to large, set to #4\MessageBreak}#2=#4\relax
  \fi\fi}
\newcommand*{\np@err@defined}[1]{%
  \PackageError{notespages}%
    {Key #1 is already defined.\MessageBreak}%
    {The key #1 may have been defined by some other package\MessageBreak
     or the NotesPages package was loaded twice.}}
\key@ifundefined{np}{startnotes}{}{\np@err@defined{startnotes}}
\define@choicekey{np}{startnotes}[\np@startnotes]%
  {clearpage,newpage}[clearpage]{}
\key@ifundefined{np}{allowfloats}{}{\np@err@defined{allowfloats}}
\define@boolkey{np}{allowfloats}[true]{}
\key@ifundefined{np}{pagestyle}{}{\np@err@defined{pagestyle}}
\define@cmdkey{np}[np@]{pagestyle}[current]{%
  \def\np@tempa{current}\ifx\np@tempa\np@pagestyle\else
    \@ifundefined{ps@#1}{%
      \PackageWarning{notespages}{%
        `#1' is not a valid pagestyle, set to default\MessageBreak}%
      \def\np@pagestyle{current}}{}\fi}
\key@ifundefined{np}{notesstyle}{}{\np@err@defined{notesstyle}}
\define@choicekey{np}{notesstyle}[\np@notesstyle]%
  {plain,lines,vlines,grid,text}[grid]{}
\newcommand*{\np@notesstyle@nominations}{plain,lines,vlines,grid,text}
\newcommand*{\np@def@notesstyle@key}{}
\def\np@def@notesstyle@key#1\np@end{%
  \define@choicekey{np}{notesstyle}[\np@notesstyle]{#1}[grid]{}}
\key@ifundefined{np}{titlestyle}{}{\np@err@defined{titlestyle}}
\@ifundefined{minisec}{%
  \define@choicekey{np}{titlestyle}[\np@titlestyle]%
    {none,text,section,subsection,subsubsection}[section]{}%
  \newcommand*{\np@titlestyle@nominations}%
    {none,text,section,subsection,subsubsection}}{%
  \define@choicekey{np}{titlestyle}[\np@titlestyle]%
    {none,text,section,subsection,subsubsection,minisec}[section]{}%
  \newcommand*{\np@titlestyle@nominations}%
    {none,text,section,subsection,subsubsection,minisec}}
\newcommand*{\np@def@titlestyle@key}{}
\def\np@def@titlestyle@key#1\np@end{%
  \define@choicekey{np}{titlestyle}[\np@titlestyle]{#1}[section]{}}
\key@ifundefined{np}{titletext}{}{\np@err@defined{titletext}}
\define@key{np}{titletext}[\npnotesname]%
  {\ifnp@marktext@set\else\def\np@marktext{#1}\fi
    \def\notestitletext{#1}}
\key@ifundefined{np}{titleskip}{}{\np@err@defined{titleskip}}
\define@key{np}{titleskip}[0pt]{\np@titleskip=#1}
\key@ifundefined{np}{titlenotesfill}{}{\np@err@defined{titlenotesfill}}
\define@boolkey{np}{titlenotesfill}[true]{}
\key@ifundefined{np}{notestext}{}{\np@err@defined{notestext}}
\define@key{np}{notestext}[\npnotestext]{\def\notesareatext{#1}}
\key@ifundefined{np}{notestextalign}{}{\np@err@defined{notestextalign}}
\define@choicekey{np}{notestextalign}[\np@notesalign]%
  {left,right,center,none}[center]{}
\key@ifundefined{np}{mark}{}{\np@err@defined{mark}}
\define@choicekey{np}{mark}[\np@mark]{both,right,left,keep}[both]{}
\key@ifundefined{np}{marktext}{}{\np@err@defined{marktext}}
\define@cmdkey{np}[np@]{marktext}[\npnotesname]{\np@marktext@settrue}
\key@ifundefined{np}{markuppercase}{}{\np@err@defined{markuppercase}}
\define@boolkey{np}{markuppercase}[true]{}
\newcommand*{\np@init@markuppercase}{%
  \ifnp@std@class
    \setkeys{np}{markuppercase=true}%
  \else
    \setkeys{np}{markuppercase=false}%
  \fi}
\key@ifundefined{np}{hparts}{}{\np@err@defined{hparts}}
\define@key{np}{hparts}[25]%
  {\np@hparts=#1\np@check@num@range{hparts}{\np@hparts}{1}{200}}
\key@ifundefined{np}{vparts}{}{\np@err@defined{vparts}}
\define@key{np}{vparts}[0]%
  {\np@vparts=#1\np@check@num@range{vparts}{\np@vparts}{0}{300}}
\key@ifundefined{np}{usenotesareaheight}{}%
  {\np@err@defined{usenotesareaheight}}
\define@boolkey{np}{usenotesareaheight}[true]{}
\key@ifundefined{np}{multiple}{}{\np@err@defined{multiple}}
\define@key{np}{multiple}[4]%
  {\np@multiple=#1\np@check@num@range{multiple}{\np@multiple}{1}{100}}
\key@ifundefined{np}{minpages}{}{\np@err@defined{minpages}}
\define@key{np}{minpages}[0]%
  {\np@minpages=#1\np@check@num@range{minpages}{\np@minpages}{0}{100}}
\key@ifundefined{np}{endpages}{}{\np@err@defined{endpages}}
\define@key{np}{endpages}[0]%
  {\np@endpages=#1\np@check@num@range{endpages}{\np@endpages}{0}{100}}
\key@ifundefined{np}{fillminspace}{}{\np@err@defined{fillminspace}}
\define@key{np}{fillminspace}[0.25\textheight]{\np@fill@minspace=#1}
\key@ifundefined{np}{fillmaxspace}{}{\np@err@defined{fillmaxspace}}
\define@key{np}{fillmaxspace}[\textheight]{\np@fill@maxspace=#1}
\key@ifundefined{np}{filltopskip}{}{\np@err@defined{filltopskip}}
\define@key{np}{filltopskip}[0pt]{\np@fill@topskip=#1}
\key@ifundefined{np}{filltopfill}{}{\np@err@defined{filltopfill}}
\define@boolkey{np}{filltopfill}[true]{}
\key@ifundefined{np}{empty}{}{\np@err@defined{empty}}
\define@key{np}{empty}[]{\setkeys{np}{%
  pagestyle=empty,notesstyle=plain,titlestyle=none}}
\key@ifundefined{np}{vacant}{}{\np@err@defined{vacant}}
\define@key{np}{vacant}[]{\setkeys{np}{pagestyle=empty,
  notesstyle=text,titlestyle=none,titleskip=0.3\textheight}}
\key@ifundefined{np}{default}{}{\np@err@defined{default}}
\define@key{np}{default}[]{\setkeys{np}{%
  startnotes,allowfloats=false,pagestyle,notesstyle,
  titlestyle,titletext,titleskip,titlenotesfill=false,
  notestext,notestextalign,
  mark,marktext,
  hparts=25,vparts=0,usenotesareaheight=false,
  minpages,endpages,multiple=4,
  fillminspace,fillmaxspace,filltopskip,filltopfill}%
  \np@init@markuppercase}
\setkeys{np}{default}
\ProcessOptionsX<np>
\newcommand*{\npnpinfo}[1]{%
  \expandafter\def\csname np@np@info.#1\endcsname{}}
\AtEndDocument{\if@filesw\newwrite\tf@npm
  \immediate\openout\tf@npm\jobname.npm\fi
  \ifnp@mark@new
    \PackageWarningNoLine{notespage}{%
      New notes pages were added.
      Please rerun LaTeX to get header marks right.}%
  \fi}
\newcommand*{\tracingnpmarks}{}
\newcount\tracingnpmarks
\tracingnpmarks\z@
\newcommand{\np@tracing@marks}[3]{%
  \ifnum\tracingnpmarks>\z@
    \PackageInfo{notespages}{#1 header marks: #2 done\MessageBreak
      #3\MessageBreak}%
  \fi}
\newcommand*{\ifnp@page@has@np}{}
\newif\ifnp@page@has@np
\newcommand*{\np@page@has@np}[1]{%
  \@ifundefined{np@np@info.#1}%
    {\np@page@has@npfalse}{\np@page@has@nptrue}}
\newcommand*{\np@mark@keep}{TT\fi
  \def\np@tempa{keep}\ifx\np@tempa\np@mark}
\newcommand*{\np@savemark}{%
  \if\np@mark@keep
    \np@tracing@marks{save}{not}{mark=keep (1)}%
  \else
    \np@tempcnta\c@page\advance\np@tempcnta\m@ne
    \np@page@has@np{\the\np@tempcnta}\ifnp@page@has@np
      \np@tracing@marks{save}{not}{np on previous page (2)}%
    \else
      \np@tracing@marks{save}{}{mark not keep (3)}%
      \global\np@save@marks@tokens\expandafter{\@themark}%
    \fi
  \fi}
\newcommand*{\np@@markleft}[3]{\markboth{#3}{#2}}
\newcommand*{\np@@markright}[3]{\markboth{#1}{#3}}
\newcommand*{\np@markleft}[1]{%
  \expandafter\np@@markleft\the\np@save@marks@tokens{#1}}
\newcommand*{\np@markright}[1]{%
  \expandafter\np@@markright\the\np@save@marks@tokens{#1}}
\newcommand*{\np@setmark}{
  \if\np@mark@keep
    \np@tracing@marks{set}{not}{mark=keep (4)}%
  \else
    \np@page@has@np{\the\c@page}\ifnp@page@has@np\else
      \global\np@mark@newtrue
    \fi
    \def\np@tempa{both}\ifx\np@tempa\np@mark
      \np@tracing@marks{set}{}{mark=both (5)}%
      \ifKV@np@markuppercase
        \markboth{\MakeUppercase{\np@marktext}}%
          {\MakeUppercase{\np@marktext}}%
      \else
        \markboth{\np@marktext}{\np@marktext}%
      \fi
    \else
      \def\np@tempa{right}\ifx\np@tempa\np@mark
        \np@tracing@marks{set}{}{mark=right (6)}%
        \ifKV@np@markuppercase
          \np@markright{\MakeUppercase{\np@marktext}}%
        \else
          \np@markright{\np@marktext}%
        \fi
      \else
        \def\np@tempa{left}\ifx\np@tempa\np@mark
          \np@tracing@marks{set}{}{mark=left (7)}%
          \ifKV@np@markuppercase
            \np@markleft{\MakeUppercase{\np@marktext}}%
          \else
            \np@markleft{\np@marktext}%
          \fi
        \fi
      \fi
    \fi
  \fi}
\newcommand*{\np@restore@@mark}[4]{%
  \begingroup
    \let\label\relax \let\index\relax \let\glossary\relax
    \@temptokena {#4}%
    \unrestored@protected@xdef\@themark{%
      {\protect\ifnum\the\np@tempcnta=\c@page
        #3\protect\else #1\protect\fi}%
      {\the\@temptokena}}%
    \@temptokena \expandafter{\@themark}%
    \mark{\the\@temptokena}%
    \@temptokena {#4}%
    \unrestored@protected@xdef\@themark{{#3}{\the\@temptokena}}%
  \endgroup
  \if@nobreak\ifvmode\nobreak\fi\fi}
\newcommand*{\np@restore@mark}[2]{%
  \expandafter\np@restore@@mark\@themark{#1}{#2}}
\newcommand*{\np@restoremark}{%
  \if\np@mark@keep
    \np@tracing@marks{restore}{not}{mark=keep (8)}%
  \else
    \np@tempcnta\c@page\advance\np@tempcnta\@ne
    \np@page@has@np{\the\np@tempcnta}\ifnp@page@has@np
      \np@tracing@marks{restore}{not}{np on next page (9)}%
    \else
      \np@tracing@marks{restore}{}{(10)}%
      \expandafter\np@restore@mark\the\np@save@marks@tokens
    \fi
  \fi}
\newcommand*{\np@startnotespage}{%
  \expandafter\csname \np@startnotes\endcsname}
\newcommand*{\np@setpagestyle}{%
  \def\np@tempa{current}\ifx\np@tempa\np@pagestyle\else
    \thispagestyle{\np@pagestyle}\fi}
\newcommand*{\np@ts@section}{\section*{\notestitletext}}
\newcommand*{\np@ts@subsection}{\subsection*{\notestitletext}}
\newcommand*{\np@ts@subsubsection}{\subsubsection*{\notestitletext}}
\newcommand*{\np@ts@minisec}{\minisec{\notestitletext}}
\newcommand*{\np@ts@text}{\noindent\notestitletext\par}
\newcommand*{\np@ts@none}{}
\newcommand*{\np@maketitle}{\csname np@ts@\np@titlestyle\endcsname}
\newcommand*{\np@calcheight}{%
  \ifdim\pagegoal=\maxdimen
    \remainingtextheight\textheight
  \else
    \remainingtextheight\pagegoal
    \advance\remainingtextheight by -\pagetotal
    \advance\remainingtextheight by -\lineskip
  \fi}
\newcommand*{\np@Tc}{}
\newcount\np@Tc
\newcommand*{\np@Zc}{}
\newcount\np@Zc
\newcommand*{\np@Nc}{}
\newcount\np@Nc
\newcommand*{\np@Z}{}
\newdimen\np@Z
\newcommand*{\np@N}{}
\newdimen\np@N
\newcommand*{\np@result}{}
\newcommand*{\np@calcnextdigit}{%
  \multiply\np@Tc\np@Nc
  \advance\np@Zc-\np@Tc
  \multiply\np@Zc10\relax
  \np@Tc\np@Zc
  \divide\np@Tc\np@Nc
  \xdef\np@result{\np@result\number\np@Tc}}
\newcommand*{\np@divide}{%
  \gdef\np@result{}%
  \global\np@Zc\np@Z\global\np@Nc\np@N
  \ifnum\np@Zc<\z@\np@Zc-\np@Zc\gdef\np@result{-}\fi
  \ifnum\np@Nc<\z@\np@Nc-\np@Nc\xdef\np@result{\np@result-}\fi
  \np@Tc\np@Zc
  \divide\np@Tc\np@Nc
  \xdef\np@result{\np@result\number\np@Tc.}%
  \np@calcnextdigit\np@calcnextdigit\np@calcnextdigit
  \np@calcnextdigit\np@calcnextdigit\np@calcnextdigit}
\newcommand*{\np@dddivide}[2]{\global\np@Z#1\global\np@N#2\np@divide}
\newcommand*{\np@truncate}{}
\def\np@truncate#1.#2\np@end{#1}
\newcommand{\np@ns@plain}{%
  \phantom{\rule{\textwidth}{\remainingtextheight}}}
\newcommand{\np@calc@vheight}{%
  \ifKV@np@usenotesareaheight
    \np@height\remainingtextheight\divide\np@height\np@vparts
    \np@tempcntb\np@vparts
  \else
    \np@height\textheight\divide\np@height\np@vparts
    \np@dddivide\remainingtextheight\np@height
    \expandafter\np@tempdima\np@result\p@
    \advance\np@tempdima0.01\p@
    \edef\np@tempa{\expandafter\np@truncate\the\np@tempdima\np@end}%
    \np@tempcntb\np@tempa\relax
  \fi}
\newcommand{\np@ns@lines}{%
  \ifnum\np@vparts=\z@\relax
    \PackageWarning{notespages}{vparts is 0, there are no lines
      \MessageBreak}%
    \np@ns@plain
  \else\ifnum\np@vparts=\@ne\relax
    \let\unitlength\relax
    \begin{picture}(\textwidth,\remainingtextheight)(\z@,\z@)%
    \color{NotesHColor}%
    \multiput(\z@,\z@)(\z@,\remainingtextheight){2}%
      {\line(1,0){\textwidth}}%
    \end{picture}%
  \else
    \np@calc@vheight
    \let\unitlength\relax
    \begin{picture}(\textwidth,\remainingtextheight)(\z@,\z@)%
    \color{NotesHColor}%
    \multiput(\z@,\z@)(\z@,\np@height){\np@tempcntb}%
      {\line(1,0){\textwidth}}%
    \end{picture}%
  \fi\fi}
\newcommand{\np@ns@vlines}{%
  \np@width\textwidth\divide\np@width\np@hparts
  \np@tempcnta\np@hparts\advance\np@tempcnta\@ne\relax
  \let\unitlength\relax
  \begin{picture}(\textwidth,\remainingtextheight)(\z@,\z@)%
  \color{NotesVColor}%
  \multiput(\z@,\z@)(\np@width,\z@){\np@tempcnta}%
    {\line(0,1){\remainingtextheight}}%
  \end{picture}}
\newcommand{\np@ns@grid}{%
  \np@width\textwidth\divide\np@width\np@hparts
  \np@tempcnta\np@hparts\advance\np@tempcnta\@ne\relax
  \ifnum\np@vparts=\z@\relax
    \np@height\np@width
    \np@dddivide\remainingtextheight\np@height
    \expandafter\np@tempdima\np@result\p@
    \advance\np@tempdima0.01\p@
    \edef\np@tempa{\expandafter\np@truncate\the\np@tempdima\np@end}%
    \np@tempcntb\np@tempa\relax
    \np@tempdima\np@height\multiply\np@tempdima\np@tempcntb
    \advance\np@tempcntb\@ne\relax
  \else\ifnum\np@vparts=\@ne\relax
    \np@height\remainingtextheight
    \np@tempcntb\tw@\relax
    \np@tempdima\np@height
  \else
    \np@calc@vheight
    \np@tempdima\np@height\multiply\np@tempdima\np@tempcntb
    \advance\np@tempcntb\@ne
  \fi\fi
  \let\unitlength\relax
  \begin{picture}(\textwidth,\remainingtextheight)(\z@,\z@)%
  \color{NotesVColor}%
  \multiput(\z@,\z@)(\np@width,\z@){\np@tempcnta}%
    {\line(0,1){\np@tempdima}}%
  \color{NotesHColor}%
  \multiput(\z@,\z@)(\z@,\np@height){\np@tempcntb}%
    {\line(1,0){\textwidth}}%
  \end{picture}}
\newcommand{\np@ns@text}{%
  \def\np@tempa{none}\ifx\np@tempa\np@titlestyle
    \hrule\@height\z@
    \vspace*{\np@titleskip}%
  \fi
  \def\np@tempa{left}\ifx\np@tempa\np@notesalign
%%    \typeout{notespages debug: notestextalign=left}%
    \raggedright
  \else
    \def\np@tempa{right}\ifx\np@tempa\np@notesalign
%%      \typeout{notespages debug: notestextalign=right}%
      \raggedleft
    \else
      \def\np@tempa{center}\ifx\np@tempa\np@notesalign
%%        \typeout{notespages debug: notestextalign=center}%
        \centering
      \fi
    \fi
  \fi
  \color{NotesTextColor}\notesareatext\par}
\newcommand{\np@inner@notespage}{\parfillskip\z@ plus 1fil%
  \begingroup
  \csname np@ns@\np@notesstyle\endcsname
  \endgroup}
\newcommand*{\np@notespage}{%
  \ifKV@np@allowfloats\else
    \def\np@tempa{newpage}\ifx\np@tempa\np@startnotes
      \edef\np@orig@textfraction{\textfraction}%
      \gdef\textfraction{1}%
    \fi
  \fi
  \np@startnotespage
  \np@savemark
  \np@setmark
  \if\np@mark@keep\else
    \protected@write\@auxout{}%
      {\string\@writefile{npm}{\string\npnpinfo{\the\c@page}}}%
  \fi
  \np@setpagestyle
  \np@maketitle
  \def\np@tempa{none}\ifx\np@tempa\np@titlestyle\else
    \vspace*{\np@titleskip}%
  \fi
  \noindent\np@calcheight
  \ifKV@np@titlenotesfill\vfill\noindent\fi
  \np@inner@notespage
  \np@restoremark
  \ifKV@np@allowfloats\else
    \def\np@tempa{newpage}\ifx\np@tempa\np@startnotes
      \xdef\textfraction{\np@orig@textfraction}%
    \fi
  \fi
  \newpage}
\newcommand*{\notespage}[1][]{%
  \begingroup
  \np@marktext@setfalse\setkeys{np}{#1}%
  \np@notespage
  \endgroup}
\newcommand*{\notespages}[1][]{%
  \begingroup
  \np@marktext@setfalse\setkeys{np}{#1}%
%%  \typeout{notespages debug:\space\the\pagetotal\space\the\pagegoal}%
  \ifdim\pagetotal=\z@
    \np@started@on@new@pagetrue\else\np@started@on@new@pagefalse\fi
  \ifdim\pagetotal<\pagegoal
    \np@started@on@full@pagefalse\else\np@started@on@full@pagetrue\fi
  \np@notepages\c@page
  \ifnp@started@on@new@page\advance\np@notepages\m@ne\fi
  \ifnp@started@on@full@page\advance\np@notepages\@ne\fi
  \divide\np@notepages\np@multiple
  \multiply\np@notepages\np@multiple
  \advance\np@notepages-\c@page
  \ifnp@started@on@new@page\advance\np@notepages\@ne\fi
  \ifnp@started@on@full@page\advance\np@notepages\m@ne\fi
  \ifnum\np@notepages<\z@
    \advance\np@notepages\np@multiple\fi
  \np@tempcnta\np@endpages
  \np@tempcntb\np@endpages
  \divide\np@tempcnta\np@multiple
  \multiply\np@tempcnta\np@multiple
  \advance\np@tempcntb-\np@tempcnta
  \advance\np@notepages-\np@tempcntb
  \np@tempcnta\np@minpages
  \divide\np@tempcnta\np@multiple
  \multiply\np@tempcnta\np@multiple
  \advance\np@notepages\np@tempcnta
  \ifnum\np@notepages<\np@minpages
    \advance\np@notepages\np@multiple\relax\fi
  \ifnum\np@notepages>\z@\relax
    \loop\ifnum\np@notepages>\z@\relax
      \np@notespage\advance\np@notepages\m@ne\relax
    \repeat
  \fi
  \endgroup}
\newcommand*{\notesfill}[1][]{%
  \begingroup
  \setkeys{np}{#1}%
  \np@calcheight
  \advance\remainingtextheight-\np@fill@topskip
  \ifdim\remainingtextheight<\np@fill@minspace\else
    \ifdim\remainingtextheight>\np@fill@maxspace
      \np@tempdima\remainingtextheight
      \advance\np@tempdima-\np@fill@maxspace
    \else
      \np@tempdima=\z@
    \fi
    \vspace*{\np@fill@topskip}
    \ifKV@np@filltopfill\vfill\fi
    \np@maketitle
    \def\np@tempa{none}\ifx\np@tempa\np@titlestyle\else
      \vspace*{\np@titleskip}%
    \fi
    \noindent\np@calcheight
    \advance\remainingtextheight-\np@tempdima
    \ifKV@np@titlenotesfill\vfill\noindent\fi
    \np@inner@notespage\newpage
  \fi
  \endgroup}
\newcommand*{\setnotespages}[1]{%
  \np@marktext@setfalse\setkeys{np}{#1}}
\newcommand*{\definenotesoption}[2]{%
  \key@ifundefined{np}{#1}{\define@key{np}{#1}[]{\setkeys{np}{#2}}}%
    {\PackageError{notespages}%
      {Key #1 is already defined.\MessageBreak}%
      {The key #1 may have been defined by some package\MessageBreak
       or you tried to redefine this key.}}}
\newcommand{\definenotesstyle}[2]{%
  \edef\np@notesstyle@nominations{\np@notesstyle@nominations,#1}%
  \expandafter\np@def@notesstyle@key\np@notesstyle@nominations\np@end
  \long\expandafter\def\csname np@ns@#1\endcsname{#2}}
\newcommand{\definetitlestyle}[2]{%
  \edef\np@titlestyle@nominations{\np@titlestyle@nominations,#1}%
  \expandafter\np@def@titlestyle@key\np@titlestyle@nominations\np@end
  \long\expandafter\def\csname np@ts@#1\endcsname{#2}}
\let\np@orig@chapter\chapter
\newcommand{\nppatchchapter}[1]{%
  \@ifundefined{chapter}{}{%
    \def\chapter{\notespages[#1]\np@orig@chapter}}}
\newcommand{\npunpatchchapter}{%
  \@ifundefined{chapter}{}{\let\chapter\np@orig@chapter}}
\newcommand*{\np@lang@german}{\def\npnotesname{Notizen}%
  \def\npnotestext{Diese Seite wurde absichtlich leer gelassen.}}
\newcommand*{\np@lang@english}{\def\npnotesname{Notes}%
  \def\npnotestext{This page is intentionally left blank.}}
\newcommand*{\np@lang@french}{\def\npnotesname{Notes}%
  \def\npnotestext{Cette page est laiss\'{e}e intentionnellement vide.}}
\newcommand*{\np@declarelang}[2]{%
  \@ifpackagewith{babel}{#1}{%
    \expandafter\addto
      \csname extras#1\expandafter\endcsname
      \csname np@lang@#2\endcsname}{}}
\newcommand*{\np@supportbabel}{%
  \@ifpackageloaded{babel}{%
    \np@declarelang{english}{english}%
    \np@declarelang{USenglish}{english}%
    \np@declarelang{american}{english}%
    \np@declarelang{UKenglish}{english}%
    \np@declarelang{british}{english}%
    \np@declarelang{canadian}{english}%
    \np@declarelang{australian}{english}%
    \np@declarelang{newzealand}{english}%
    \np@declarelang{austrian}{german}%
    \np@declarelang{german}{german}%
    \np@declarelang{germanb}{german}%
    \np@declarelang{ngerman}{german}%
    \np@declarelang{naustrian}{german}%
    \np@declarelang{french}{french}%
    \np@declarelang{francais}{french}%
    \np@declarelang{canadien}{french}%
    \np@declarelang{acadian}{french}}{}}
\np@supportbabel
\newcommand*{\np@setcolors}{%
  \@ifundefined{\string\color @NotesHColor}%
    {\definecolor{NotesHColor}{gray}{0.7}}{}%
  \@ifundefined{\string\color @NotesVColor}%
    {\definecolor{NotesVColor}{gray}{0.7}}{}%
  \@ifundefined{\string\color @NotesTextColor}%
    {\definecolor{NotesTextColor}{gray}{0.7}}{}}

\newcommand*{\np@setxcolors}{%
  \providecolor{NotesHColor}{gray}{0.7}%
  \providecolor{NotesVColor}{gray}{0.7}%
  \providecolor{NotesTextColor}{gray}{0.7}}

\newcommand*{\np@supportcolor}{%
  \@ifpackageloaded{xcolor}{\np@setxcolors}{%
  \@ifpackageloaded{color}{\np@setcolors}{\let\color\@gobble}}}
\AtBeginDocument{\InputIfFileExists{\jobname.npm}{}{}%
  \np@supportbabel\np@supportcolor}
\endinput
%%
%% End of file `notespages.sty'.
