isa: made a command with perltex for fancy ISA
[calu.git] / isasty / perltex.sty
1 %%
2 %% This is file `perltex.sty',
3 %% generated with the docstrip utility.
4 %%
5 %% The original source files were:
6 %%
7 %% perltex.dtx  (with options: `package')
8 %% 
9 %% This is a generated file.
10 %% 
11 %% Copyright (C) 2010 Scott Pakin <scott+pt@pakin.org>
12 %% 
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
16 %% license is in:
17 %% 
18 %%    http://www.latex-project.org/lppl.txt
19 %% 
20 %% and version 1.3c or later is part of all distributions of LaTeX version
21 %% 2006/05/20 or later.
22 %% 
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
28 \newif\ifperl
29 \perltrue
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}{}
37 \ifperl
38 \else
39   \ifplmac@required
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.}
46     \else
47       \bgroup
48         \obeyspaces
49         \typeout{perltex: Document was compiled without using the perltex script;}
50         \typeout{         it may not print as desired.}
51       \egroup
52   \fi
53 \fi
54 \def\perlnewcommand{%
55   \let\plmac@command=\newcommand
56   \let\plmac@next=\relax
57   \@ifnextchar*{\plmac@newcommand@i}{\plmac@newcommand@i!}%
58 }
59 \def\perlrenewcommand{%
60   \let\plmac@next=\relax
61   \let\plmac@command=\renewcommand
62   \@ifnextchar*{\plmac@newcommand@i}{\plmac@newcommand@i!}%
63 }
64 \def\plmac@newcommand@i#1#2{%
65   \ifx#1*%
66     \def\plmac@starchar{*}%
67   \else
68     \def\plmac@starchar{}%
69   \fi
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]}%]
75 }
76 \def\plmac@newcommand@ii[#1]{%
77   \def\plmac@numargs{#1}%
78   \@ifnextchar[{\plmac@newcommand@iii@opt}
79                {\plmac@newcommand@iii@no@opt}%]
80 }
81 \def\plmac@newcommand@iii@opt[#1]{%
82   \def\plmac@defarg{#1}%
83   \plmac@haveargs
84 }
85 \def\plmac@newcommand@iii@no@opt{%
86   \let\plmac@defarg=\relax
87   \plmac@haveargs
88 }
89 \newtoks\plmac@perlcode
90 \def\plmac@haveargs{%
91   \begingroup
92     \let\do\@makeother\dospecials
93     \catcode`\^^M=\active
94     \newlinechar`\^^M
95     \endlinechar=`\^^M
96     \catcode`\{=1
97     \catcode`\}=2
98     \afterassignment\plmac@havecode
99     \global\plmac@perlcode
100 }
101 {\catcode`\^^M=11\gdef\plmac@sep{^^M}}
102 \newcount\plmac@argnum
103 \def\plmac@havecode{%
104   \endgroup
105   \edef\plmac@define@sub{%
106     \noexpand\plmac@write@perl{DEF\plmac@sep
107       \plmac@tag\plmac@sep
108       \plmac@cleaned@macname\plmac@sep
109       \plmac@tag\plmac@sep
110       \the\plmac@perlcode
111     }%
112   }%
113   \plmac@define@sub
114   \edef\plmac@body{%
115     USE\plmac@sep
116     \plmac@tag\plmac@sep
117     \plmac@cleaned@macname
118   }%
119   \let\plmac@hash=\relax
120   \plmac@argnum=\@ne
121   \loop
122     \ifnum\plmac@numargs<\plmac@argnum
123     \else
124       \edef\plmac@body{%
125         \plmac@body\plmac@sep\plmac@tag\plmac@sep
126         \plmac@hash\plmac@hash\number\plmac@argnum}%
127       \advance\plmac@argnum by \@ne
128   \repeat
129   \let\plmac@hash=##%
130   \expandafter\let\plmac@macname=\relax
131   \ifx\plmac@defarg\relax
132     \edef\plmac@define@command{%
133       \noexpand\plmac@command\plmac@starchar{\plmac@macname}%
134       [\plmac@numargs]{%
135         \noexpand\plmac@write@perl{\plmac@body}%
136       }%
137   }%
138   \else
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}%
143       }%
144   }%
145   \fi
146   \expandafter\let\plmac@macname=\plmac@oldbody
147   \plmac@define@command
148   \plmac@next
149 }
150 \def\perlnewenvironment{%
151   \let\plmac@command=\newcommand
152   \let\plmac@next=\plmac@end@environment
153   \@ifnextchar*{\plmac@newenvironment@i}{\plmac@newenvironment@i!}%
154 }
155 \def\perlrenewenvironment{%
156   \let\plmac@command=\renewcommand
157   \let\plmac@next=\plmac@end@environment
158   \@ifnextchar*{\plmac@newenvironment@i}{\plmac@newenvironment@i!}%
159 }
160 \def\plmac@newenvironment@i#1#2{%
161   \ifx#1*%
162     \def\plmac@starchar{*}%
163   \else
164     \def\plmac@starchar{}%
165   \fi
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]}%]
172 }
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
177   }%
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]}%]
183 }
184 \def\perldo{%
185   \begingroup
186     \let\do\@makeother\dospecials
187     \catcode`\^^M=\active
188     \newlinechar`\^^M
189     \endlinechar=`\^^M
190     \catcode`\{=1
191     \catcode`\}=2
192     \afterassignment\plmac@have@run@code
193     \global\plmac@perlcode
194 }
195 \def\plmac@have@run@code{%
196   \endgroup
197   \edef\plmac@run@code{%
198     \noexpand\plmac@write@perl{RUN\plmac@sep
199       \plmac@tag\plmac@sep
200       N/A\plmac@sep
201       \plmac@tag\plmac@sep
202       \the\plmac@perlcode
203     }%
204   }%
205   \plmac@run@code
206 }
207 \newif\ifplmac@file@exists
208 \newcommand{\plmac@await@existence}[1]{%
209   \begin{lrbox}{\@tempboxa}%
210     \input\plmac@pipe
211   \end{lrbox}%
212   \loop
213     \IfFileExists{#1}%
214                  {\plmac@file@existstrue}%
215                  {\plmac@file@existsfalse}%
216     \ifplmac@file@exists
217     \else
218   \repeat
219 }
220 \newwrite\plmac@outfile
221 \newcommand{\plmac@write@perl}{%
222   \begingroup
223     \let\do\@makeother\dospecials
224     \catcode`\^^M=\active
225     \newlinechar`\^^M
226     \endlinechar=`\^^M
227     \catcode`\{=1
228     \catcode`\}=2
229     \plmac@write@perl@i
230 }
231 \ifperl
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
239     \endgroup
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
247   }
248 \else
249   \newcommand{\plmac@write@perl@i}[1]{\endgroup}
250   \gdef\plmac@show@placeholder#1#2\@empty{%
251     \ifx#1D\relax
252       \endgroup
253     \else
254       \endgroup
255       \fbox{Perl\TeX}%
256     \fi
257   }%
258   \AtBeginDocument{%
259     \renewcommand{\plmac@write@perl@i}[1]{%
260       \plmac@show@placeholder#1\@empty
261     }%
262   }
263 \fi
264 \endinput
265 %%
266 %% End of file `perltex.sty'.