% \iffalse meta-comment
%
% Copyright (C) 2005
%   Rolf Niepraschk,  <Rolf.Niepraschk@ptb.de>
%   Hubert Gaesslein, <HubertJG@open.mind.de>
% --------------------------------------------------------------
%
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.2
% 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.2 or later is part of all distributions of LaTeX
% version 1999/12/01 or later.
%
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{pst-pdf.dtx}
%</driver>
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{pst-pdf}
%<*package>
    [2005/06/29 v1.1i PS graphics for pdfLaTeX (RN,HjG)]
%</package>
%
%<*driver>
\listfiles
\documentclass[a4paper]{ltxdoc}
\usepackage[ignore]{pst-pdf}
\usepackage[british]{babel}
\usepackage{booktabs,calc,array,url}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\setlength\emergencystretch{3em}
%%%%%% spaeter wieder weg %%%%%
\usepackage{color}
\usepackage{texnames}
\newcommand\notice[1]{%
  \marginpar{\mbox{}\raggedright\color{red}\itshape #1}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{pst-pdf.dtx}
  \PrintChanges
  \PrintIndex
\end{document}
%</driver>
% \fi
%
% \CheckSum{787}
%
% \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.0a}{2005/01/27}{Initial version.}
% \changes{v1.0b}{2005/01/28}{Some code and documentation cleaning. (RN)}
% \changes{v1.0d}{2005/01/30}{Redefinition of \cmd{\includegraphics} in
%   modes 0 und 1. Now using of eps graphics directly in pdf\LaTeX{} is
%   possible. (RN)}
% \changes{v1.0j}{2005/02/22}{Check AtBeginDocument for package
%   `pstricks' even if ``nopstricks'' is given. (RN)}
% \changes{v1.0j}{2005/02/22}{For \cmd{\includegraphics}
% \cmd{\usepicture} and |postscript| the new options ``frame'',
% ``framesep'', ``framerule'', ``linewidth'', and ``ignore'' added. (RN)}
% \changes{v1.0l}{2005/02/25}{Options ``framesep'', ``framerule'',
% ``linewidth'' removed, ``fname'' and ``innerframe'' added. (RN)}
% \changes{v1.0m}{2005/02/26}{New package option ``notightpage'' added. (RN)}
% \changes{v1.0n}{2005/02/27}{Some code cleaning. (RN)}
% \changes{v1.0n}{2005/02/27}{Changed marcro names (\cmd{\savepicture}
% and \cmd{\usepicture}). (RN)}
% \changes{v1.0o}{2005/03/12}{Option ``fname'' renamed to ``showname''. (RN)}
% \changes{v1.0p}{2005/03/13}{Some code and documentation cleaning. (RN)}
% \changes{v1.0s}{2005/03/28}{Scaling e.g. of PostScript pictures now only
% in extraction mode. Some code cleaning. (RN)}
% \changes{v1.1b}{2005/04/09}{Some code and documentation cleaning. (RN)}
% \changes{v1.1c}{2005/04/17}{New package option ``tightpage'' added. (RN)}
%
% \GetFileInfo{pst-pdf.dtx}
%
% \DoNotIndex{\newcommand,\renewcommand,\newenvironment,\renewenvironment}
% \DoNotIndex{\providecommand,\def,\edef,\let,\gdef,\xdef,\global,\newtoks}
% \DoNotIndex{\chardef,\@namedef,\g@addto@macro,\newif,\newcounter}
% \DoNotIndex{\RequirePackage,\DeclareOption,\ProcessOptions,\ExecuteOptions}
% \DoNotIndex{\input,\endinput,\IfFileExists,\InputIfFileExists}
% \DoNotIndex{\@ifdefinable,\@ifundefined,\@percentchar}
% \DoNotIndex{\iftrue,\iffalse}
% \DoNotIndex{\the,\if,\ifx,\else,\or,\fi,\ifnum,\ifdim,\ifcase,\ifodd}
% \DoNotIndex{\AtBeginDocument,\AtEndDocument,\AtEndOfPackage}
% \DoNotIndex{\PackageError,\PackageWarning,\PackageWarningNoLine,\PackageInfo}
% \DoNotIndex{\message,\MessageBreak,\typeout,\space,\@spaces}
% \DoNotIndex{\@tempa,\@tempb,\x}
% \DoNotIndex{\z@,\z@skip,\p@,\@ne,\tw@,\thr@@,\@iv,\two@fourteen,\strip@pt}
% \DoNotIndex{\advance,\multiply,\divide}
% \DoNotIndex{\@for,\@tfor,\do,\@gobble,\@gobbletwo,\relax,\ignorespaces}
% \DoNotIndex{\csname,\endcsname,\begingroup,\endgroup,\bgroup,\egroup}
% \DoNotIndex{\expandafter,\afterassignment,\aftergroup,\noexpand}
% \DoNotIndex{\setbox,\box,\hbox,\vbox,\ht,\wd,\dp,\llap,\rlap}
% \DoNotIndex{\small,\large,\tiny,\ttfamily,\lowercase}
% \DoNotIndex{\@@,\@empty,\@firstoftwo,\@secondoftwo}
% \DoNotIndex{\@tempboxa,\@tempcnta,\@temptokena,\toks@,\@namedef,\@nameuse}
%
% \providecommand*\env[1]{\textsf{#1}}
% \providecommand*\clsname[1]{\textsf{#1}}
% \providecommand*\pkgname[1]{\textsf{\mbox{#1}}}
% \providecommand*\optname[1]{\textsf{#1}}
% \providecommand*\progname[1]{\textsf{`#1'}}
%
% \providecommand*\PS{Post\-Script}
%
% \newenvironment{optlist}%
% {\begin{description}%
%   \renewcommand\makelabel[1]{%
%     \descriptionlabel{\bfseries\optname{##1}}}%
%   \itemsep0.25\itemsep}%
% {\end{description}}
%
% \newcommand*\META[1]{\meta{\normalfont#1}}
% \newcommand*\TorF{\META{true\textbar false}}
%
% \title{The \pkgname{pst-pdf} package\thanks{This document
%   corresponds to \textsf{pst-pdf}~\fileversion, dated \filedate. 
%  Thanks to Peter Dyballa for the translation.}}
% \author{%
%   Rolf Niepraschk\thanks{\texttt{Rolf.Niepraschk@ptb.de}}
%   \and
%   Hubert G\"a{\ss}lein\thanks{\texttt{HubertJG@open.mind.de}}}
% \date{\filedate}
%
% \maketitle
%
% \section{Introduction}
%
% The package \pkgname{pst-pdf} simplifies the use of graphics from
% PSTricks and other \PS\ code in PDF documents. As in building a
% bibliography with \BibTeX{} additional external programmes are being
% invoked. In this case they are used to create a PDF file
% (\cmd{\PDFcontainer}) that will contain all this graphics material. In the
% final document this contents will be inserted instead of the original
% \PS\ code.
%
% \section{Usage}
%
% \subsection{Package options}
%
%   \begin{optlist}
%
%   \item[active] Activates the extraction mode (DVI output). An explicit
%     declaration usually is not necessary (default in \LaTeX\ mode).
%
%   \item[inactive] No special actions; only the packages
%     \pkgname{pstricks} and \pkgname{graphicx} are loaded (default in
%     V\TeX). Can be used to just convert the document with \LaTeX\ into a
%     DVI file while avoiding the automatic extraction mode.
%
%   \item[pstricks] The package \pkgname{pstricks} is loaded (default).
%
%   \item[nopstricks] The package \pkgname{pstricks} does not get loaded.
%     Once it is detected that \pkgname{pstricks} was loaded however in
%     some other way, the \env{pspicture} environment is treated as if the
%     option ``pstricks'' was given.
%
%   \item[draft] From the \cmd{\PDFcontainer} file included graphics is
%     displayed as frame in pdf\LaTeX\ mode.
%
%   \item[final] From the \cmd{\PDFcontainer} file included graphics is
%     correctly displayed in pdf\LaTeX\ mode (default).
%
%   \item[tightpage] The graphics' dimensions in the \cmd{\PDFcontainer}
%     file match exactly those of the corresponding \TeX\ boxes (default).
%
%   \item[notightpage] The dimensions of the \TeX\ box corresponding to its
%     graphics is not always correct, since a \PS\ statement can draw
%     outside its box. The option ``notightpage'' makes the graphics in the
%     \cmd{\PDFcontainer} file to be at least the size of the whole page.
%     To be able to make use of the graphics' in a later pdf\LaTeX\ run,
%     the \cmd{\PDFcontainer} file needs to be finished in a way that each
%     graphics gets reduced in size to its visible part. For this an
%     external programme like
%     |pdfcrop|\footnote{CTAN:~\url{support/pdfcrop/}} can be useful. Its
%     use can save declaring the option ``trim'' (see also
%     section~\ref{sec:copt}).
%
%   \item[displaymath] In PDF mode the mathematical environments
%     \env{displaymath}, \env{eqnarray}, and \env{\$\$} get also extracted
%     and included as graphics. This way additional PSTricks extensions can
%     easily be added to the contents of these environments. (Question: how
%     do AMS\LaTeX\ environments behave?)
%
%   \item[\meta{other}] All other options are passed to \pkgname{pstricks}
%     package.
%
%   \end{optlist}
%
% \subsection{Program calls}
%
% The following table shows the course necessary to create a PDF document
% containing \PS\ graphics\footnote{The \TeX\ distribution ``te\TeX''
%   contains a UNIX shell script |ps4pdf| which executes all the necessary
%   steps. See: CTAN:~\url{macros/latex/contrib/ps4pdf/}}. As comparison
% the analogous course for a bibliography is shown.\bigskip
%
% \newcolumntype{P}[1]{>{\mbox{}\raggedright}p{#1}}
% \noindent
% \begin{tabular}[t]{@{}P{.65\linewidth}@{}P{.35\linewidth}@{}}
%   \textbf{\PS\ graphics} & \textbf{bibliography} \tabularnewline
%   \toprule
%   |pdflatex document.tex| & |pdflatex document.tex|
%   \tabularnewline\midrule
%   \multicolumn{2}{@{}c@{}}{\emph{auxiliary calls}} \tabularnewline
%   |latex document.tex| \tabularnewline
%   |dvips -o document-pics.ps document.dvi| \tabularnewline
%   |ps2pdf document-pics.ps|
%   &
%   |bibtex document.aux|
%   \tabularnewline\midrule
%   |pdflatex document.tex| & |pdflatex document.tex|
% \end{tabular}\bigskip
%
% While creating the output only code from inside a \env{pspicture} or
% \env{postscript} environment is considered. \PS\ graphics files, which
% are passed as parameter of an \cmd{\includegraphics} statement, too are
% included into the \cmd{\PDFcontainer} file. This file's name is by
% default \meta{\cmd{\jobname}}|-pics.pdf|. It can be changed by
% re-defining the macro \cmd{\PDFcontainer}. \medskip
%
% \subsection{User commands}
%
% \DescribeEnv{pspicture}
% \indent\cmd{\begin}|{pspicture}|\oarg{keys}%
%   \parg{x0,x1}\parg{y0,y1} \dots\cmd{\end}|{pspicture}|
% \par\noindent
% The \env{pspicture} environment is not available when the option
% ``|nopstricks|'' was given. It is to be used the same way as if in
% PSTricks. In pdf\LaTeX\ mode this environment's contents is only
% displayed when the \cmd{\PDFcontainer} file was created before.
% \medskip
%
% \DescribeEnv{postscript}
% \cmd{\begin}|{postscript}|\oarg{keys} \dots\cmd{\end}|{postscript}|
% \par\noindent
% The \env{postscript} environment can contain any code except floats. In
% pdf\LaTeX\ mode its contents is take too off the \cmd{\PDFcontainer}
% file. Other as in the \env{pspicture} environment the necessary space is
% not always preserved when the \cmd{\PDFcontainer} file does not exist yet.
% \medskip
%
% \DescribeMacro{\includegraphics}
% \cmd{\includegraphics}\oarg{keys}\marg{filename}
% \par\noindent
% To be used as in \pkgname{graphics}/\pkgname{graphicx} defined. In
% pdf\LaTeX\ mode it is now additionally feasable to pass the name of an
% EPS file. Its visible contents too is taken from the \cmd{\PDFcontainer}
% file.
% \medskip
%
% \DescribeMacro{\savepicture}
% \cmd{\savepicture}\marg{name}
% \par\noindent
% The last output graphics (result of the \env{pspicture} or \env{postscript}
% environments or the \cmd{\includegraphics} statement with an \PS\ file as
% argument) is being saved in a file under the name as given by the parameter.
% \medskip
%
% \DescribeMacro{\usepicture}
% \cmd{\usepicture}\oarg{keys}\marg{name}
% \par\noindent
% The recently via \cmd{\savepicture} saved graphics is being output. The
% optional parameter is taken from the \cmd{\includegraphics} statement's
% set of specifiers.
% \medskip
%
% \subsection{Command options} \label{sec:copt}

% The behaviour of the \cmd{\includegraphics} and \cmd{\usepicture}
% statements and the \env{postscript} environment can be modified with any
% of the following parameters (key value syntax):
%   \begin{optlist}
%
%   \item[frame=\TorF] As with the \cmd{\fbox} statement a frame is drawn
%     around the graphics. Any change of size due to rotation is taken into
%     account. Drawing happens in pdf\LaTeX\ mode; before, in creating the
%     \cmd{\PDFcontainer} file, it is ignored. Default: false.
%
%   \item[innerframe=\TorF] As in ``|frame|'', but the frame is drawn
%     around the graphics, not its box.
%
%   \item[ignore=\TorF] If ``|true|'' no graphics is output. With
%     \cmd{\savepicture}\marg{name} the graphics can be used later in a
%     different place via \cmd{\usepicture}. Default: false.
%
%   \item[showname=\TorF] A caption of minimal font size records the used
%     file's name. Default: false.
%
%   \item[namefont=\META{font commands}] Controls the font used when
%     ``|showname=true|'' is set. Default: \cmd{\ttfamily}\cmd{\tiny}
%
%   \end{optlist}
%
%   All parameters can be set globally as in
%   \cmd{\setkeys}|{Gin}|\marg{key=value}.
%   \bigskip
%
% \StopEventually{}
%
% \section{Implementation}
%
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
% \subsection{Package options}
% \changes{v1.0c}{2005/01/29}{New options ``pstricks'', ``nopstricks'',
% ``draft'' and ``\mbox{final}''. (RN)}
% \changes{v1.1e}{2005/04/30}{New option ``displaymath'' (see preview
%   package). (HjG/RN)}
% \changes{v1.1f}{2005/04/30}{Package option ``ignore'' reimplemented.
%   Now the compilation of the dtx file in \LaTeX\ mode is possible. (RN)}
%    \begin{macrocode}
\newcommand*\ppf@TeX@mode{-1}
\newcommand*\ppf@draft{false}
\newif\if@ppf@PST@used\@ppf@PST@usedtrue
\newif\if@ppf@tightpage \@ppf@tightpagetrue
\DeclareOption{active}{\def\ppf@TeX@mode{0}}
\DeclareOption{inactive}{\def\ppf@TeX@mode{9}}
\DeclareOption{ignore}{\def\ppf@TeX@mode{999}}
\DeclareOption{pstricks}{\@ppf@PST@usedtrue}
\DeclareOption{nopstricks}{\@ppf@PST@usedfalse}
\DeclareOption{displaymath}{%
  \PassOptionsToPackage\CurrentOption{preview}}
\DeclareOption{draft}{\def\ppf@draft{true}}
\DeclareOption{final}{\def\ppf@draft{false}%
  \PassOptionsToPackage\CurrentOption{graphicx}}
%    \end{macrocode}
% \changes{v1.1i}{2005/06/29}{Package option ``final'' also
%   for ``graphicx''. (RN)}
%    \begin{macrocode}
\DeclareOption{notightpage}{\@ppf@tightpagefalse}%
\DeclareOption{tightpage}{\@ppf@tightpagetrue}%
\DeclareOption*{%
  \PassOptionsToPackage\CurrentOption{pstricks}}
\ProcessOptions\relax
\ifnum\ppf@TeX@mode=999\relax\expandafter\endinput\fi
%    \end{macrocode}
% \subsection{Compiler tests}
% It is tested which \TeX\ compiler in which mode of operation is actually
% used (see `|graphics.cfg|' in te\TeX/\TeX\ Live). Accordingly the
% environments \env{pspicture} and \env{postscript} gain each a different
% range of functions. This test is only executed when the options |active|
% or |inactive| were not given.
%    \begin{macrocode}
\ifnum\ppf@TeX@mode=-1\relax
  \begingroup
%    \end{macrocode}
% Default (\TeX{} with a dvi-to-ps converter)
%    \begin{macrocode}
    \chardef\x=0 %
%    \end{macrocode}
% Check pdf\TeX{}
%    \begin{macrocode}
    \@ifundefined{pdfoutput}{}{%
      \ifcase\pdfoutput\else
        \chardef\x=1 %
      \fi
    }%
%    \end{macrocode}
% Check V\TeX{}
%    \begin{macrocode}
    \@ifundefined{OpMode}{}{\chardef\x=2 }%
  \expandafter\endgroup
  \ifcase\x
%    \end{macrocode}
% \quad$\Rightarrow$\,DVI mode
%    \begin{macrocode}
    \def\ppf@TeX@mode{0}%
  \or
%    \end{macrocode}
% \quad$\Rightarrow$\,pdf\TeX{} is running in PDF mode
%    \begin{macrocode}
    \def\ppf@TeX@mode{1}%
  \else
%    \end{macrocode}
% \quad$\Rightarrow$\,V\TeX{} is running
%    \begin{macrocode}
    \def\ppf@TeX@mode{9}%
  \fi
\fi
%    \end{macrocode}
% \changes{v1.0g}{2005/02/12}{Definition of \cmd{\PDFcontainer}
%   now with \cmd{\edef}. (RN)}
%    \begin{macrocode}
\newcommand*\PDFcontainer{}
\edef\PDFcontainer{\jobname-pics.pdf}
\newcounter{pspicture}
\newcommand*\ppf@other@extensions[1]{}
\newcommand*\usepicture[2][]{}
\newcommand*\savepicture[1]{}
%    \end{macrocode}
%    \begin{macrocode}
\RequirePackage{graphicx}%
\let\ppf@Ginclude@graphics\Ginclude@graphics
\let\ppf@Gin@extensions\Gin@extensions
\let\ppf@Gin@ii\Gin@ii
%    \end{macrocode}
%    \begin{macrocode}
\newif\if@ppf@pdftex@graphic
\newif\ifGin@frame\Gin@framefalse
\newif\ifGin@innerframe\Gin@innerframefalse
\newif\ifGin@showname\Gin@shownamefalse
\newif\ifGin@ignore\Gin@ignorefalse
%    \end{macrocode}
% \cmd{\ifpr@outer} in fact is defined in package \pkgname{preview}. We
% have to do it here too since otherwise \TeX\ could ``stumble and fall''
% while parsing the \cs\texttt{ifcase} structure.
% \changes{v1.1i}{2005/06/29}{\cmd{\ifpr@outer} must be predefined. (HjG/RN)}
%    \begin{macrocode}
\newif\ifpr@outer
%    \end{macrocode}
% \begin{macro}{\ppf@is@pdfTeX@graphic}
% \changes{v1.0i}{2005/02/18}{No more errors for given files without
%   extensions. (RN)}
% \changes{v1.0r}{2005/03/25}{Changed \cmd{\ppf@is@known@graphic} to
%   \cmd{\ppf@is@pdfTeX@graphic}. Now pdf\TeX\ graphics are prefered. (RN)}
% Parameter |#1| is the name of a graphics file with or without extension,
% parameter |#2| contains the valid extensions in PDF mode,
% parameter |#3| contains the valid extensions in DVI mode.
% If it works to process the graphics in PDF mode, then the statements
% in |#4| are executed, otherwise those in |#5|.
%    \begin{macrocode}
\newcommand*\ppf@is@pdfTeX@graphic[5]{%
  \@ppf@pdftex@graphicfalse%
  \begingroup
    \edef\pdfTeXext{#2}%
%    \end{macrocode}
% Instead of loading the found graphics, only a test on file name extension.
%    \begin{macrocode}
    \def\Gin@setfile##1##2##3{%
      \edef\@tempb{##2}%
      \@for\@tempa:=\pdfTeXext\do{%
        \ifx\@tempa\@tempb\global\@ppf@pdftex@graphictrue\fi}}%
%    \end{macrocode}
% File types for both modes need to be determined to prevent a wrong
% error message ``File `|#1|' not found''.
%    \begin{macrocode}
    \edef\Gin@extensions{#2,#3}%
%    \end{macrocode}
% Trial invocation. Output is completely inhibited.
%    \begin{macrocode}
    \pr@outerfalse\ppf@Ginclude@graphics{#1}%
  \endgroup
  \if@ppf@pdftex@graphic#4\else#5\fi
}
%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}
  \if@ppf@PST@used\RequirePackage{pstricks}\fi
  \ifcase\ppf@TeX@mode\relax
%    \end{macrocode}
% \subsection{Extraction mode (DVI output)}
% The \env{pspicture} environment retains any definition from
% |pstricks.tex|. Only the code from the environments \env{pspicture} and
% \env{postscript} as well as \cmd{\includegraphics} with \PS\ files leads
% to records into the DVI file. The remainder of the document's code is
% ignored for output. After conversion of the DVI file via \PS\
% (``|dvips|'') into PDF (\cmd{\PDFcontainer} file) each graphics takes
% exactly one page in the \cmd{\PDFcontainer} file. The \TeX\ compiler with
% DVI output and the package option ``|active|'' both force this mode.
%    \begin{macrocode}
  \PackageInfo{pst-pdf}{%
    MODE: \ppf@TeX@mode\space (dvi -- extraction mode)}
  \RequirePackage[active,dvips,tightpage]{preview}[2005/01/29]%
  \newcommand*\ppf@PreviewBbAdjust{}
  \newcommand*\ppf@RestoreBbAdjust{%
    \let\PreviewBbAdjust\ppf@PreviewBbAdjust}%
%    \end{macrocode}
% The pdf\LaTeX\ mode compliant graphics file formats are needed too.
%    \begin{macrocode}
  \begingroup
    \let\AtBeginDocument\@gobble \let\PackageWarningNoLine\@gobbletwo
    \def\pdftexversion{121}\input{pdftex.def}%
    \edef\x{\endgroup\def\noexpand\ppf@other@extensions{\Gin@extensions}
    }%
  \x
%    \end{macrocode}
% \changes{v1.1c}{2005/04/17}{Supress handling of pdf\LaTeX\ graphic
%   formats in DVI mode. (RN)}
% In PDF mode no rules must be defined for its compliant (PNG, JPEG, PDF)
% graphics file formats (because of for example \progname{dvips} extensions).
% The universal EPS rule is used to at least find these files.
%    \begin{macrocode}
  \AtBeginDocument{%
    \@for\@tempa:=\ppf@other@extensions\do{%
      \expandafter\let\csname Gin@rule@\@tempa\endcsname\relax}%
    \DeclareGraphicsRule{*}{eps}{*}{}}%
%    \end{macrocode}
% No function in this mode.
%    \begin{macrocode}
  \define@key{Gin}{innerframe}[true]{}%
  \define@key{Gin}{frame}[true]{}%
  \define@key{Gin}{ignore}[true]{}%
  \define@key{Gin}{showname}[true]{}%
  \define@key{Gin}{namefont}{}%
%    \end{macrocode}
% \changes{v1.0o}{2005/03/12}{New code for ``notightpage''. (RN)}
%    \begin{macrocode}
  \if@ppf@tightpage\else
    \def\PreviewBbAdjust{%
      -.5\paperwidth -.5\paperheight .5\paperwidth .5\paperheight}%
    \AtEndDocument{%
      \PackageWarningNoLine{pst-pdf}{Picture container needs cropping.}}%
  \fi
%    \end{macrocode}
% \begin{environment}{postscript}
% \changes{v1.0e}{2005/02/03}{``trim'' option added. (RN)}
% The \env{postscript} environment utilises the trim option in the same
% manner as does \cmd{\includegraphics} (any specification without dimension
% is interpreted as if given in bp).
%    \begin{macrocode}
  \newenvironment{postscript}[1][]%
  {%
    \global\let\ppf@PreviewBbAdjust\PreviewBbAdjust
    \if@ppf@tightpage
      \begingroup
        \setkeys{Gin}{#1}%
        \xdef\PreviewBbAdjust{%
          -\Gin@vllx bp -\Gin@vlly bp \Gin@vurx bp \Gin@vury bp}%
      \endgroup
    \fi
    \ignorespaces
  }%
  {\aftergroup\ppf@RestoreBbAdjust}%
%    \end{macrocode}
% \end{environment}
%    \begin{macrocode}
  \PreviewEnvironment{postscript}%
  \AtBeginDocument{%
    \@ifundefined{PSTricksLoaded}{}%
    {%
%    \end{macrocode}
% \begin{environment}{pspicture}
% Announce \pkgname{preview} original definition.
%    \begin{macrocode}
      \PreviewEnvironment{pspicture}%
%    \end{macrocode}
% \end{environment}
% \begin{environment}{psmatrix}
% Announce \pkgname{preview} original definition..
%    \begin{macrocode}
      \@ifundefined{psmatrix}{}%
      {%
        \PreviewEnvironment{psmatrix}%
        \newcommand*\ppf@set@mode{}%
        \newcommand*\ppf@test@mmode{%
        \ifmmode
          \ifinner
            \let\ppf@set@mode=$%
          \else
            \def\ppf@set@mode{$$}%
          \fi
        \else
          \let\ppf@set@mode=\@empty
        \fi
        }%
        \let\ppf@psmatrix=\psmatrix
        \expandafter\let\expandafter\ppf@pr@psmatrix%
          \expandafter=\csname pr@\string\psmatrix\endcsname
        \let\ppf@endpsmatrix=\endpsmatrix
        \def\psmatrix{\ppf@test@mmode\ppf@psmatrix}
        \expandafter\def\csname pr@\string\psmatrix\endcsname{%
          \ppf@set@mode\ppf@pr@psmatrix}%
        \def\endpsmatrix{\ppf@endpsmatrix\ppf@set@mode}%
      }%
%    \end{macrocode}
% \end{environment}
% Announce internal macro \cmd{\pst@object} to enable the use of some
% PSTricks code outside of \env{pspicture} environments. At the moment
% invocations of the following kind are feasible:
% \begin{flushleft}
%   \cmd{\pst@object}%
%   \marg{m}\meta{\texttt{*}}\oarg{o}\marg{o}\marg{o}\parg{o}\parg{o}\parg{o} \\
%   \qquad (|m|\,$=$\,necessary, |*|\,$=$\,optional, |o|\,$=$\,optional)
% \end{flushleft}
% More than three optional arguments at the call's end, as in
% \cmd{\psline} possible, do not work yet.
% \changes{v1.1a}{2005/04/07}{Support for the internal PSTricks macro
%   \cmd{\pst@object}. (HjG/RN)}
%    \begin{macrocode}
      \PreviewMacro[{{}*[]%
        ?\bgroup{#{#1}{{#1}}}{}%
        ?\bgroup{#{#1}{{#1}}}{}%
        ?({#{(#1)}{({#1})}}{}%
        ?({#{(#1)}{({#1})}}{}%
        ?({#{(#1)}{({#1})}}{}%
        }]{\pst@object}}
%    \end{macrocode}
% Prevent multiple test-wise setting of table contents by ``tabularx''.
% \changes{v1.1c}{2005/04/17}{Special support for ``tabularx''. (RN)}
%    \begin{macrocode}
    \@ifundefined{tabularx}{}{%
      \def\tabularx#1#2{\tabular{#2}}%
      \newcolumntype{X}{c}%
      \let\endtabularx=\endtabular}%
  }%
%    \end{macrocode}
% \begin{macro}{\Ginclude@graphics}
% All graphics content of well known format (for instance EPS files) is
% treated in a regular way, which in this mode denotes that it is subject
% to \pkgname{preview} functions. Other graphics content (for instance PDF
% files) is ignored.
% \changes{v1.0k}{2005/02/23}{Prevent division by zero. (RN)}
% \changes{v1.1h}{2005/06/26}{Check if inside of a PS-related
%   environment (correct graphic inclusion). (RN)}
% \changes{v1.1i}{2005/06/29}{Correction of the inside check. (RN/HjG)}
%    \begin{macrocode}
  \def\Ginclude@graphics#1{%
    \ifpr@outer
%    \end{macrocode}
% Generally pdf\TeX\ supported graphics formats are intended to be preferred
% (inclusion in final pdf\TeX\ run). If it's a \PS\ type graphics, then the
% original definition is in function again and registration for the
% \pkgname{preview} package is necessary in order to convert this \PS\ type
% graphics into PDF.
%    \begin{macrocode}
      \ppf@is@pdfTeX@graphic{#1}{\ppf@other@extensions}{\Gin@extensions}%
%    \end{macrocode}
% Dummy box to prevent a division by zero while scaling or rotating.
% Otherwise ignored.
%    \begin{macrocode}
      {\rule{10pt}{10pt}}%
      {\ppf@Ginclude@graphics{#1}}%
    \else
%    \end{macrocode}
% Inside a \PS\ environment (\env{pspicture} etc.) \cmd{\includegraphics} has
% to behave as in its original definition (only DVIPS supported graphics
% formats are allowed).
%    \begin{macrocode}
      \ppf@Ginclude@graphics{#1}%
    \fi
  }%
%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}
  \PreviewMacro[{{}}]{\ppf@Ginclude@graphics}%
  \let\pdfliteral\@gobble%
\or
%    \end{macrocode}
% \subsection{pdf\LaTeX\ mode (PDF output)}
% When the \cmd{\PDFcontainer} file (default:
% \meta{\cmd{\jobname}}|-pics.pdf|) exists, the contents of the
% environments \env{pspicture} and \env{postscript} is ignored. Instead the
% corresponding graphics from the \cmd{\PDFcontainer} file is used.
%    \begin{macrocode}
  \PackageInfo{pst-pdf}{MODE: \ppf@TeX@mode\space (pdfTeX mode)}%
  \@temptokena{%
    \let\Gin@PS@file@header\@gobble\let\Gin@PS@literal@header\@gobble
    \let\Gin@PS@raw\@gobble\let\Gin@PS@restored\@gobble
    \@ifundefined{PSTricksLoaded}{}{%
%    \end{macrocode}
% Necessary if PSTricks $<$ 2.0.
%    \begin{macrocode}
      \PSTricksOff
      \@ifundefined{c@lor@to@ps}{\def\c@lor@to@ps#1 #2\@@{}}{}}}%
%    \end{macrocode}
% \PS\ output is now inhibited and later once again.
%    \begin{macrocode}
  \the\@temptokena
  \expandafter\AtBeginDocument\expandafter{\the\@temptokena}%
  \@ifundefined{PSTricksLoaded}{}
  {%
%    \end{macrocode}
% To parse the arguments of PSTricks' \cmd{\pst@object} we load
% \pkgname{preview} in active mode, but restore the default definitions of
% \cmd{\output} and \cmd{\shipout}. \cmd{\pr@startbox} and \cmd{\pr@endbox}
% serve here only to disable \cmd{\pst@object} and to load the
% corresponding graphics from the \cmd{\PDFcontainer} file. At present a
% maximum of three optional parameters in round braces (parenthesis) at the
% end of \cmd{\pst@object} is supported, which is sufficient, but not
% always enough.
% \changes{v1.1b}{2005/04/09}{Ignore the call of
%   \cmd{\nofiles} inside of \pkgname{preview}. (RN)}
%    \begin{macrocode}
    \newtoks\ppf@temptoken
    \ppf@temptoken\expandafter{\the\output}%
    \let\ppf@nofiles\nofiles \let\nofiles\relax
    \RequirePackage[active]{preview}[2005/01/29]%
    \let\shipout=\pr@shipout \let\nofiles\ppf@nofiles
    \output\expandafter{\the\ppf@temptoken}%
    \ppf@temptoken{}%
%    \end{macrocode}
% \cmd{\pr@startbox}, \cmd{\pr@endbox}: simpler over original definitions.
%    \begin{macrocode}
    \long\def\pr@startbox#1#2{%
    \ifpr@outer
      \toks@{#2}%
      \edef\pr@cleanup{\the\toks@}%
      \setbox\@tempboxa\vbox\bgroup
      \everydisplay{}%
      \pr@outerfalse%
      \expandafter\@firstofone
    \else
      \expandafter\@gobble
    \fi{#1}}%
    \def\pr@endbox{%
    \egroup
    \setbox\@tempboxa\box\voidb@x
    \ppf@@getpicture
    \pr@cleanup}%
%    \end{macrocode}
% (See also the identical definition in DVI mode.)
%    \begin{macrocode}
    \AtBeginDocument{%
      \@ifundefined{pst@object}{}%
      {%
        \PreviewMacro[{{}*[]%
          ?\bgroup{#{#1}{{#1}}}{}%
          ?\bgroup{#{#1}{{#1}}}{}%
          ?({#{(#1)}{({#1})}}{}%
          ?({#{(#1)}{({#1})}}{}%
          ?({#{(#1)}{({#1})}}{}%
          }]{\pst@object}}%
      }%
    }%
%    \end{macrocode}
% Too the supported file name extensions from DVI mode are needed.
%    \begin{macrocode}
  \begingroup
    \input{dvips.def}%
    \edef\x{\endgroup\def\noexpand\ppf@other@extensions{\Gin@extensions}}%
  \x
%    \end{macrocode}
% Dummy definition for in DVI mode supported file formats.
%    \begin{macrocode}
  \DeclareGraphicsRule{*}{eps}{*}{}%
%    \end{macrocode}
%    \begin{macrocode}
  \define@key{Gin}{innerframe}[true]{%
    \lowercase{\Gin@boolkey{#1}}{innerframe}}%
  \define@key{Gin}{frame}[true]{%
    \lowercase{\Gin@boolkey{#1}}{frame}}%
  \define@key{Gin}{ignore}[true]{%
    \lowercase{\Gin@boolkey{#1}}{ignore}}%
  \define@key{Gin}{frame@@}{%
%    \end{macrocode}
% (For internal use only!)
%    \begin{macrocode}
    \edef\@tempa{\toks@{\noexpand\frame{\the\toks@}}}%
    \ifcase#1\relax
      \ifGin@innerframe\else\let\@tempa\relax\fi
    \or
      \ifGin@frame\else\let\@tempa\relax\fi
    \fi
    \@tempa
  }%
  \define@key{Gin}{showname}[true]{%
    \lowercase{\Gin@boolkey{#1}}{showname}}%
  \define@key{Gin}{namefont}{%
    \begingroup
      \@temptokena\expandafter{\ppf@namefont#1}%
      \edef\x{\endgroup\def\noexpand\ppf@namefont{\the\@temptokena}}%
    \x
  }%
  \newcommand*\ppf@filename{}%
  \newcommand*\ppf@namefont{\tiny\ttfamily}%
  \newcommand*\ppf@Gin@keys{}%
  \let\ppf@Gin@setfile\Gin@setfile
%    \end{macrocode}
% \begin{macro}{\Gin@setfile}
% Save real file name and, if applicable, page number for later use.
% \changes{v1.0k}{2005/02/23}{Show also the pagenumber if exists. (RN)}
%    \begin{macrocode}
  \def\Gin@setfile#1#2#3{\ppf@Gin@setfile{#1}{#2}{#3}%
    \xdef\ppf@filename{%
      #3\ifx\GPT@page\@empty\else(\GPT@page)\fi}}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\Gin@ii}
%   Examine the options ``frame'', ``ignore'', etc. as soon as other
%   special cases.
% \changes{v1.0s}{2005/03/28}{Rewritten. (RN)}
%    \begin{macrocode}
  \def\Gin@ii[#1]#2{%
    \begingroup
%    \end{macrocode}
% The value of \cmd{\ifGin@innerframe} has to be known before the inner
% frame is drawn. The values for \cmd{\ifGin@showname} and
% \cmd{\ppf@namefont} need to be available after rendering the graphics
% too. Thus beforehand and protected inside a group examine the options.
%    \begin{macrocode}
      \setkeys{Gin}{#1}%
      \@temptokena{#1}\def\@tempb{#2}%
%    \end{macrocode}
% Finds empty file name when calling \cmd{\usepicture}.
%    \begin{macrocode}
      \ifx\@tempb\@empty\else
        \ppf@is@pdfTeX@graphic{#2}{\Gin@extensions}{\ppf@other@extensions}%
%    \end{macrocode}
% Graphics out of \cmd{\PDFcontainer} are complete -- scaled, rotated, etc.
% Don't apply these things again and therefore ignore the optional parameters.
%    \begin{macrocode}
        {%
          \ifx\@tempb\PDFcontainer
            \@temptokena{page=\GPT@page}%
          \fi
        }%
        {%
          \refstepcounter{pspicture}%
          \@temptokena{page=\the\c@pspicture}\def\@tempb{\PDFcontainer}%
        }%
      \fi
      \ifGin@ignore\else
%    \end{macrocode}
% ``|frame@@=0|''\,$=$\,inner frame, ``|frame@@=1|''\,$=$\,outer frame.
%    \begin{macrocode}
        \edef\@tempa{\noexpand\ppf@Gin@ii[frame@@=0,\the\@temptokena,
          frame@@=1]{\@tempb}}%
        \@tempa
        \ifGin@showname
          \ppf@namefont
          \raisebox{-\ht\strutbox}[0pt][0pt]{\llap{\ppf@filename}}%
          \gdef\ppf@filename{}%
        \fi
      \fi
    \endgroup
  }%
%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}
  \IfFileExists{\PDFcontainer}%
  {%
%    \end{macrocode}
% \begin{macro}{\ppf@container@max}
% The number of pages as contained in \cmd{\PDFcontainer} file.
%    \begin{macrocode}
    \pdfximage{\PDFcontainer}%
    \edef\ppf@container@max{\the\pdflastximagepages}%
%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}
    \AtEndDocument{%
      \ifnum\c@pspicture>\z@
%    \end{macrocode}
% A warning only makes sense when a graphics is needed at all.
%    \begin{macrocode}
        \ifnum\c@pspicture=\ppf@container@max\else
          \PackageWarningNoLine{pst-pdf}{%
            `\PDFcontainer' contains \ppf@container@max\space pages
            \MessageBreak but \the\c@pspicture\space pages are requested:
            \MessageBreak File `\PDFcontainer' is no more valid!
            \MessageBreak Recreate it
          }%
        \fi
      \fi
    }%
  }%
  {%
    \def\ppf@container@max{0}%
    \AtEndDocument{%
      \ifnum\c@pspicture>\z@
        \filename@parse{\PDFcontainer}%
        \PackageWarningNoLine{pst-pdf}{%
          File `\PDFcontainer' not found.\MessageBreak
          Use the following commands to create it:\MessageBreak
          ----------------------------------------------------
          \MessageBreak
          latex \jobname.tex\MessageBreak
          dvips -o \filename@base.ps \jobname.dvi\MessageBreak
          ps2pdf \filename@base.ps\MessageBreak
          ----------------------------------------------------
        }%
      \fi
    }%
  }%
%    \end{macrocode}
% \begin{macro}{\ppf@isnum}
% If parameter |#1| is numeric, the instructions in |#2|,
% otherwise those in |#3| are executed (see \pkgname{bibtopic.sty}).
%    \begin{macrocode}
  \newcommand\ppf@isnum[1]{%
    \if!\ifnum9<1#1!\else_\fi\expandafter\@firstoftwo
    \else\expandafter\@secondoftwo\fi}%
%    \end{macrocode}
% \end{macro}
% \begin{environment}{postscript}
% \changes{v1.0h}{2005/02/15}{Based no more on the comment environment
%   from the verbatim package. (RN)}
% \begin{environment}{pspicture}
% \changes{v1.1g}{2005/05/28}{pspicture environment
%   must still parse its arguments. (RN/HjG)}
% Both environments ignore their contents and load instead the corresponding
% graphics out of the \cmd{\PDFcontainer} file. The value of the herein used
% |pspicture| counter's value can be used in \cmd{\label}/\cmd{\ref}.
% \begin{environment}{psmatrix}
% \changes{v1.1d}{2005/04/19}{Support for PSTricks environment
%   ``psmatrix''. (RN)}
% \changes{v1.1g}{2005/05/28}{``psmatrix'' environment
%   (preserve math mode). (RN/HjG)}
%    \begin{macrocode}
  \newcommand*\ppf@set@mode{}%
  \newcommand*\ppf@test@mmode{%
  \ifmmode
    \ifinner
      \let\ppf@set@mode=$%
    \else
      \def\ppf@set@mode{$$}%
    \fi
  \else
    \let\ppf@set@mode=\@empty
  \fi
  }
  \newenvironment{postscript}[1][]
  {%
    \ppf@test@mmode
    \gdef\ppf@Gin@keys{}%
    \def\@tempa{postscript}\ifx\@tempa\@currenvir\gdef\ppf@Gin@keys{#1}\fi
%    \end{macrocode}
% Inside this environment parsing of \cmd{\pst@object}'s arguments is not
% necessary, thus the original definition is used again.
%    \begin{macrocode}
    \expandafter\let\expandafter\pst@object
      \csname pr@\string\pst@object\endcsname
    \pr@outerfalse
%    \end{macrocode}
% Needed for \cmd{\psmatrix}.
%    \begin{macrocode}
    \@makeother\&%
    \def\Gin@ii[##1]##2{}\setbox\@tempboxa=\vbox\bgroup
    \ppf@set@mode
  }%
  {\ppf@set@mode\egroup\aftergroup\ppf@@getpicture}%
  \AtBeginDocument{%
    \@ifundefined{PSTricksLoaded}{}%
    {%
      \iffalse
        \PreviewEnvironment{pspicture}% Why doesn't it work?
        \g@addto@macro\pspicture{%
          %%\pr@outerfalse% necessary, or already there anyway?
          \@makeother\&% necessary?
          \def\Gin@ii[#1]#2{}%
        }%
        \g@addto@macro\endpspicture{\ppf@@getpicture}%
      \else
        \def\pst@@@picture[#1](#2,#3)(#4,#5){\postscript}%
        \def\endpspicture{\endpostscript\endgroup}%
      \fi
      \@ifundefined{psmatrix}{}%
      {\let\psmatrix=\postscript\let\endpsmatrix=\endpostscript}%
    }%
  }%
%    \end{macrocode}
% \end{environment}
% \end{environment}
% \end{environment}
% \begin{macro}{\savepicture}
% \changes{v1.0f}{2005/02/04}{New macro \cmd{\savepspicture}. (RN)}
% Saves the recent graphics' number in a macro named \cmd{\ppf@@@}|#1|.
%    \begin{macrocode}
  \def\savepicture#1{%
    \expandafter\xdef\csname ppf@@@#1\endcsname{\the\pdflastximage}}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\usepicture}
% \changes{v1.0f}{2005/02/04}{New macro \cmd{\usepspicture}. Useful
%   for putting a PSTricks graphic in a box or something else. (RN)}
% \changes{v1.0g}{2005/02/12}{Now \cmd{\usepspicture} does accept a
%   numerical parameter. (RN)}
% \changes{v1.0q}{2005/03/20}{Now \cmd{\usepspicture} works for all
%   kind of graphics. (RN)}
% Inserts graphics with symbolic name |#2|. This name has to be declared
% beforehand in \cmd{\savepicture}\marg{name}. Instead of a name a number
% can be used too, which directly addresses a graphics in the
% \cmd{\PDFcontainer} file. The optional parameter |#1| corresponds to the
% one in \cmd{\includegraphics}.
%    \begin{macrocode}
  \renewcommand*\usepicture[2][]{%
    \@ifundefined{ppf@@@#2}%
    {%
      \ppf@isnum{#2}%
      {\ppf@getpicture{#1}{#2}}%
      {\@latex@error{picture `#2' undefined}\@ehc}%
    }%
    {%
      \begingroup
        \def\Ginclude@graphics##1{%
          \xdef\ppf@filename{#2}%
          \setbox\z@\hbox{\pdfrefximage\@nameuse{ppf@@@#2}}%
          \Gin@nat@height\ht\z@ \Gin@nat@width\wd\z@
          \def\Gin@llx{0} \let\Gin@lly\Gin@llx
          \Gin@defaultbp\Gin@urx{\Gin@nat@width}%
          \Gin@defaultbp\Gin@ury{\Gin@nat@height}%
          \Gin@bboxtrue\Gin@viewport@code
          \Gin@nat@height\Gin@ury bp%
          \advance\Gin@nat@height-\Gin@lly bp%
          \Gin@nat@width\Gin@urx bp%
          \advance\Gin@nat@width-\Gin@llx bp%
          \Gin@req@sizes
          \ht\z@\Gin@req@height \wd\z@\Gin@req@width
          \leavevmode\box\z@}%
        \define@key{Gin}{type}{}%
        \includegraphics[scale=1,#1]{}%
      \endgroup
    }}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\ppf@getpicture}
% Inserts the page (graphics) with number |#2| from the \cmd{\PDFcontainer}
% file. Parameter |#1|: any option as in \cmd{\includegraphics}.
%    \begin{macrocode}
  \newcommand*\ppf@getpicture[2]{%
    \@tempcnta=#2\relax%
    \ifnum\@tempcnta>\ppf@container@max
      \PackageWarningNoLine{pst-pdf}{%
        pspicture No. \the\@tempcnta\space undefined}%
    \else
      \includegraphics[draft=\ppf@draft,#1,page=\the\@tempcnta]%
        {\PDFcontainer}%
    \fi
    \gdef\ppf@Gin@keys{}}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\ppf@@getpicture}
% Inserts next page (graphics) from the \cmd{\PDFcontainer} file.
%    \begin{macrocode}
  \newcommand*\ppf@@getpicture{%
    \ifpr@outer
      \refstepcounter{pspicture}%
      \expandafter\ppf@getpicture\expandafter{\ppf@Gin@keys}%
      {\the\c@pspicture}%
    \fi}%
%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}
\else
%    \end{macrocode}
% \subsection{Inactive Mode}
% Only the packages \pkgname{pstricks} and \pkgname{graphicx} are loaded
% -- no further exertion of influence. The package option
% ``|inactive|'' as soon as the V\TeX compiler force this mode.
%    \begin{macrocode}
  \PackageInfo{pst-pdf}{MODE: \ppf@TeX@mode\space (inactive mode)}%
  \newenvironment{postscript}[1][]{\ignorespaces}{}
  \let\ppf@is@pdfTeX@graphic\relax
\fi
%    \end{macrocode}
% \changes{v1.0f}{2005/02/04}{Config file loading added. (RN)}
%    \begin{macrocode}
\InputIfFileExists{pst-pdf.cfg}{%
  \PackageInfo{pst-pdf}{Local config file pst-pdf.cfg used}}{}
%</package>
%    \end{macrocode}
%
% \Finale
%\endinput
%
% And here comes the example document ...
%<*example>
\listfiles\errorcontextlines=100\relax
\documentclass[12pt]{article}

%% before `psfrag'!
\usepackage[displaymath,dvipsnames]{pst-pdf}
%%\usepackage[displaymath,dvipsnames,notightpage]{pst-pdf}

\usepackage{pst-node,pst-tree}

\usepackage{psfrag,tabularx}

\pagestyle{empty}

\begin{postscript}[trim=0 0 0 0,ignore]
  \includegraphics[width=.475\textwidth]{penguin.eps}
\end{postscript}
\savepicture{ps:A}

\begin{document}

\setkeys{Gin}{showname,frame}%

\psset{unit=0.0714\textwidth}% 1/14 * \textwidth
\newpsobject{showgrid}{psgrid}{subgriddiv=1,griddots=10,gridlabels=6pt}

\newcommand*\BASEMARKER{\rule{.5em}{.4pt}}

\setlength\parindent{0pt}

\centering

\section*{\textsf{pst-pdf:}
  PSTricks and other PostScript code in pdf\LaTeX\ documents}

\vfill

\begin{pspicture}(-5.5,-5.25)(5.25,5.25)%
%%\begin{pspicture}[trim=-.5 -.25 .25 .25,frame](-5,-5)(5,5)% PSTricks2
  \pscircle*[linecolor=Apricot]{5}
  \rput(0,0.5){\includegraphics[width=8\psxunit]{elephant}}
  \Huge\sffamily\bfseries
  \rput(-4.5,4.5){A} \rput(4.5,4.5){B}
  \rput(-4.5,-4.5){C}\rput(4.5,-4.5){D}
  \rmfamily
  \rput(0,-3.8){PSTricks}
  \rput(0,3.8){\LaTeX}
  \showgrid
\end{pspicture}\savepicture{ps:B}

\vfill\null\newpage

\usepicture{ps:A}
\hfill
\includegraphics[width=.475\textwidth]{insect1}

\vfill

\usepicture[angle=180,origin=c]{ps:A}
\hfill
\usepicture[width=.47\textwidth]{ps:B}

\includegraphics[width=.475\textwidth,frame=false,
  namefont={\Huge\itshape}]{knuth}
\hfill
\usepicture[angle=45,origin=bl,width=.475\textwidth,innerframe]{1}%

\vfill

\includegraphics[width=.47\textwidth]{psf-demo}
\hfill
\begin{psfrags}
  \psfragscanon
  \psfrag{x1}[br][  ]{\LaTeX} \psfrag{x2}[br][br]{\LaTeX}
  \psfrag{x3}[br][tl]{\LaTeX} \psfrag{x4}[br][Br]{\LaTeX}
  \psfrag{x5}[Br][ r][1.15][45]{\Huge\LaTeX}
  \psfrag{x6}[tl][ l][1.15][45]{\Huge\LaTeX}
  \includegraphics[width=.47\textwidth]{psf-demo}
\end{psfrags}

\includegraphics[width=\textwidth,showname=false,frame=false]{insect15}

\bigskip

\Large

\begin{equation}
  \sigma(t)=\frac{1}{\sqrt{2\pi}}
  \int^t_0 e^{-x^2/2} dx
\end{equation}

\clearpage

\setkeys{Gin}{showname=false,frame=false}%

{ \Huge \renewcommand*\arraystretch{1.5}

  \noindent
  \begin{tabularx}{\textwidth}{|@{}>{\centering}X@{}|} \hline

  \psframebox*[fillcolor=green,framearc=.6]{HUGO}\BASEMARKER
  \fbox{\BASEMARKER GUSTAV}  \tabularnewline

  \begin{postscript}
  \psframebox*[fillcolor=green,framearc=.6]{HUGO}\BASEMARKER
  \fbox{\BASEMARKER GUSTAV}
  \end{postscript}           \tabularnewline \hline

  \end{tabularx}

}

\bigskip

\definecolor{pink}{rgb}{1, .75, .8}
\renewcommand\psedge{\nccurve}
\newcommand{\Female}[2][]{{\psset{linecolor=pink}\TR[#1]{\emph{#2}}}}
\newcommand{\Male}[2][]{{\psset{linecolor=blue}\TR[#1]{#2}}}

\psset{nodesep=2pt,angleA=90,angleB=-90}

{ \footnotesize

   %% From: The \LaTeX\ Graphics Companion; first release.
   \pstree[treemode=U]{\Female{{\bfseries Matilde}}}{%
     \pstree{\Male{Sebastian}}{%
       \pstree{\Male[name=P]{Philip}}{\Male{Frederick}\Female{Ethel}}
       \pstree{\Female[name=W]{Mary}}{\Male{Lionel}\Female{Agnes}}}
     \pstree{\Female{Leonor}}{%
       \pstree{\Male[name=R]{Ra\'ul}}{\Male{Joaquim}\Female{J\'ulia}}
       \pstree{\Female[name=A]{Am\'elia}}{\Male{\'Alvaro}\Female{Augusta}}}
   }

  \iffalse  % --> Cannot work outside of a special environment!
  \psset{linecolor=green,doubleline=true,linestyle=dotted}
  \ncline{P}{W}\nbput{1940}
  \ncline{R}{A}\nbput{1954}
  \fi
}

\bigskip

\psset{arrows=->,fillcolor=white,fillstyle=solid}

\footnotesize

\newcommand{\Show}[1]{\psshadowbox{#1}}

\begin{psmatrix}[mnode=r,ref=t,unit=.3]
  \psframebox[linestyle=none,framesep=.75]{%
    \begin{psmatrix}[name=A,ref=c]
      \Show{Stakeholder}
    \end{psmatrix}} &
  \psframebox[fillstyle=solid,fillcolor=pink,framesep=.95]{%
    \rule{1cm}{0pt}
    \begin{psmatrix}[ref=c]
      [name=B]\Show{Goal} & \Show{Criteria}\\
              \Show{Sub-goal} & \Show{Justification}
      \ncline{1,1}{1,2}
      \ncline{1,1}{2,2}
      \ncline{1,1}{2,1}\tlput{Strategy}
      \ncline{2,1}{2,2}
    \end{psmatrix}}
  \ncline[angleB=180]{A}{B}\naput[npos=.7]{Model}
\end{psmatrix}

\begin{postscript}[angle=90,height=\textheight,frame=false]

\pstree[treemode=U]{\Female{{\bfseries Matilde}}}{%
  \pstree{\Male{Sebastian}}{%
    \pstree{\Male[name=P]{Philip}}{\Male{Frederick}\Female{Ethel}}
    \pstree{\Female[name=W]{Mary}}{\Male{Lionel}\Female{Agnes}}}
  \pstree{\Female{Leonor}}{
  \pstree{\Male[name=R]{Ra\'ul}}{\Male{Joaquim}\Female{J\'ulia}}
  \pstree{\Female[name=A]{Am\'elia}}{\Male{\'Alvaro}\Female{Augusta}}}
}

\psset{linecolor=green,doubleline=true,linestyle=dotted}
\ncline{P}{W}\nbput{1940}
\ncline{R}{A}\nbput{1954}

\end{postscript}

\bigskip

\psset{arrows=-}

\begin{displaymath}
  \bordermatrix{%
  & A            & B & C\cr
  & \rnode{D}{D} & E & \rnode{F}{F}\cr
  & G            & H & I\cr
  & \rnode{J}{J} & K & M
  }
  \ncline[nodesep=-1em,linecolor=red]{D}{F}
  \ncline[nodesep=-1em,linecolor=red]{D}{J}
\end{displaymath}

\end{document}
%</example>
