% \iffalse meta-comment
%
% Copyright (C) 2001, 2004, 2006 by
%    Heiko Oberdiek <oberdiek@uni-freiburg.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".
%
% This Current Maintainer of this work is Heiko Oberdiek.
%
% This work consists of the main source file pdflscape.dtx
% and the derived files
%    pdflscape.sty, pdflscape.pdf, pdflscape.ins, pdflscape.drv.
%
% Distribution:
%    CTAN:macros/latex/contrib/oberdiek/pdflscape.dtx
%    CTAN:macros/latex/contrib/oberdiek/pdflscape.pdf
%
% Unpacking:
%    (a) If pdflscape.ins is present:
%           tex pdflscape.ins
%    (b) Without pdflscape.ins:
%           tex pdflscape.dtx
%    (c) If you insist on using LaTeX
%           latex \let\install=y\input{pdflscape.dtx}
%        (quote the arguments according to the demands of your shell)
%
% Documentation:
%    (a) If pdflscape.drv is present:
%           latex pdflscape.drv
%    (b) Without pdflscape.drv:
%           latex pdflscape.dtx; ...
%    The class ltxdoc loads the configuration file ltxdoc.cfg
%    if available. Here you can specify further options, e.g.
%    use A4 as paper format:
%       \PassOptionsToClass{a4paper}{article}
%
%    Programm calls to get the documentation (example):
%       pdflatex pdflscape.dtx
%       makeindex -s gind.ist pdflscape.idx
%       pdflatex pdflscape.dtx
%       makeindex -s gind.ist pdflscape.idx
%       pdflatex pdflscape.dtx
%
% Installation:
%    TDS:tex/latex/oberdiek/pdflscape.sty
%    TDS:doc/latex/oberdiek/pdflscape.pdf
%    TDS:source/latex/oberdiek/pdflscape.dtx
%
%<*ignore>
\begingroup
  \def\x{LaTeX2e}
\expandafter\endgroup
\ifcase 0\ifx\install y1\fi\expandafter
         \ifx\csname processbatchFile\endcsname\relax\else1\fi
         \ifx\fmtname\x\else 1\fi\relax
\else\csname fi\endcsname
%</ignore>
%<*install>
\input docstrip.tex
\Msg{************************************************************************}
\Msg{* Installation}
\Msg{* Package: pdflscape 2006/04/24 v0.6 Landscape pages in PDF (HO)}
\Msg{************************************************************************}

\keepsilent
\askforoverwritefalse

\preamble

This is a generated file.

Copyright (C) 2001, 2004, 2006 by
   Heiko Oberdiek <oberdiek@uni-freiburg.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".

This Current Maintainer of this work is Heiko Oberdiek.

This work consists of the main source file pdflscape.dtx
and the derived files
   pdflscape.sty, pdflscape.pdf, pdflscape.ins, pdflscape.drv.

\endpreamble

\generate{%
  \file{pdflscape.ins}{\from{pdflscape.dtx}{install}}%
  \file{pdflscape.drv}{\from{pdflscape.dtx}{driver}}%
  \usedir{tex/latex/oberdiek}%
  \file{pdflscape.sty}{\from{pdflscape.dtx}{package}}%
}

