% \iffalse 
%<*internal>
\iffalse
%</internal>
%<*readme>
____________________
The addlines package
v0.2

This package provides the command \addlines for adding 
or removing space in the textblock of the page it's
used on. E.g., adding an extra line of text to the page
so that a section fits better on the next page.

It will also add space to the *facing* page in a 
two-sided document.

An inverse command is provided if you prefer it:
  \removelines{ x } == \addlines{ -x }
  
See addlines.pdf for more info.

______________
Will Robertson
wspr 81 [at] gmail [dot] com

Copyright 2007-2008
Distributed under the LaTeX Project Public License
%</readme>
%<*internal>
\fi
\begingroup
%</internal>
%<*batchfile>
\input docstrip.tex
\keepsilent
\preamble

  _______________________________________
  Copyright (C) 2007-2008  Will Robertson

  License information appended.


\endpreamble
\postamble

Copyright (C) 2007-2008 by Will Robertson <wspr81@gmail.com>

Distributable under the LaTeX Project Public License,
version 1.3c or higher (your choice). The latest version of
this license is at: http://www.latex-project.org/lppl.txt

This work is "maintained" (as per LPPL maintenance status) 
by Will Robertson.

This work consists of the files addlines.dtx and
                                addlines.ins,
          and the derived files addlines.pdf,
                                addlines.sty, and
                                addlines-example.ltx.

\endpostamble
\askforoverwritefalse
\generate{\file{\jobname.sty}{\from{\jobname.dtx}{package}}}
\generate{\file{\jobname-example.ltx}{\from{\jobname.dtx}{example}}}
%</batchfile>
%<batchfile>\endbatchfile
%<*internal>
\generate{\file{\jobname.ins}{\from{\jobname.dtx}{batchfile}}}
\nopreamble\nopostamble
\generate{\file{README.txt}{\from{\jobname.dtx}{readme}}}
\generate{\file{prepare.sh}{\from{\jobname.dtx}{prepare}}}
\generate{\file{dtx-style.sty}{\from{\jobname.dtx}{dtx-style}}}
\endgroup
\immediate\write18{makeindex -s gind.ist -o \jobname.ind  \jobname.idx}
\immediate\write18{makeindex -s gglo.ist -o \jobname.gls  \jobname.glo}
%</internal>
%
%<*driver>
\documentclass{ltxdoc}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\usepackage{dtx-style}
\begin{document}
  \DocInput{addlines.dtx}
\end{document}
%</driver>
% \fi
%
% \GetFileInfo{\jobname.sty}
% \CheckSum{0}
% \makeatletter
%
% \title{The \pkg{\jobname} package}
% \author{Will Robertson}
% \date{\filedate \qquad \fileversion}
%
% \maketitle
%
% \noindent
% This is a small package that defines a user command for adding lines
% to the current (and facing page, if appropriate). This is intended to be used in the 
% final typesetting
% process of a manuscript for running pages long or short in order to
% fit their material better (starting a paragraph on the next page,
% for example).
%
% The \cmd\addlines\ command adds enough vertical space to
% the current text block to fit in one more line of text. An optional
% argument specifies the number of lines to add; negative numbers
% \emph{remove} space, and fractional numbers are fine, too. For
% example:
% \begin{center}
% \begin{tabular}{l>{\itshape\small}l}
%  |\addlines| & adds one line to the current page height\\
%  |\addlines[2]| & adds two lines to the current page\\
%  |\addlines[-1]| & subtracts one line from the current page height
% \end{tabular}
% \end{center}
%
% The command should be placed somewhere near the middle of the page
% that it is intending to affect. Too near the top and it may not be
% seen in time (\LaTeX's page breaking routine is asynchronous).
%
% For syntactic sugar, \cmd{\addline} is a synonym for \cmd\addlines,
% and \cmd{\removeline\textcolor{gray}(s\textcolor{gray})} is the opposite of \cmd\addlines.
%
% As alluded to in the introduction, for a double-sided document 
% (\eg, if the class option |[twoside]| is in
% effect) extra height must be added to \emph{both pages} on a spread
% for things to look good. If \cmd\addlines\ is called on an even page
% (\ie, a \emph{verso} or left-side page) it adds the same space to its
% facing page. Conversely, on an odd page (\ie, a \emph{recto} or right-side
% page) an error is produced, but the space is still added.
%
% These errors can be suppressed by loading \pkg{addlines} with the |[draft]|
% package option. The option that indicates that errors should
% be shown is |[final]|; this is activated by default but could be overridden with a |[draft]| 
% class option.
%
% \subsection*{Notes}
% This command is a wrapper around the more basic command
% \cmd\enlargethispage. It uses the \pkg{changepage} package to check if
% the command is called on an even page, and the \pkg{afterpage}
% package to add material to a facing odd page if necessary.
%
% The \pkg{changepage} mechanism for detecting page number oddness may
% require more than a single \LaTeX\ compilation to stabilise, so
% false positives may occur. If \pkg{memoir} is used, its
% \cmd\strictpagechecktrue\ command is executed.
%
% \pkg{afterpage} may conflict poorly with
% other packages that modify \LaTeX's output routine (\ie, the
% algorithm used to chunk the document into discrete pages).
%
% Uses $\varepsilon$-\TeX\ because I'm lazy.
%
% \subsection*{Example document}
% 
%    \begin{macrocode}
%<*example>
\documentclass[twoside]{article}
\usepackage[a5paper,width=30em,lines=30]{geometry}
\usepackage{lipsum}
\usepackage{addlines}
\begin{document}
\lipsum[1-5]

