%%
%% This is file `background.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% background.dtx  (with options: `package')
%% 
%% Copyright (C) 2009 Gonzalo Medina (gmedinaar@unal.edu.co)
%% 
%% --------------------------------------------------------------------------
%% 
%% 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 2003/12/01 or later.
%% 
%% This work has the LPPL maintenance status "maintained".
%% 
%% The Current Maintainer of this work is Gonzalo Medina.
%% 
%% This work consists of the files background.ins, background.dtx,
%% and the derived files background.sty and background.pdf.
%% 
 % \end{center}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{background}[2009/11/07 v1.0 bg material]

\RequirePackage{everypage}
\RequirePackage{tikz}
\RequirePackage{afterpage}

\newif\ifbg@some
  \bg@somefalse

\def\bg@contents{Draft}
\def\bg@color{red!45}
\def\bg@angle{60}
\def\bg@opacity{.5}
\def\bg@scale{15}
\def\bg@position{current page.center}
\def\bg@anchor{}
\def\bg@hshift{0}
\def\bg@vshift{0}

\DeclareOption{all}{\bg@somefalse}
\DeclareOption{some}{\bg@sometrue}
\DeclareOption{center}{%
  \def\bg@position{current page.center}%
  \def\bg@anchor{}%
  \def\bg@angle{60}}
\DeclareOption{bottom}{%
  \def\bg@position{current page.south}%
  \def\bg@anchor{above}%
  \def\bg@angle{0}%
  \def\bg@scale{8}}
\DeclareOption{top}{%
  \def\bg@position{current page.north}%
  \def\bg@anchor{below}%
  \def\bg@angle{0}%
  \def\bg@scale{8}}

\ExecuteOptions{all,center}
\ProcessOptions

\newcommand*\SetBgContents[1]{%
  \def\bg@contents{#1}}
\newcommand*\SetBgColor[1]{%
  \def\bg@color{#1}}
\newcommand*\SetBgAngle[1]{%
  \def\bg@angle{#1}}
\newcommand*\SetBgOpacity[1]{%
  \def\bg@opacity{#1}}
\newcommand*\SetBgScale[1]{%
  \def\bg@scale{#1}}
\newcommand*\SetBgPosition[1]{%
  \def\bg@position{#1}}
\newcommand*\SetBgAnchor[1]{%
  \def\bg@anchor{#1}}
\newcommand*\SetBgHshift[1]{%
  \def\bg@hshift{#1}}
\newcommand*\SetBgVshift[1]{%
  \def\bg@vshift{#1}}

\newcommand\bg@material{%
  \begin{tikzpicture}[remember picture,overlay]
  \node [rotate=\bg@angle,scale=\bg@scale,opacity=\bg@opacity,%
    xshift=\bg@hshift,yshift=\bg@vshift,color=\bg@color]
    at (\bg@position) [\bg@anchor]  {\bg@contents};
  \end{tikzpicture}}%
\newcommand\BgThispage{\AddThispageHook{\bg@material}}

\newcommand\NoBgThispage{%
  \let\oldbg@material\bg@material\renewcommand\bg@material{}%
  \afterpage{\AddEverypageHook{\oldbg@material}}}

\ifbg@some
  \AddThispageHook{}
\else
  \AddEverypageHook{\bg@material}
\fi
\endinput
%%
%% End of file `background.sty'.