\obeyspaces
\Msg{************************************************************************}
\Msg{*}
\Msg{* To finish the installation you have to move the following}
\Msg{* file into a directory searched by TeX:}
\Msg{*}
\Msg{*     pdflscape.sty}
\Msg{*}
\Msg{* To produce the documentation run the file `pdflscape.drv'}
\Msg{* through LaTeX.}
\Msg{*}
\Msg{* Happy TeXing!}
\Msg{*}
\Msg{************************************************************************}

\endbatchfile
%</install>
%<*ignore>
\fi
%</ignore>
%<*driver>
\NeedsTeXFormat{LaTeX2e}
\ProvidesFile{pdflscape.drv}%
  [2006/04/24 v0.6 Landscape pages in PDF (HO)]
\documentclass{ltxdoc}
\usepackage{holtxdoc}
\begin{document}
  \DocInput{pdflscape.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{344}
%
% \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         \~}
%
% \GetFileInfo{pdflscape.drv}
%
% \title{The \xpackage{pdflscape} package}
% \date{2006/04/24 v0.6}
% \author{Heiko Oberdiek\\\xemail{oberdiek@uni-freiburg.de}}
%
% \maketitle
%
% \begin{abstract}
% Package \xpackage{pdflscape} adds PDF support to the
% environment \texttt{landscape} of package \xpackage{lscape}
% by setting the PDF page attribute \texttt{/Rotate}.
% \end{abstract}
%
% \tableofcontents
%
% \section{Documentation}
%
% \subsection{Supported drivers}
%
% \begin{itemize}
% \item \xoption{pdftex}
% \item \xoption{dvips}, \xoption{dvipsone},
%       \xoption{pctex32}, \xoption{pctexps}
%       (and other drivers that provide a non-empty \cs{Gin@PS@raw})
% \item \xoption{dvipdfm}
% \end{itemize}
%
% \subsection{Caveat}
%
% Depending on the configuration Ghostscript
% adds a guessed rotation entry by its own.
% This can lead to two |/Rotate| entries per page.
% To prevent this behaviour set the parameter
% |AutoRotatePages| to |/None|, eg:
% \begin{quote}
%   |ps2pdf -dAutoRotatePages=/None|
% \end{quote}
%
% \subsection{Requirements}
%
% \begin{itemize}
% \item The package \xpackage{lscape}.
% \item The package \xpackage{everyshi} for all drivers
%        except \xoption{pdftex}.
% \end{itemize}
%
% \subsection{Usage}
%
% Load this package instead of or after package \xpackage{lscape}:
% \begin{quote}
%   |\usepackage{pdflscape}|\\
%   |\begin{landscape}|\dots|\end{landscape}|
% \end{quote}
%
% \StopEventually{
% }
%
% \section{Implementation}
%
% \subsection{Package identification}
%
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%    Package identification.
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{pdflscape}%
  [2006/04/24 v0.6 Landscape pages in PDF (HO)]
%    \end{macrocode}
%
% \subsection{Driver options}
%
%    \begin{macrocode}
\let\PLS@driver\@empty
\DeclareOption{pdftex}{%
  \PassOptionsToPackage\CurrentOption{lscape}%
  \def\PLS@driver{pdftex}%
}
\DeclareOption{dvips}{%
  \PassOptionsToPackage\CurrentOption{lscape}%
  \def\PLS@driver{dvips}%
}
\DeclareOption{dvipsone}{%
  \PassOptionsToPackage\CurrentOption{lscape}%
  \def\PLS@driver{dvips}%
}
\DeclareOption{pctexps}{%
  \PassOptionsToPackage\CurrentOption{lscape}%
  \def\PLS@driver{dvips}%
}
\DeclareOption{dvipdfm}{%
  \PassOptionsToPackage\CurrentOption{dvipdfm}%
  \def\PLS@driver{dvipdfm}%
}
\DeclareOption*{\PassOptionsToPackage\CurrentOption{lscape}}
\ProcessOptions
\RequirePackage{lscape}
%    \end{macrocode}
%
% \subsection{Autodetection of driver}
%
% \subsubsection{Driver \xoption{pdftex}}
%
%    \begin{macrocode}
\def\PLS@temp{pdftex}
\ifnum 1=0\ifx\pdfoutput\@undefined
          \else
            \ifx\pdfoutput\relax
            \else
              \ifnum\pdfoutput>0 %
                1%
              \fi
            \fi
          \fi
          \space
  \ifx\PLS@driver\@empty
    \let\PLS@driver\PLS@temp
    \PackageInfo{pdflscape}{Auto-detected driver: `\PLS@temp'}%
  \fi
  \ifx\PLS@driver\PLS@temp
  \else
    \PackageError{pdflscape}{%
      The driver option `\PLS@driver' is not compatible\MessageBreak
      with pdfTeX in PDF mode, using driver `pdftex' instead%
    }\@ehc
    \let\PLS@driver\PLS@temp
  \fi
\fi
%    \end{macrocode}
%
% \subsubsection{Driver \xoption{dvips}}
%
%    \begin{macrocode}
\def\PLS@temp{dvips}
\ifnum 1=0\ifx\Gin@PS@raw\@undefined
          \else
            \ifx\Gin@PS@raw\relax
            \else
              \ifx\Gin@PS@raw\@empty
              \else
                1%
              \fi
            \fi
          \fi
          \space
  \ifx\PLS@driver\@empty
    \let\PLS@driver\PLS@temp
    \PackageInfo{pdflscape}{Auto-detected driver: `\PLS@temp'}%
  \fi
  \ifx\PLS@driver\PLS@temp
  \else
    \PackageError{pdflscape}{%
      The driver option `\PLS@driver' is not compatible\MessageBreak
      with detected PostScript driver,\MessageBreak
      Will try using driver `dvips'%
    }\@ehc
    \let\PLS@driver\PLS@temp
  \fi
\fi
%    \end{macrocode}
%
% \subsubsection{Driver \xoption{dvipdfm}}
%
%    \begin{macrocode}
\def\PLS@temp{dvipdfm.def}
\ifx\PLS@temp\Gin@driver
  \def\PLS@temp{dvipdfm}%
  \ifx\PLS@driver\@empty
    \let\PLS@driver\PLS@temp
    \PackageInfo{pdflscape}{Auto-detected driver: `\PLS@temp'}%
  \fi
  \ifx\PLS@driver\PLS@temp
  \else
    \PackageError{pdflscape}{%
      Graphics driver `dvipdfm.def' is loaded, but this\MessageBreak
      is incompatible with driver `\PLS@driver'.\MessageBreak
      Will try using driver `dvipdfm'%
    }\@ehc
    \let\PLS@driver\PLS@temp
  \fi
\fi

\ifx\PLS@driver\@empty
  \PackageError{pdflscape}{%
    Neither pdfTeX, PostScript, nor dvipdfm driver found%
  }\@ehc
\fi
%    \end{macrocode}
%
% \subsection{Driver implementation}
%
% \begin{itemize}
% \item |\PLS@AddRotate #1|\\
%   it expects the correct rotation number in |#1|
%   and implements the adding of the /Rotation entry
%   in the |/Page| object of the current page.
% \item |\PLS@RemoveRotate|\\
%   it removes a previous |/Rotate| entry, if necessary.
% \end{itemize}
%
% \subsubsection{\pdfTeX}
%
% Not too nice is the global setting of \cs{pdfpageattr}.
% Perhaps this can be changed in future versions.
%
%    \begin{macrocode}
\def\PLS@temp{pdftex}
\ifx\PLS@temp\PLS@driver
  \def\PLS@AddRotate#1{%
    \ifnum#1=0
%    \end{macrocode}
%    Already the default.
%    \begin{macrocode}
    \else
      \global\pdfpageattr\expandafter{%
        \the\pdfpageattr
        /Rotate #1%
      }%
    \fi
  }
%    \end{macrocode}
%    Removes a |/Rotate| entry.
%    \begin{macrocode}
  \def\PLS@RemoveRotate{%
    \begingroup
      \global\pdfpageattr\expandafter{\expandafter}%
      \expandafter\PLS@@RemoveRotate
        \the\pdfpageattr /Rotate\@nil
    \endgroup
  }
  \def\PLS@@RemoveRotate#1/Rotate#2\@nil{%
%    \end{macrocode}
%    Append |/Rotate| free stuff to \cs{pdfpageattr}.
%    \begin{macrocode}
    \global\pdfpageattr\expandafter{\the\pdfpageattr#1}%
    \ifx\\#2\\%
%    \end{macrocode}
%    Ready, because the detected |/Rotate| is part of
%    the end marker: |/Rotate\@nil|
%    \begin{macrocode}
    \else
%    \end{macrocode}
%    First read in the argument of |/Rotate|,
%    then continue parsing.
%    \begin{macrocode}
      \afterassignment\PLS@@RemoveRotate
      \count0=#2\@nil
    \fi
  }
\fi
%    \end{macrocode}
%
% \subsubsection{PostScript driver}
%
%    \begin{macrocode}
\def\PLS@temp{dvips}
\ifx\PLS@temp\PLS@driver
  \RequirePackage{everyshi}%
  \EveryShipout{\PLS@EveryShi}%
  \let\PLS@EveryShi\@empty
  \def\PLS@AddRotate#1{%
    \ifnum#1=0
    \else
      \def\PLS@EveryShi{%
        \global\setbox\@cclv\vbox{%
          \Gin@PS@raw{%
            [{ThisPage}\string<\string</Rotate #1\string>\string>%
            /PUT pdfmark%
          }%
          \box\@cclv
        }%
      }%
    \fi
  }%
  \def\PLS@RemoveRotate{\let\PLS@EveryShi\@empty}%
\fi
%    \end{macrocode}
%
% \subsubsection{Driver dvipdfm}
%
%    \begin{macrocode}
\def\PLS@temp{dvipdfm}
\ifx\PLS@temp\PLS@driver
  \RequirePackage{everyshi}%
  \EveryShipout{\PLS@EveryShi}%
  \let\PLS@EveryShi\@empty
  \def\PLS@AddRotate#1{%
    \ifnum#1=0
    \else
      \def\PLS@EveryShi{%
        \global\setbox\@cclv\vbox{%
          \special{pdf: put @thispage << /Rotate #1 >>}%
          \box\@cclv
        }%
      }%
    \fi
  }%
  \def\PLS@RemoveRotate{\let\PLS@EveryShi\@empty}%
\fi
%    \end{macrocode}
%
% \subsection{Driver independent stuff}
%
%    The landscape environment is extended by
%    adding the correct |/Rotate| entries.
%    \begin{macrocode}
\g@addto@macro{\landscape}{\PLS@Rotate{90}}
\g@addto@macro{\endlandscape}{\PLS@Rotate{0}}
%    \end{macrocode}
%
%    \begin{macro}{\PLS@Rotate}
%    Main macro, that sets the |/Rotate| entry.\\
%    Argument: any TeX number or nothing, that means zero.\\
%    Driver independent.
%    \begin{macrocode}
\def\PLS@Rotate#1{%
  \begingroup
%    \end{macrocode}
%    1. Check and validate the argument.
%    \begin{macrocode}
    \PLS@CheckAngle{#1}%
  \expandafter\endgroup
%    \end{macrocode}
%    2. Remove previous |\Rotate| entry.
%    \begin{macrocode}
  \expandafter\PLS@RemoveRotate
%    \end{macrocode}
%    3. Add |/Rotate| entry.
%    \begin{macrocode}
  \expandafter\PLS@AddRotate\expandafter{\the\count@}%
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\PLS@CheckAngle}
%    Validates the rotation angle.\\
%    The result is stored in the count register |\count@|.\\
%    Driver independent.
%    \begin{macrocode}
\def\PLS@CheckAngle#1{%
%    \end{macrocode}
%    Nothing means zero:
%    \begin{macrocode}
  \ifx\\#1\\%
    \count@=0
  \else
    \count@=#1\relax
  \fi
%    \end{macrocode}
%    Normalise to interval -360 $<$ |\count@| $<$ 360.
%    \begin{macrocode}
  \@whilenum\count@>359\do{\addtocounter\count@ -360 }%
  \@whilenum\count@<-359\do{\addtocounter\count@ 360 }%
%    \end{macrocode}
%    Check values: 0, +/-90, +/-180, +/-270
%    \begin{macrocode}
  \ifnum 1=0\ifnum\count@=0 \else
            \ifnum\count@=90 \else
            \ifnum\count@=-90 \else
            \ifnum\count@=180 \else
            \ifnum\count@=-180 \else
            \ifnum\count@=270 \else
            \ifnum\count@=-270 \else
           1\fi\fi\fi\fi\fi\fi\fi\relax
    \PackageError{pdflscape}{%
      Invalid value \the\count@\space for /Rotate%
    }\@ehc
    \count@=0
  \fi
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}
% \section{Installation}
%
% \paragraph{CTAN.} This package is available on
% CTAN\footnote{\url{ftp://ftp.ctan.org/tex-archive/}}:
% \begin{description}
% \item[\CTAN{macros/latex/contrib/oberdiek/pdflscape.dtx}] The source file.
% \item[\CTAN{macros/latex/contrib/oberdiek/pdflscape.pdf}] Documentation.
% \end{description}
%
% \paragraph{Unpacking.} The \xfile{.dtx} file is a self-extracting
% \docstrip\ archive. The files are extracted by running the
% \xfile{.dtx} through \plainTeX:
% \begin{quote}
%   \verb|tex pdflscape.dtx|
% \end{quote}
%
% \paragraph{TDS.} Now the different files must be moved into
% the different directories in your installation TDS tree
% (also known as \xfile{texmf} tree):
% \begin{quote}
% \sbox0{^^A
% \begin{tabular}{@{}>{\ttfamily}l@{$\quad\rightarrow\quad$}>{\ttfamily}l@{}}
%   pdflscape.sty & tex/latex/oberdiek/pdflscape.sty\\
%   pdflscape.pdf & doc/latex/oberdiek/pdflscape.pdf\\
%   pdflscape.dtx & source/latex/oberdiek/pdflscape.dtx\\
% \end{tabular}^^A
% }%
% \ifdim\wd0>\linewidth
%   \mbox{}\nobreak\hskip0pt minus\leftmargin
%   \usebox0
%   \nobreak\hskip0pt minus\rightmargin
% \else
%   \usebox0
% \fi
% \end{quote}
% If you have a \xfile{docstrip.cfg} that configures and enables \docstrip's
% TDS installing feature, then some files can already be in the right
% place, see the documentation of \docstrip.
%
% \paragraph{Refresh file databases.} If your \TeX~distribution
% (\teTeX, \mikTeX, \dots) rely on file databases, you must refresh
% these. For example, \teTeX\ users run \verb|texhash| or
% \verb|mktexlsr|.
%
% \subsection{Some details for the interested}
%
% \paragraph{Attached source.}
%
% The PDF documentation on CTAN also includes the
% \xfile{.dtx} source file. It can be extracted by
% AcrobatReader 6 or higher. Another option is \textsf{pdftk},
% e.g. unpack the file into the current directory:
% \begin{quote}
%   \verb|pdftk pdflscape.pdf unpack_files output .|
% \end{quote}
%
% \paragraph{Unpacking with \LaTeX.}
% The \xfile{.dtx} chooses its action depending on the format:
% \begin{description}
% \item[\plainTeX:] Run \docstrip\ and extract the files.
% \item[\LaTeX:] Generate the documentation.
% \end{description}
% If you insist on using \LaTeX\ for \docstrip\ (really,
% \docstrip\ does not need \LaTeX), then inform the autodetect routine
% about your intention:
% \begin{quote}
%   \verb|latex \let\install=y\input{pdflscape.dtx}|
% \end{quote}
% Do not forget to quote the argument according to the demands
% of your shell.
%
% \paragraph{Generating the documentation.}
% You can use both the \xfile{.dtx} or the \xfile{.drv} to generate
% the documentation. The process can be configured by the
% configuration file \xfile{ltxdoc.cfg}. For instance, put this
% line into this file, if you want to have A4 as paper format:
% \begin{quote}
%   \verb|\PassOptionsToClass{a4paper}{article}|
% \end{quote}
% An example follows how to generate the
% documentation with pdf\LaTeX:
% \begin{quote}
%\begin{verbatim}
%pdflatex pdflscape.dtx
%makeindex -s gind.ist pdflscape.idx
%pdflatex pdflscape.dtx
%makeindex -s gind.ist pdflscape.idx
%pdflatex pdflscape.dtx
%\end{verbatim}
% \end{quote}
%
% \begin{History}
%   \begin{Version}{2001/01/15 v0.1}
%   \item
%     First public version,
%     published in \xnewsgroup{de.comp.text.tex}.
%   \end{Version}
%   \begin{Version}{2001/02/04 v0.2}
%   \item
%     Minor documentation update.
%   \item
%     CTAN.
%   \end{Version}
%   \begin{Version}{2004/05/11 v0.3}
%   \item
%     Support for dvipdfm added.
%   \end{Version}
%   \begin{Version}{2004/05/12 v0.4}
%   \item
%     Bug fix: support for multipage landscape environment
%     for all drivers except for \xoption{pdftex}.
%   \end{Version}
%   \begin{Version}{2006/02/20 v0.5}
%   \item
%     DTX framework.
%   \item
%     LPPL 1.3
%   \item
%     Code is not changed.
%   \end{Version}
%   \begin{Version}{2006/04/24 v0.6}
%   \item
%     Bug fix: \cs{PLS@RemoveRotate} reinserted for \cs{PLS@Rotate}.
%   \item
%     Fix for \cs{PLS@RemoveRotate} (dvips/dvipdfm): \cs{PLS@EverhShi}
%     hook is cleared.
%   \end{Version}
% \end{History}
%
% \PrintIndex
%
% \Finale
\endinput
