%%
%% This is file `pfarrei.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% pfarrei.dtx  (with options: `package,tex')
%% 
%% Copyright (c) 2013 Markus Kohm
%%                    komascript at gmx info
%% 
%% This file was generated from file(s) of the work `pfarrei'.
%% ------------------------------------------------------------------
%% 
%% It may be distributed under the conditions of the
%% LaTeX Project Public License in the version distributed together
%% with the work `pfarrei'.  You may however distribute the work
%% `pfarrei' without all such generated files.  See also
%% <http://www.latex-project.org/lppl.txt> for additional
%% information.
%% 
%% This work has the LPPL maintenance status `maintained'.
%% 
%% The Current Maintainer of this work is Markus Kohm.
%% 
%% The list of files belonging to the work `pfarrei' is given in
%% the file `pfarrei.dtx'.
%% 
\begingroup
   \def\revisiondate$#1: #2-#3-#4 #5${%
    \gdef\pfarreirevisiondate{#2/#3/#4}%
  }\revisiondate$Date: 2013-10-16 20:54:26 +0200 (Mi, 16. Okt 2013) $
  \def\revision$#1: #2 #3${%
    \gdef\pfarreirevision{#2}%
  }\revision$Revision: 36 $
\endgroup
\ProvidesPackage{pfarrei}
  [\pfarreirevisiondate\space r\pfarreirevision\space LaTeX2e package
                                                  (for pastors)]
