%%
%% This is file `perltex.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% perltex.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Copyright (C) 2010 Scott Pakin <scott+pt@pakin.org>
%% 
%% This file may be distributed and/or modified under the conditions of
%% the LaTeX Project Public License, either version 1.3c 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.3c or later is part of all distributions of LaTeX version
%% 2006/05/20 or later.
%% 
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{perltex}
    [2010/07/10 v2.1 LaTeX macros for use with PerlTeX]
\newif\ifplmac@required \plmac@requiredtrue
\DeclareOption{optional}{\plmac@requiredfalse} \ProcessOptions\relax
\newif\ifperl
\perltrue
\@ifundefined{plmac@tag}{\perlfalse}{}
\@ifundefined{plmac@tofile}{\perlfalse}{}
\@ifundefined{plmac@fromfile}{\perlfalse}{}
\@ifundefined{plmac@toflag}{\perlfalse}{}
\@ifundefined{plmac@fromflag}{\perlfalse}{}
\@ifundefined{plmac@doneflag}{\perlfalse}{}
\@ifundefined{plmac@pipe}{\perlfalse}{}
\ifperl
\else
  \ifplmac@required
    \PackageError{perltex}{Document must be compiled using perltex}
      {Instead of compiling your document directly with latex, you need
       to\MessageBreak use the perltex script.  \space perltex sets up
       a variety of macros needed by\MessageBreak the perltex
       package as well as a listener process needed for\MessageBreak
       communication between LaTeX and Perl.}
    \else
      \bgroup
        \obeyspaces
        \typeout{perltex: Document was compiled without using the perltex script;}
        \typeout{         it may not print as desired.}
      \egroup
  \fi
\fi
\def\perlnewcommand{%
  \let\plmac@command=\newcommand
  \let\plmac@next=\relax
  \@ifnextchar*{\plmac@newcommand@i}{\plmac@newcommand@i!}%
}
\def\perlrenewcommand{%
  \let\plmac@next=\relax
  \let\plmac@command=\renewcommand
  \@ifnextchar*{\plmac@newcommand@i}{\plmac@newcommand@i!}%
}
\def\plmac@newcommand@i#1#2{%
  \ifx#1*%
    \def\plmac@starchar{*}%
  \else
    \def\plmac@starchar{}%
  \fi
  \def\plmac@macname{#2}%
  \let\plmac@oldbody=#2\relax
  \expandafter\def\expandafter\plmac@cleaned@macname\expandafter{%
    \expandafter\string\plmac@macname}%
  \@ifnextchar[{\plmac@newcommand@ii}{\plmac@newcommand@ii[0]}%]
}
\def\plmac@newcommand@ii[#1]{%
  \def\plmac@numargs{#1}%
  \@ifnextchar[{\plmac@newcommand@iii@opt}
               {\plmac@newcommand@iii@no@opt}%]
}
\def\plmac@newcommand@iii@opt[#1]{%
  \def\plmac@defarg{#1}%
  \plmac@haveargs
}
\def\plmac@newcommand@iii@no@opt{%
  \let\plmac@defarg=\relax
  \plmac@haveargs
}
\newtoks\plmac@perlcode
\def\plmac@haveargs{%
  \begingroup
    \let\do\@makeother\dospecials
    \catcode`\^^M=\active
    \newlinechar`\^^M
    \endlinechar=`\^^M
    \catcode`\{=1
    \catcode`\}=2
    \afterassignment\plmac@havecode
    \global\plmac@perlcode
}
{\catcode`\^^M=11\gdef\plmac@sep{^^M}}
\newcount\plmac@argnum
\def\plmac@havecode{%
  \endgroup
  \edef\plmac@define@sub{%
    \noexpand\plmac@write@perl{DEF\plmac@sep
      \plmac@tag\plmac@sep
      \plmac@cleaned@macname\plmac@sep
      \plmac@tag\plmac@sep
      \the\plmac@perlcode
    }%
  }%
  \plmac@define@sub
  \edef\plmac@body{%
    USE\plmac@sep
    \plmac@tag\plmac@sep
    \plmac@cleaned@macname
  }%
  \let\plmac@hash=\relax
  \plmac@argnum=\@ne
  \loop
    \ifnum\plmac@numargs<\plmac@argnum
    \else
      \edef\plmac@body{%
        \plmac@body\plmac@sep\plmac@tag\plmac@sep
        \plmac@hash\plmac@hash\number\plmac@argnum}%
      \advance\plmac@argnum by \@ne
  \repeat
  \let\plmac@hash=##%
  \expandafter\let\plmac@macname=\relax
  \ifx\plmac@defarg\relax
    \edef\plmac@define@command{%
      \noexpand\plmac@command\plmac@starchar{\plmac@macname}%
      [\plmac@numargs]{%
        \noexpand\plmac@write@perl{\plmac@body}%
      }%
  }%
  \else
    \edef\plmac@define@command{%
      \noexpand\plmac@command\plmac@starchar{\plmac@macname}%
      [\plmac@numargs][\plmac@defarg]{%
        \noexpand\plmac@write@perl{\plmac@body}%
      }%
  }%
  \fi
  \expandafter\let\plmac@macname=\plmac@oldbody
  \plmac@define@command
  \plmac@next
}
\def\perlnewenvironment{%
  \let\plmac@command=\newcommand
  \let\plmac@next=\plmac@end@environment
  \@ifnextchar*{\plmac@newenvironment@i}{\plmac@newenvironment@i!}%
}
\def\perlrenewenvironment{%
  \let\plmac@command=\renewcommand
  \let\plmac@next=\plmac@end@environment
  \@ifnextchar*{\plmac@newenvironment@i}{\plmac@newenvironment@i!}%
}
\def\plmac@newenvironment@i#1#2{%
  \ifx#1*%
    \def\plmac@starchar{*}%
  \else
    \def\plmac@starchar{}%
  \fi
  \def\plmac@envname{#2}%
  \expandafter\def\expandafter\plmac@macname\expandafter{\csname#2\endcsname}%
  \expandafter\let\expandafter\plmac@oldbody\plmac@macname\relax
  \expandafter\def\expandafter\plmac@cleaned@macname\expandafter{%
    \expandafter\string\plmac@macname}%
  \@ifnextchar[{\plmac@newcommand@ii}{\plmac@newcommand@ii[0]}%]
}
\def\plmac@end@environment{%
  \expandafter\def\expandafter\plmac@next\expandafter{\expandafter
    \let\csname end\plmac@envname\endcsname=\plmac@end@macro
    \let\plmac@next=\relax
  }%
  \def\plmac@macname{\plmac@end@macro}%
  \expandafter\let\expandafter\plmac@oldbody\csname end\plmac@envname\endcsname
  \expandafter\def\expandafter\plmac@cleaned@macname\expandafter{%
    \expandafter\string\plmac@macname}%
  \@ifnextchar[{\plmac@newcommand@ii}{\plmac@newcommand@ii[0]}%]
}
\def\perldo{%
  \begingroup
    \let\do\@makeother\dospecials
    \catcode`\^^M=\active
    \newlinechar`\^^M
    \endlinechar=`\^^M
    \catcode`\{=1
    \catcode`\}=2
    \afterassignment\plmac@have@run@code
    \global\plmac@perlcode
}
\def\plmac@have@run@code{%
  \endgroup
  \edef\plmac@run@code{%
    \noexpand\plmac@write@perl{RUN\plmac@sep
      \plmac@tag\plmac@sep
      N/A\plmac@sep
      \plmac@tag\plmac@sep
      \the\plmac@perlcode
    }%
  }%
  \plmac@run@code
}
\newif\ifplmac@file@exists
\newcommand{\plmac@await@existence}[1]{%
  \begin{lrbox}{\@tempboxa}%
    \input\plmac@pipe
  \end{lrbox}%
  \loop
    \IfFileExists{#1}%
                 {\plmac@file@existstrue}%
                 {\plmac@file@existsfalse}%
    \ifplmac@file@exists
    \else
  \repeat
}
\newwrite\plmac@outfile
\newcommand{\plmac@write@perl}{%
  \begingroup
    \let\do\@makeother\dospecials
    \catcode`\^^M=\active
    \newlinechar`\^^M
    \endlinechar=`\^^M
    \catcode`\{=1
    \catcode`\}=2
    \plmac@write@perl@i
}
\ifperl
  \newcommand{\plmac@write@perl@i}[1]{%
      \immediate\openout\plmac@outfile=\plmac@tofile\relax
      \let\protect=\noexpand
      \def\begin{\noexpand\begin}%
      \def\end{\noexpand\end}%
      \immediate\write\plmac@outfile{#1}%
      \immediate\closeout\plmac@outfile
    \endgroup
    \immediate\openout\plmac@outfile=\plmac@toflag\relax
    \immediate\closeout\plmac@outfile
    \plmac@await@existence\plmac@fromflag
    \immediate\openout\plmac@outfile=\plmac@tofile\relax
    \immediate\closeout\plmac@outfile
    \plmac@await@existence\plmac@doneflag
    \input\plmac@fromfile\relax
  }
\else
  \newcommand{\plmac@write@perl@i}[1]{\endgroup}
  \gdef\plmac@show@placeholder#1#2\@empty{%
    \ifx#1D\relax
      \endgroup
    \else
      \endgroup
      \fbox{Perl\TeX}%
    \fi
  }%
  \AtBeginDocument{%
    \renewcommand{\plmac@write@perl@i}[1]{%
      \plmac@show@placeholder#1\@empty
    }%
  }
\fi
\endinput
%%
%% End of file `perltex.sty'.
