% \iffalse meta-comment
%<=*COPYRIGHT>
%% Copyright (C) 2011-2012 by Martin Scharrer <martin@scharrer-online.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 Martin Scharrer.
%%
%% This work consists of the files tikzpagenodes.dtx and tikzpagenodes.ins
%% and the derived filebase tikzpagenodes.sty.
%%
%<=/COPYRIGHT>
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{tikzpagenodes.dtx}[%
%<=*DATE>
    2012/09/16
%<=/DATE>
%<=*VERSION>
    v1.1
%<=/VERSION>
    DTX file for tikzpagenodes package]
\documentclass{ydoc}
\GetFileInfo{tikzpagenodes.dtx}
\usepackage{tikzpagenodes}[\filedate]
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{tikzpagenodes.dtx}
  \PrintChanges
  \PrintIndex
\end{document}
%</driver>
% \fi
%
% \CheckSum{308}
%
% \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         \~}
%
%
% \changes{v1.0}{2011/09/15}{First version.}
% \changes{v1.1}{2012/09/16}{Corrected positions of 'marginpar area' nodes.}
%
% \DoNotIndex{\newcommand,\newenvironment}
%
% \providecommand*{\url}{\texttt}
% \GetFileInfo{tikzpagenodes.dtx}
% \title{The \textsf{tikzpagenodes} package}
% \author{Martin Scharrer\\ \url{martin@scharrer.me}}
% \repository{https://bitbucket.org/martin_scharrer/tikzpagenodes}
%
% \maketitle
% \section{Introduction}
% The drawing bundle PGF/TikZ provides a special rectangle node \texttt{current page} which allows users to access all edges and the center of the current page.
% This is useful if material should be drawn or placed on absolute positions of the page.
% For this to work the \texttt{tikzpicture} need to use the \texttt{remember picture} option to remember its position relative to the page origin.
%
% Often material should also be drawn or placed relative to other areas of the page, e.g.\ the text area.
% Such a node can be defined manually as shown in the post \href{http://permalink.gmane.org/gmane.comp.tex.pgf.user/2078}{More special nodes} on the \texttt{pgf-users} list.
% This package was written to simplify this by providing real special nodes which are defined in the same way as \texttt{current page}.
% One difficulty is that in \texttt{twoside} mode odd and even pages have different margins. For this the author's other package \texttt{ifoddpage} is used.
%
% \section{Usage}
% The provided nodes can be used in all \env{tikzpicture}s which use the \texttt{remember picture} option. In the majority of the cases the option \texttt{overlay} should also be used
% to avoid that the picture reserves any space at the position its code is placed.
%
% The following special nodes are provided. They are rectangle in shape, possess all anchors of this shape:
%
% \par\medskip\par\noindent
% \begin{minipage}{\textwidth}
% \begin{tabular}{>{\ttfamily}ll}
%   \toprule
%   \normalfont Node & Description \\
%   \midrule
%   current page text area       &  Text area\footnote{Up to the baseline of the text area, i.e.\ the depth of the last line is not included} \small(\Macro\textwidth\relax$\times$\Macro\textheight) \\
%   current page marginpar area  &  Marginpar area \small(\Macro\marginparwidth\relax$\times$\Macro\textheight) \\
%   current page header area     &  Header area \small(\Macro\textwidth\relax$\times$\Macro\headerheight) \\
%   current page footer area     &  Footer area \small(\Macro\textwidth\relax$\times$\Macro\headerheight
%       \footnote{Officially there is no footer height. Its baseline has a distance of \Macro\footerskip from the baseline of the text area.
%           Because using this value would make the upper edge equal to the lower edge of the text area node, the \Macro\headerheight is used as a decent replacement.}) \\
%   \bottomrule
% \end{tabular}
% \end{minipage}
%
%
% \clearpage
% \section{Examples}
%
%   \begin{examplecode}
%   \tikz[remember picture,overlay] {%
%       \draw [blue,line width=2mm]
%           (current page.south west)
%           rectangle
%           (current page.north east)
%   ;
%       \draw [green]
%           (current page text area.south west)
%           rectangle
%           (current page text area.north east)
%   ;
%       \draw [yellow]
%           (current page marginpar area.south west)
%           rectangle
%           (current page marginpar area.north east)
%   ;
%       \draw [red]
%           (current page header area.south west)
%           rectangle
%           (current page header area.north east)
%   ;
%       \draw [orange]
%           (current page footer area.south west)
%           rectangle
%           (current page footer area.north east)
%   ;
%   }%
%   \end{examplecode}
%
%
% \StopEventually{}
%
% \clearpage
% \section{Implementation}
%
% \iffalse
%<*tikzpagenodes.sty>
% \fi
%    \begin{macrocode}
%<!COPYRIGHT>
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{tikzpagenodes}[%
%<!DATE>
%<!VERSION>
%<*DRIVER>
    2099/01/01 develop
%</DRIVER>
    Special PGF/TikZ nodes for areas of the page]
%    \end{macrocode}
%
%
%    \begin{macrocode}
\RequirePackage{tikz}
\RequirePackage{ifoddpage}
%    \end{macrocode}
%
% \subsection{Different margins for odd and even pages in \texttt{twoside} mode}
%
% Update the page conditional for every picture which uses \texttt{remember picture}.
%    \begin{macrocode}
\tikzset{every picture/.append style={execute at begin picture={%
    \ifpgfrememberpicturepositiononpage
        \checkoddpage
    \fi
}}}
%    \end{macrocode}
%
% \begin{macro}{\currentsidemargin}
% Expands to the current left side margin, i.e. \Macro\oddsidemargin for odd pages in |twoside| mode and all pages in |oneside| mode
% or \Macro\evensidemargin for even pages in |twoside| mode.
%    \begin{macrocode}
\def\currentsidemargin{\ifoddpageoroneside\oddsidemargin\else\evensidemargin\fi}%
%    \end{macrocode}
% \end{macro}
%
%
% \subsection{Often used lengths}
%
% \begin{macro}{\current@textarea@left}
% Complete left margin including 1in constant and offset. This value is used multiple times and therefore stored in macro.
%    \begin{macrocode}
\def\current@textarea@left{(1in+\hoffset+\currentsidemargin)}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\current@textarea@top}
% Complete top margin including 1in constant, offset and header. This value is used multiple times and therefore stored in macro.
%    \begin{macrocode}
\def\current@textarea@top{(1in+\voffset+\topmargin+\headheight+\headsep)}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Node Definition Macro}
% Most required macros can be |\let| to the |current page| node.
%    \begin{macrocode}
\def\@newtikzpagenode#1{%
    \expandafter\let\csname pgf@sh@ns@#1\expandafter\endcsname\csname pgf@sh@ns@current page\endcsname
    \expandafter\let\csname pgf@sh@nt@#1\expandafter\endcsname\csname pgf@sh@nt@current page\endcsname
    \expandafter\let\csname pgf@sh@pi@#1\expandafter\endcsname\csname pgf@sh@pi@current page\endcsname
    \expandafter\def\csname pgf@sh@np@#1\endcsname
}
%    \end{macrocode}
%
% \subsection{Current Page Text Area Node}
%    \begin{macrocode}
\@newtikzpagenode{current page text area}{%
    \def\southwest{\pgfpoint{\current@textarea@left}{\paperheight-\current@textarea@top-\textheight}}%
    \def\northeast{\pgfpoint{\current@textarea@left+\textwidth}{\paperheight-\current@textarea@top}}%
}
%    \end{macrocode}
%
%
% \subsection{Current Page Marginpar Area Node}
%    \begin{macrocode}
\@newtikzpagenode{current page marginpar area}{%
    \def\southwest{\pgfpoint
        {\current@textarea@left\ifoddpageoroneside+\textwidth+\marginparsep\else-\marginparsep-\marginparwidth\fi}%
        {\paperheight-\current@textarea@top-\textheight}%
    }%
    \def\northeast{\pgfpoint
        {\current@textarea@left\ifoddpageoroneside+\textwidth+\marginparsep+\marginparwidth\else-\marginparsep\fi}%
        {\paperheight-\current@textarea@top}%
    }%
}
%    \end{macrocode}
%
%
% \subsection{Current Page Header Area Node}
%    \begin{macrocode}
\@newtikzpagenode{current page header area}{%
    \def\southwest{\pgfpoint{\current@textarea@left}{\paperheight-\current@textarea@top+\headsep}}%
    \def\northeast{\pgfpoint{\current@textarea@left+\textwidth}{\paperheight-\current@textarea@top+\headsep+\headheight}}%
}
%    \end{macrocode}
%
%
% \subsection{Current Page Footer Area Node}
%    \begin{macrocode}
\@newtikzpagenode{current page footer area}{%
    \def\southwest{\pgfpoint{\current@textarea@left}{\paperheight-\current@textarea@top-\textheight-\footskip}}%
    \def\northeast{\pgfpoint{\current@textarea@left+\textwidth}{\paperheight-\current@textarea@top-\textheight-\footskip+\headheight}}%
}
%    \end{macrocode}
%
% \subsection{Current Page Column Areas}
%    \begin{macrocode}
\@newtikzpagenode{current page column 1 area}{%
    \def\southwest{\pgfpoint{\current@textarea@left}{\paperheight-\current@textarea@top-\textheight}}%
    \def\northeast{\pgfpoint{\current@textarea@left+\columnwidth}{\paperheight-\current@textarea@top}}%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\@newtikzpagenode{current page column 2 area}{%
    \def\southwest{\pgfpoint{\current@textarea@left+\columnwidth+\columnsep}{\paperheight-\current@textarea@top-\textheight}}%
    \def\northeast{\pgfpoint{\current@textarea@left+2\columnwidth+\columnsep}{\paperheight-\current@textarea@top}}%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\@newtikzpagenode{current page column 3 area}{%
    \def\southwest{\pgfpoint{\current@textarea@left+2\columnwidth+2\columnsep}{\paperheight-\current@textarea@top-\textheight}}%
    \def\northeast{\pgfpoint{\current@textarea@left+3\columnwidth+2\columnsep}{\paperheight-\current@textarea@top}}%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\@newtikzpagenode{current page column 4 area}{%
    \def\southwest{\pgfpoint{\current@textarea@left+3\columnwidth+3\columnsep}{\paperheight-\current@textarea@top-\textheight}}%
    \def\northeast{\pgfpoint{\current@textarea@left+4\columnwidth+3\columnsep}{\paperheight-\current@textarea@top}}%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\@newtikzpagenode{current page column 5 area}{%
    \def\southwest{\pgfpoint{\current@textarea@left+4\columnwidth+4\columnsep}{\paperheight-\current@textarea@top-\textheight}}%
    \def\northeast{\pgfpoint{\current@textarea@left+5\columnwidth+4\columnsep}{\paperheight-\current@textarea@top}}%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\@newtikzpagenode{current page column 6 area}{%
    \def\southwest{\pgfpoint{\current@textarea@left+5\columnwidth+5\columnsep}{\paperheight-\current@textarea@top-\textheight}}%
    \def\northeast{\pgfpoint{\current@textarea@left+6\columnwidth+5\columnsep}{\paperheight-\current@textarea@top}}%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\@newtikzpagenode{current page column 7 area}{%
    \def\southwest{\pgfpoint{\current@textarea@left+6\columnwidth+6\columnsep}{\paperheight-\current@textarea@top-\textheight}}%
    \def\northeast{\pgfpoint{\current@textarea@left+7\columnwidth+6\columnsep}{\paperheight-\current@textarea@top}}%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\@newtikzpagenode{current page column 8 area}{%
    \def\southwest{\pgfpoint{\current@textarea@left+7\columnwidth+7\columnsep}{\paperheight-\current@textarea@top-\textheight}}%
    \def\northeast{\pgfpoint{\current@textarea@left+8\columnwidth+7\columnsep}{\paperheight-\current@textarea@top}}%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\@newtikzpagenode{current page column 9 area}{%
    \def\southwest{\pgfpoint{\current@textarea@left+8\columnwidth+8\columnsep}{\paperheight-\current@textarea@top-\textheight}}%
    \def\northeast{\pgfpoint{\current@textarea@left+9\columnwidth+8\columnsep}{\paperheight-\current@textarea@top}}%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\@newtikzpagenode{current page column 10 area}{%
    \def\southwest{\pgfpoint{\current@textarea@left+9\columnwidth+9\columnsep}{\paperheight-\current@textarea@top-\textheight}}%
    \def\northeast{\pgfpoint{\current@textarea@left+10\columnwidth+9\columnsep}{\paperheight-\current@textarea@top}}%
}
%    \end{macrocode}
%
% \iffalse
%</tikzpagenodes.sty>
% \fi
%
% \Finale
% \endinput