\newcommand*{\ifbooklet}{}
\let\ifbooklet\@secondoftwo
\DeclareOption{booklet}{\let\ifbooklet\@firstoftwo}
\DeclareOption{nobooklet}{\let\ifbooklet\@secondoftwo}
\ProcessOptions*
\RequirePackage{ifpdf}
\RequirePackage{pdfpages}
\newcommand*{\AvToAiv}[1][\OriginalFile]{%
  \ifpdf\else
    \PackageError{pfarrei}{PDF mode needed}{%
      a5toa4 needs the direct PDF mode.\MessageBreak
      Usually this may be activated using either pdflatex, lualatex or
      xelatex.%
    }%
    \input{x.tex}
  \fi
  \ifbooklet{%
    \includepdf[pages=-,booklet]{#1}%
  }{%
    \includepdf[pages=-,nup=2x1]{#1}%
  }%
}
\newenvironment*{bookletpage}{%
  \edef\reserved@a{bookletpage}%
  \ifx\@currenvir\reserved@a
    \PackageError{pfarrei}{`bookletpage' used as ordinary environment}{%
      Please note, that `bookletpage' is a virtual environment
      only.\MessageBreak
      You should not use it directly as an environment, but use
      `\string\bookletpage' at the\MessageBreak
      begin code and `\string\endbookletpage' at the end code of a wrapper
      environment.\MessageBreak
      If you'll continue, expect several additional errors%
    }%
    \let\bookletpagebox\@tempboxa
    \let\bookletpagestyle\@empty
  \else
    \expandafter\let\expandafter\bookletpagebox
    \csname \@currenvir box\endcsname
    \expandafter\let\expandafter\bookletpagestyle
    \csname \@currenvir style\endcsname
  \fi
  \edef\reserved@a{%
    \noexpand\begin{lrbox}{\bookletpagebox}
    \noexpand\begin{minipage}[t][\textheight][t]{\textwidth}%
      \begingroup
        \def\noexpand\@currenvir{\@currenvir}%
        \def\noexpand\@currenvline{\@currenvline}%
        \noexpand\parskip=\the\parskip
        \noexpand\parindent=\the\parindent
        \noexpand\parfillskip=\the\parfillskip
  }\reserved@a
}{%
  \endbookletpagebox
  \printbookletpagebox
}
\def\endbookletpagebox{%
        \par
      \endgroup
    \end{minipage}%
  \end{lrbox}%
  \global\setbox\bookletpagebox\box\bookletpagebox
}
\newcommand*\printbookletpagebox[1][\@currenvir]{%
  \ifbooklet{%
    \@ifundefined{bookletpagestyle}{}{%
      \ifx\bookletpagestyle\@empty\else\thispagestyle{\bookletpagestyle}\fi%
    }%
    \clearpage\noindent\usebox\bookletpagebox\clearpage
  }{%
    \PackageInfo{pfarrei}{`#1' not printed}%
  }%
}
\newsavebox\bookletfrontpagebox
\newcommand*{\bookletfrontpagestyle}{empty}
\newenvironment*{bookletfrontpage}{%
  \bookletpage
}{%
  \endbookletpagebox
  \clearpage
  \ifbooklet{%
    \ifnum\c@page>\@ne
      \PackageError{pfarrei}{Booklet front page not first page}{%
        The booklet font page should be the first page, but it seems, that it
        is\MessageBreak
        page no. \the\c@page. \space Maybe you should put it immediately after
        `\string\begin{document}.%
        Nevertheless, if you'll continue it will be printed here%
      }%
    \fi
    \printbookletpagebox
  }{%
    \PackageInfo{pfarrei}{Booklet front page ignored}%
  }%
}
\newsavebox\bookletemptypagebox
\newcommand*{\bookletemptypagestyle}{empty}
\newenvironment*{bookletemptypage}{%
  \bookletpage
}{%
  \endbookletpagebox
}
\newsavebox\bookletbackpagebox
\newcommand*{\bookletbackpagestyle}{empty}
\newenvironment*{bookletbackpage}{%
  \bookletpage
}{%
  \endbookletpagebox
  \if@filesw\immediate\write\@mainaux{\string\printbookletbackpage}\fi
}%
\newcommand*{\printbookletbackpage}{}
\newcommand*{\@printbookletbackpage}{%
  \ifbooklet{%
    \clearpage
    \let\bookletpagestyle\bookletemptypagestyle
    \ifvoid\bookletemptypagebox
      \let\bookletpagebox\strutbox
    \else
      \let\bookletpagebox\bookletemptypagebox
    \fi
    \@tempcnta=\c@page
    \divide\@tempcnta by 4
    \multiply\@tempcnta by 4
    \ifnum \@tempcnta=\c@page\else
      \advance\@tempcnta by 4
      \@whilenum \c@page<\@tempcnta\do{%
        \printbookletpagebox
      }%
    \fi
    \let\bookletpagestyle\bookletbackpagestyle
    \let\bookletpagebox\bookletbackpagebox
    \printbookletpagebox
  }{%
    \PackageInfo{pfarrei}{Booklet back page ignored}%
  }%
}
\AtBeginDocument{\let\printbookletbackpage\@printbookletbackpage}
\newcommand*{\motto}[1]{\gdef\@motto{#1}}
\newcommand*{\@motto}{}
\newcommand*{\titlepicture}[1]{\gdef\@titlepicture{#1}}
\newcommand*{\@titlepicture}{}
\providecommand*{\title}[1]{\gdef\@title{#1}}
\providecommand*{\@title}{}
\newcommand*{\parish}[1]{\gdef\@parish{#1}}
\newcommand*{\@parish}{}
\providecommand*{\date}[1]{\gdef\@date{#1}}
\def\@date{}
\newcommand*{\makebooklettitlepage}{%
  \begin{bookletfrontpage}
    \parskip.5\baselineskip
    \parindent\z@
    \parfillskip \z@ \@plus 1fil
    \centering
    \ifx\@motto\@empty\else{\Huge\@motto\par}\fi
    \vfill
    \ifx\@titlepicture\@empty\else\@titlepicture\par\fi
    \vfill
    \parskip\z@
    \Huge
    \@title\par
    \@parish\par
    \@date\par
    \ifx\@title\@empty\ifx\@parish\@empty\ifx\@date\@empty\null\fi\fi\fi
  \end{bookletfrontpage}
}
\let\samedoublepage@save@hbox\hbox
\newenvironment*{samedoublepage}{%
  \par
  \let\hbox\vbox
  \begin{lrbox}{\@tempboxa}%
    \let\hbox\samedoublepage@save@hbox
}{%
  \end{lrbox}%
  \let\hbox\samedoublepage@save@hbox
  \@tempdima\ifdim\pagegoal=\maxdimen\textheight
            \else\dimexpr\pagegoal-\pagetotal\fi
  \ifdim \@tempdima
        <\dimexpr\ht\@tempboxa+\dp\@tempboxa\relax
    \ifodd\c@page
      \newpage
      \@tempdima\textheight
    \else \typeout{even page}%
    \fi
    \@whiledim \@tempdima
              <\dimexpr\ht\@tempboxa+\dp\@tempboxa\relax\do{%
      \splitmaxdepth\dp\strutbox
      \splittopskip\topskip
      \setbox\z@\vsplit\@tempboxa to \@tempdima
      \usebox\z@
      \newpage
      \@tempdima\textheight
    }%
  \fi
  \ifvoid\@tempboxa\else\usebox\@tempboxa\fi
}
\RequirePackage{keyval}
\define@key{pfarrei.prayer}{response}{\def\prayer@response{#1}}
\define@key{pfarrei.prayer}{responder}{\def\prayer@responder{#1:}}
\define@key{pfarrei.prayer}{leader}{\def\prayer@leader{#1:}}
\newcommand*{\prayer@responder}{}
\newcommand*{\prayer@response}{}
\newcommand*{\prayer@leader}{}
\newcommand*{\setupprayer}{%
  \setkeys{pfarrei.prayer}%
}
\newif\ifprayer@firstitem
\newcommand*{\prayer@response@item}{%
  \ifprayer@firstitem\else
    \ifx\prayer@responder\@empty\else
      \ifx\prayer@response\@empty\else
        \prayer@save@item[\prayer@responder] \prayer@response
      \fi
    \fi
  \fi
}
\newcommand*{\prayer@item}[1][\prayer@leader]{%
  \prayer@response@item
  \prayer@firstitemfalse
  \prayer@save@item[{#1}]%
}
\newenvironment*{prayer}[1][]{%
  \begin{description}
    \begingroup
      \def\@currenvir{prayer}%
      \setupprayer{#1}%
      \let\prayer@save@item\item
      \let\item\prayer@item
      \prayer@firstitemtrue
      \let\noresponder\prayer@firstitemtrue
}{%
      \prayer@response@item
    \endgroup
  \end{description}
}
\endinput
%%
%% End of file `pfarrei.sty'.