\emph{Here is the command used correctly on an even page.}
\addlines

\lipsum[6-15]

\emph{Here is the command used erroneously on an odd page.}
\addlines

\lipsum[16-20]
\end{document}
%</example>
%    \end{macrocode}
%
% \subsection*{Change history}
% \begin{description}
% \item[0.1] Initial version implementing the basic commands.
% \item[0.2] Switched from \pkg{chngpage} to \pkg{changepage} and added package options |[draft]| and |[final]|.
% \end{description}
% 
% 
%
% \StopEventually{}
%
% \clearpage
% \part{\pkg{\jobname} implementation}
%\iffalse
%<*package>
%\fi
%
%
%    \begin{macrocode}
\ProvidesPackage{addlines}
  [2008/08/16 v0.2 Add/remove lines from a page]
%    \end{macrocode}
%
% Packages:
%    \begin{macrocode}
\RequirePackage{etex,afterpage,changepage}
%    \end{macrocode}
%
% Option:
%    \begin{macrocode}
\newif\if@addlines@checkpage@
\DeclareOption{final}{\@addlines@checkpage@true}
\DeclareOption{draft}{\@addlines@checkpage@false}
\ExecuteOptions{final}
\ProcessOptions
%    \end{macrocode}
%
% \begin{macro}{\addlines}
% \oarg{Number of lines to add to the text height}
%    \begin{macrocode}
\newcommand\addlines[1][1]{%
  \enlargethispage{#1\baselineskip}%
  \if@addlines@checkpage@
    \if@twoside
      \checkoddpage
      \ifoddpage
        \PackageError{addlines}
          {You're adding lines to the wrong page}
          {Extra lines need to be added to both sides of a doublepage spread.^^J
           This error might clear up after a recompile, though.}%
      \else
        \afterpage{\enlargethispage{#1\baselineskip}}%
      \fi
    \fi
  \fi}
\let\addline\addlines
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\removelines}
% \oarg{Number of lines to remove from the text height}
% Works with negative numbers through the miracles of $\varepsilon$-\TeX.
%    \begin{macrocode}
\newcommand\removelines[1][1]{%
  \addlines[\numexpr -1*(#1) \relax]}
\let\removeline\removelines
%    \end{macrocode}
% \end{macro}
%
% Finally, we don't want sloppy page number checking:
%    \begin{macrocode}
\strictpagechecktrue
%    \end{macrocode}
%
%\iffalse
%</package>
%\fi
%
%
%\iffalse
%<*dtx-style>
%    \begin{macrocode}
\ProvidesPackage{dtx-style}

\errorcontextlines=999

\def\@dotsep{1000}
\setcounter{tocdepth}{2}
\setlength\columnseprule{0.1pt}
\renewcommand\tableofcontents{\relax
  \begin{multicols}{2}[\section*{\contentsname}]\small
    \@starttoc{toc}\relax
  \end{multicols}}

\setcounter{IndexColumns}{2}
\renewenvironment{theglossary}
  {\small\list{}{}
     \item\relax
     \glossary@prologue\GlossaryParms 
     \let\item\@idxitem \ignorespaces 
     \def\pfill{\hspace*{\fill}}}
  {\endlist}

\usepackage{xcolor}
\usepackage{array,booktabs,calc,enumitem,fancyvrb,addlines,ifthen,refstyle,varioref,titlesec,url}

\usepackage[sc,osf]{mathpazo}

\linespread{1.069}      % A bit more space between lines
\frenchspacing         % Remove extra space after punctuation
\setlength\parindent{2em}
\definecolor{niceblue}{rgb}{0.2,0.4,0.8}
\def\theCodelineNo{\textcolor{niceblue}{\sffamily\tiny\arabic{CodelineNo}}}

\newcommand*\name[1]{{#1}}
\newcommand*\pkg[1]{\textsf{#1}}
\newcommand*\feat[1]{\texttt{#1}}
\newcommand*\opt[1]{\texttt{#1}}
\newcommand*\note[1]{\unskip\footnote{#1}}
\let\latin\textit
\def\eg{\latin{e.g.}}
\def\Eg{\latin{E.g.}}
\def\ie{\latin{i.e.}}
\def\etc{\@ifnextchar.{\latin{etc}}{\latin{etc.}\@}}
\def\CTAN{\textsc{ctan}}

\newcounter{argument}
\g@addto@macro\endmacro{\setcounter{argument}{0}}
\newcommand*\darg[1]{%
  \stepcounter{argument}%
  {\ttfamily\char`\#\theargument~:~}#1\par\noindent\ignorespaces}
\newcommand*\doarg[1]{%
  \stepcounter{argument}%
  {\ttfamily\makebox[0pt][r]{[}\char`\#\theargument]:~}#1\par\noindent\ignorespaces}

\def\codeline{\par\hspace{\parindent}}% two \indents in total
%    \end{macrocode}
%</dtx-style>
%<*prepare>
rm addlines.zip
latex addlines.dtx
mv README.txt README

zip addlines.zip addlines.dtx addlines.ins addlines.pdf README
%</prepare>
%\fi
% \typeout{*************************************************************}
% \typeout{*}
% \typeout{* To finish the installation you have to move the following}
% \typeout{* file into a directory searched by XeTeX:}
% \typeout{*}
% \typeout{* \space\space\space addlines.sty}
% \typeout{*}
% \typeout{*************************************************************}
\endinput
