2 %% This is file `perltex.sty',
3 %% generated with the docstrip utility.
5 %% The original source files were:
7 %% perltex.dtx (with options: `package')
9 %% This is a generated file.
11 %% Copyright (C) 2010 Scott Pakin <scott+pt@pakin.org>
13 %% This file may be distributed and/or modified under the conditions of
14 %% the LaTeX Project Public License, either version 1.3c of this license
15 %% or (at your option) any later version. The latest version of this
18 %% http://www.latex-project.org/lppl.txt
20 %% and version 1.3c or later is part of all distributions of LaTeX version
21 %% 2006/05/20 or later.
23 \NeedsTeXFormat{LaTeX2e}[1999/12/01]
24 \ProvidesPackage{perltex}
25 [2010/07/10 v2.1 LaTeX macros for use with PerlTeX]
26 \newif\ifplmac@required \plmac@requiredtrue
27 \DeclareOption{optional}{\plmac@requiredfalse} \ProcessOptions\relax
30 \@ifundefined{plmac@tag}{\perlfalse}{}
31 \@ifundefined{plmac@tofile}{\perlfalse}{}
32 \@ifundefined{plmac@fromfile}{\perlfalse}{}
33 \@ifundefined{plmac@toflag}{\perlfalse}{}
34 \@ifundefined{plmac@fromflag}{\perlfalse}{}
35 \@ifundefined{plmac@doneflag}{\perlfalse}{}
36 \@ifundefined{plmac@pipe}{\perlfalse}{}
40 \PackageError{perltex}{Document must be compiled using perltex}
41 {Instead of compiling your document directly with latex, you need
42 to\MessageBreak use the perltex script. \space perltex sets up
43 a variety of macros needed by\MessageBreak the perltex
44 package as well as a listener process needed for\MessageBreak
45 communication between LaTeX and Perl.}
49 \typeout{perltex: Document was compiled without using the perltex script;}
50 \typeout{ it may not print as desired.}
55 \let\plmac@command=\newcommand
56 \let\plmac@next=\relax
57 \@ifnextchar*{\plmac@newcommand@i}{\plmac@newcommand@i!}%
59 \def\perlrenewcommand{%
60 \let\plmac@next=\relax
61 \let\plmac@command=\renewcommand
62 \@ifnextchar*{\plmac@newcommand@i}{\plmac@newcommand@i!}%
64 \def\plmac@newcommand@i#1#2{%
66 \def\plmac@starchar{*}%
68 \def\plmac@starchar{}%
70 \def\plmac@macname{#2}%
71 \let\plmac@oldbody=#2\relax
72 \expandafter\def\expandafter\plmac@cleaned@macname\expandafter{%
73 \expandafter\string\plmac@macname}%
74 \@ifnextchar[{\plmac@newcommand@ii}{\plmac@newcommand@ii[0]}%]
76 \def\plmac@newcommand@ii[#1]{%
77 \def\plmac@numargs{#1}%
78 \@ifnextchar[{\plmac@newcommand@iii@opt}
79 {\plmac@newcommand@iii@no@opt}%]
81 \def\plmac@newcommand@iii@opt[#1]{%
82 \def\plmac@defarg{#1}%
85 \def\plmac@newcommand@iii@no@opt{%
86 \let\plmac@defarg=\relax
89 \newtoks\plmac@perlcode
92 \let\do\@makeother\dospecials
98 \afterassignment\plmac@havecode
99 \global\plmac@perlcode
101 {\catcode`\^^M=11\gdef\plmac@sep{^^M}}
102 \newcount\plmac@argnum
103 \def\plmac@havecode{%
105 \edef\plmac@define@sub{%
106 \noexpand\plmac@write@perl{DEF\plmac@sep
108 \plmac@cleaned@macname\plmac@sep
117 \plmac@cleaned@macname
119 \let\plmac@hash=\relax
122 \ifnum\plmac@numargs<\plmac@argnum
125 \plmac@body\plmac@sep\plmac@tag\plmac@sep
126 \plmac@hash\plmac@hash\number\plmac@argnum}%
127 \advance\plmac@argnum by \@ne
130 \expandafter\let\plmac@macname=\relax
131 \ifx\plmac@defarg\relax
132 \edef\plmac@define@command{%
133 \noexpand\plmac@command\plmac@starchar{\plmac@macname}%
135 \noexpand\plmac@write@perl{\plmac@body}%
139 \edef\plmac@define@command{%
140 \noexpand\plmac@command\plmac@starchar{\plmac@macname}%
141 [\plmac@numargs][\plmac@defarg]{%
142 \noexpand\plmac@write@perl{\plmac@body}%
146 \expandafter\let\plmac@macname=\plmac@oldbody
147 \plmac@define@command
150 \def\perlnewenvironment{%
151 \let\plmac@command=\newcommand
152 \let\plmac@next=\plmac@end@environment
153 \@ifnextchar*{\plmac@newenvironment@i}{\plmac@newenvironment@i!}%
155 \def\perlrenewenvironment{%
156 \let\plmac@command=\renewcommand
157 \let\plmac@next=\plmac@end@environment
158 \@ifnextchar*{\plmac@newenvironment@i}{\plmac@newenvironment@i!}%
160 \def\plmac@newenvironment@i#1#2{%
162 \def\plmac@starchar{*}%
164 \def\plmac@starchar{}%
166 \def\plmac@envname{#2}%
167 \expandafter\def\expandafter\plmac@macname\expandafter{\csname#2\endcsname}%
168 \expandafter\let\expandafter\plmac@oldbody\plmac@macname\relax
169 \expandafter\def\expandafter\plmac@cleaned@macname\expandafter{%
170 \expandafter\string\plmac@macname}%
171 \@ifnextchar[{\plmac@newcommand@ii}{\plmac@newcommand@ii[0]}%]
173 \def\plmac@end@environment{%
174 \expandafter\def\expandafter\plmac@next\expandafter{\expandafter
175 \let\csname end\plmac@envname\endcsname=\plmac@end@macro
176 \let\plmac@next=\relax
178 \def\plmac@macname{\plmac@end@macro}%
179 \expandafter\let\expandafter\plmac@oldbody\csname end\plmac@envname\endcsname
180 \expandafter\def\expandafter\plmac@cleaned@macname\expandafter{%
181 \expandafter\string\plmac@macname}%
182 \@ifnextchar[{\plmac@newcommand@ii}{\plmac@newcommand@ii[0]}%]
186 \let\do\@makeother\dospecials
187 \catcode`\^^M=\active
192 \afterassignment\plmac@have@run@code
193 \global\plmac@perlcode
195 \def\plmac@have@run@code{%
197 \edef\plmac@run@code{%
198 \noexpand\plmac@write@perl{RUN\plmac@sep
207 \newif\ifplmac@file@exists
208 \newcommand{\plmac@await@existence}[1]{%
209 \begin{lrbox}{\@tempboxa}%
214 {\plmac@file@existstrue}%
215 {\plmac@file@existsfalse}%
220 \newwrite\plmac@outfile
221 \newcommand{\plmac@write@perl}{%
223 \let\do\@makeother\dospecials
224 \catcode`\^^M=\active
232 \newcommand{\plmac@write@perl@i}[1]{%
233 \immediate\openout\plmac@outfile=\plmac@tofile\relax
234 \let\protect=\noexpand
235 \def\begin{\noexpand\begin}%
236 \def\end{\noexpand\end}%
237 \immediate\write\plmac@outfile{#1}%
238 \immediate\closeout\plmac@outfile
240 \immediate\openout\plmac@outfile=\plmac@toflag\relax
241 \immediate\closeout\plmac@outfile
242 \plmac@await@existence\plmac@fromflag
243 \immediate\openout\plmac@outfile=\plmac@tofile\relax
244 \immediate\closeout\plmac@outfile
245 \plmac@await@existence\plmac@doneflag
246 \input\plmac@fromfile\relax
249 \newcommand{\plmac@write@perl@i}[1]{\endgroup}
250 \gdef\plmac@show@placeholder#1#2\@empty{%
259 \renewcommand{\plmac@write@perl@i}[1]{%
260 \plmac@show@placeholder#1\@empty
266 %% End of file `perltex.sty'.