diff options
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r-- | Master/texmf-dist/doc/latex/perltex/README | 23 | ||||
-rw-r--r-- | Master/texmf-dist/doc/latex/perltex/perltex.pdf | bin | 300425 -> 336811 bytes | |||
-rw-r--r-- | Master/texmf-dist/source/latex/perltex/perltex.dtx | 329 | ||||
-rw-r--r-- | Master/texmf-dist/source/latex/perltex/perltex.ins | 16 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/perltex/perltex.sty | 39 | ||||
-rw-r--r-- | Master/texmf-dist/tpm/perltex.tpm | 8 |
6 files changed, 285 insertions, 130 deletions
diff --git a/Master/texmf-dist/doc/latex/perltex/README b/Master/texmf-dist/doc/latex/perltex/README index 6bccfbebe32..0e50e9ac6c7 100644 --- a/Master/texmf-dist/doc/latex/perltex/README +++ b/Master/texmf-dist/doc/latex/perltex/README @@ -1,9 +1,8 @@ - - +---------------------------------------------+ - | PERLTEX | - | Defining LaTeX macros in terms of Perl code | - | By Scott Pakin, scott+pt@pakin.org | - +---------------------------------------------+ + +------------------------------------+ + | PERLTEX | + | | + | By Scott Pakin, scott+pt@pakin.org | + +------------------------------------+ Description @@ -44,10 +43,14 @@ perltex.gls", then "latex perltex.dtx" again, then "dvips perltex.dvi License ======= -Copyright (C) 2004 by Scott Pakin +Copyright (C) 2006, Scott Pakin These files may be distributed and/or modified under the conditions of -the LaTeX Project Public License, either version 1.2 of this license or +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.2 or later is -part of all distributions of LaTeX version 1999/12/01 or later. +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. diff --git a/Master/texmf-dist/doc/latex/perltex/perltex.pdf b/Master/texmf-dist/doc/latex/perltex/perltex.pdf Binary files differindex f4fe25c5812..279321faad1 100644 --- a/Master/texmf-dist/doc/latex/perltex/perltex.pdf +++ b/Master/texmf-dist/doc/latex/perltex/perltex.pdf diff --git a/Master/texmf-dist/source/latex/perltex/perltex.dtx b/Master/texmf-dist/source/latex/perltex/perltex.dtx index 22176af68be..670009bbe87 100644 --- a/Master/texmf-dist/source/latex/perltex/perltex.dtx +++ b/Master/texmf-dist/source/latex/perltex/perltex.dtx @@ -1,17 +1,17 @@ % \iffalse meta-comment % -% Copyright (C) 2004 by Scott Pakin <scott+pt@pakin.org> -% ------------------------------------------------------ +% Copyright (C) 2006, 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.2 -% of this license or (at your option) any later version. -% The latest version of this license is in: +% 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.2 or later is part of all distributions of LaTeX -% version 1999/12/01 or later. +% and version 1.3c or later is part of all distributions of LaTeX +% version 2006/05/20 or later. % % \fi % @@ -22,7 +22,7 @@ %<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01] %<package>\ProvidesPackage{perltex} %<*package> - [2004/10/07 v1.2 LaTeX macros for use with PerlTeX] + [2006/06/24 v1.3 LaTeX macros for use with PerlTeX] %</package> % %<*driver> @@ -44,7 +44,7 @@ \hypersetup{% hyperindex=false, bookmarksopen, - pdftitle={PerlTeX: defining LaTeX macros in terms of Perl code}, + pdftitle={PerlTeX: Defining LaTeX macros in terms of Perl code}, pdfauthor={Scott Pakin, scott+pt@pakin.org}, pdfsubject={Using Perl to define LaTeX macros}, pdfkeywords={programming, LaTeX, macros, Perl} @@ -60,7 +60,7 @@ %</driver> % \fi % -% \CheckSum{468} +% \CheckSum{511} % % \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 @@ -86,21 +86,24 @@ % \GetFileInfo{perltex.sty} % % \DoNotIndex{\$, \', \(, \), \., \\, \{, \}, \^, \", \@} -% \DoNotIndex{\@ifnextchar, \@ifundefined, \@makeother} -% \DoNotIndex{\b, \begingroup, \btrapped} +% \DoNotIndex{\@empty, \@ifnextchar, \@ifundefined, \@makeother, \@ne} +% \DoNotIndex{\@permittedops} +% \DoNotIndex{\active, \advance} +% \DoNotIndex{\b, \begin, \begingroup, \btrapped} +% \DoNotIndex{\catcode, \csname} % \DoNotIndex{\d, \def} -% \DoNotIndex{\edef, \else, \endgroup, \expandafter} +% \DoNotIndex{\edef, \else, \end, \endcsname, \endgroup, \expandafter} % \DoNotIndex{\fi} % \DoNotIndex{\gdef, \global} % \DoNotIndex{\ifeof, \ifnum, \ifx, \immediate} -% \DoNotIndex{\let} +% \DoNotIndex{\let, \loop} % \DoNotIndex{\makeatletter, \makeatother, \MessageBreak} % \DoNotIndex{\n, \newcount, \newif, \newread, \newtoks, \newwrite} % \DoNotIndex{\noexpand, \number} % \DoNotIndex{\protect} -% \DoNotIndex{\r, \relax} +% \DoNotIndex{\r, \relax, \repeat} % \DoNotIndex{\s, \space, \string} -% \DoNotIndex{\the} +% \DoNotIndex{\TeX, \the} % \DoNotIndex{\W} % % \newcommand{\PerlTeX}{Perl\TeX{}} ^^A Name of the complete system @@ -111,6 +114,7 @@ % \makeatletter % \newenvironment{perlmacro}[1]{^^A % \begingroup +% \catcode`\_=11 % \def\PrintMacroName##1{\strut\MacroFont\string##1\ }^^A % \def\SpecialIndex@##1##2{^^A % \@bsphack @@ -125,7 +129,7 @@ % } % \makeatother % -% \title{\PerlTeX---defining \LaTeX{} macros in terms of Perl code^^A +% \title{\PerlTeX: \\ Defining \LaTeX{} macros in terms of Perl code^^A % \thanks{This document corresponds to \PerlTeX~\fileversion, dated % \filedate.}} % \author{Scott Pakin \\ \texttt{scott+pt@pakin.org}} @@ -328,29 +332,32 @@ % \DescribeMacro{\perlrenewcommand} % \DescribeMacro{\perlnewenvironment} % \DescribeMacro{\perlrenewenvironment} -% \perlmac{} defines four macros: |\perlnewcommand|, -% |\perlrenewcommand|, |\perlnewenvironment|, and -% |\perlrenewenvironment|. These behave exactly like their \LaTeXe{} -% counterparts---|\newcommand|, |\renewcommand|, |\newenvironment|, and -% |\renewenvironment|---except that the macro body consists of Perl code -% that dynamically generates \LaTeX{} code. \perlmac{} even includes -% support for optional arguments and the starred forms of its commands -% (i.e.~|\perlnewcommand*|, |\perlrenewcommand*|, |\perlnewenvironment*|, -% and |\perlrenewenvironment*|). -% -% When the Perl code is executed, it is placed within a subroutine named -% after the macro name but with ``|\|'' replaced with ``|latex_|''. For -% example, a \PerlTeX-defined \LaTeX{} macro called |\myMacro| produces -% a Perl subroutine called |latex_myMacro|. Macro arguments are -% converted to subroutine arguments. A \LaTeX{} macro's |#1| argument -% is referred to as |$_[0]| in Perl; |#2| is referred to as |$_[1]|; and -% so forth. +% \DescribeMacro{\perldo} +% \perlmac{} defines five macros: |\perlnewcommand|, +% |\perlrenewcommand|, |\perlnewenvironment|, |\perlrenewenvironment|, +% and |\perldo|. The first four of these behave exactly like their +% \LaTeXe{} counterparts---|\newcommand|, |\renewcommand|, +% |\newenvironment|, and |\renewenvironment|---except that the macro +% body consists of Perl code that dynamically generates \LaTeX{} code. +% \perlmac{} even includes support for optional arguments and the +% starred forms of its commands (i.e.~|\perlnewcommand*|, +% |\perlrenewcommand*|, |\perlnewenvironment*|, and +% |\perlrenewenvironment*|). |\perldo| immediately executes a block of +% Perl code without (re)defining any macros or environments. +% +% A \PerlTeX-defined macro or environments is converted to a Perl +% subroutine named after the macro/environment but beginning with +% ``|latex_|''. For example, a \PerlTeX-defined \LaTeX{} macro called +% |\myMacro| internally produces a Perl subroutine called +% |latex_myMacro|. Macro arguments are converted to subroutine +% arguments. A \LaTeX{} macro's |#1| argument is referred to as |$_[0]| +% in Perl; |#2| is referred to as |$_[1]|; and so forth. % % Any valid Perl code can be used in the body of a macro. However, % \PerlTeX{} executes the Perl code within a secure sandbox. This means % that potentially harmful Perl operations, such as |unlink|, |rmdir|, % and |system| will result in a run-time error. (It is possible to -% disable the safety checks, however, as will be explained in +% disable the safety checks, however, as is explained in % Section~\ref{sec:perltex-man}.) Having a secure sandbox implies that % it is safe to build \PerlTeX{} documents written by other people % without worrying about what they may do to your computer system. @@ -368,9 +375,13 @@ % |\setX{123}| \\ % |\getX| \\ % |\setX{456}| \\ +% |\getX| \\ +% |\perldo{$x = 789}| \\ % |\getX| \\[1ex] % \multicolumn{1}{@{}c@{}}{\Huge$\Downarrow$} \\[2ex] -% \multicolumn{1}{@{}c@{}}{$x$ was set to 123. $x$ was set to 456.} \\ +% \multicolumn{1}{@{}c@{}}{^^A +% $x$ was set to 123. $x$ was set to 456. $x$ was set to 789.^^A +% } \\ % \end{tabular} % % \bigskip @@ -407,6 +418,7 @@ % command is the recommended way to produce a Unix man page from % \perltex: % +% \enlargethispage{4ex} % \begin{verbatim} % pod2man --center=" " --release=" " perltex.pl > perltex.1 % \end{verbatim} @@ -610,19 +622,17 @@ % \section{License agreement} % \label{sec:license} % -% \begin{center} -% Copyright \textcopyright{} 2004 by Scott Pakin \texttt{<scott+pt@pakin.org>} -% \end{center} +% Copyright \textcopyright{} 2006, Scott Pakin \texttt{<scott+pt@pakin.org>} % % \providecommand{\url}[1]{\texttt{##1}} % % \noindent % These files may be distributed and/or modified under the conditions of -% the \LaTeX{} Project Public License, either version~1.2 of this +% 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 \url{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. +% version~1.3c or later is part of all distributions of \LaTeX{} version +% 2006/05/20 or later. % % \PrintChanges % \PrintIndex @@ -786,14 +796,16 @@ % \subsubsection{Defining Perl macros} % \label{sec:perl-mac} % -% \PerlTeX{} defines four macros intended to be called by the user. +% \PerlTeX{} defines five macros intended to be called by the author. % Section~\ref{sec:perl-mac} details the implementation of two of them: % |\perlnewcommand| and |\perlrenewcommand|. -% (Section~\ref{sec:perl-env} details the implementation of the other -% two, |\perlnewenvironment| and |\perlrenewenvironment|.) The goal is -% for these two macros to behave \emph{exactly} like |\newcommand| and -% |\renewcommand|, respectively, except that the author macros they in -% turn define have Perl bodies instead of \LaTeX{} bodies. +% (Section~\ref{sec:perl-env} details the implementation of the next +% two, |\perlnewenvironment| and |\perlrenewenvironment|; and, +% Section~\ref{sec:perl-run} details the implementation of the final +% macro, |\perldo|.) The goal is for these two macros to behave +% \emph{exactly} like |\newcommand| and |\renewcommand|, respectively, +% except that the author macros they in turn define have Perl bodies +% instead of \LaTeX{} bodies. % % The sequence of the operations defined in this section is as follows: % @@ -1168,16 +1180,16 @@ % will then contain |#1|, |#2|,~\dots, |#\plmac@numargs|, as desired. % \begin{macrocode} \let\plmac@hash=\relax - \plmac@argnum=1% + \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 1% + \advance\plmac@argnum by \@ne \repeat - \let\plmac@hash=##\relax + \let\plmac@hash=##% % \end{macrocode} % % \begin{macro}{\plmac@define@command} @@ -1241,12 +1253,12 @@ % % Section~\ref{sec:perl-mac} detailed the implementation of % |\perlnewcommand| and |\perlrenewcommand|. Section~\ref{sec:perl-env} -% does likewise for \PerlTeX's remaining two macros, -% |\perlnewenvironment| and |\perlrenewenvironment|, which are the -% Perl-bodied analogues of |\newenvironment| and |\renewenvironment|. -% This section is significantly shorter than the previous because -% |\perlnewenvironment| and |\perlrenewenvironment| are largely built -% atop the macros already defined in Section~\ref{sec:perl-mac}. +% does likewise for |\perlnewenvironment| and |\perlrenewenvironment|, +% which are the Perl-bodied analogues of |\newenvironment| and +% |\renewenvironment|. This section is significantly shorter than the +% previous because |\perlnewenvironment| and |\perlrenewenvironment| are +% largely built atop the macros already defined in +% Section~\ref{sec:perl-mac}. % % \begin{macro}{\perlnewenvironment} % \begin{macro}{\perlrenewenvironment} @@ -1367,6 +1379,83 @@ % \end{macro} % % +% \subsubsection{Executing top-level Perl code} +% \label{sec:perl-run} +% +% The macros defined in Sections~\ref{sec:perl-mac} +% and~\ref{sec:perl-env} enable an author to inject subroutines into the +% Perl sandbox. The final \PerlTeX\ macro, |\perldo|, instructs the +% Perl sandbox to execute a block of code outside of all subroutines. +% |\perldo|'s implementation is much simpler than that of the other +% author macros because |\perldo| does not have to process subroutine +% arguments. Figure~\ref{fig:tofile-run} illustrates the data that gets +% written to |plmac@tofile| (indirectly) by |\perldo|. +% +% \begin{figure}[htbp] +% \centering +% \DeleteShortVerb\| +% \begin{tabular}{|l|} +% \hline +% \verb|RUN| \\ \hline +% \verb|\plmac@tag| \\ \hline +% \textit{Ignored} \\ \hline +% \verb|\plmac@tag| \\ \hline +% \verb|\plmac@perlcode| \\ \hline +% \end{tabular} +% \MakeShortVerb\| +% \caption{Data written to \texttt{\string\plmac@tofile} to execute +% Perl code} +% \label{fig:tofile-run} +% \end{figure} +% +% +% \begin{macro}{\perldo} +% Execute a block of Perl code and pass the result to \LaTeX\ for +% further processing. This code is nearly identical to that of +% Section~\ref{sec:perl-mac}'s |\plmac@haveargs| but ends by invoking +% |\plmac@have@run@code| instead of |\plmac@havecode|. +% \changes{v1.3}{2006/06/23}{Introduced \texttt{\string\string\string\perldo} +% to support code execution outside of all subroutines.} +% \begin{macrocode} +\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 +} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\plmac@have@run@code} +% \begin{macro}{\plmac@run@code} +% Pass a block of code to Perl to execute. |\plmac@have@run@code| is +% identical to |\plmac@havecode| but specifies the |RUN| tag instead of +% the |DEF| tag. +% \changes{v1.3}{2006/06/23}{Added to assist +% \texttt{\string\string\string\perldo}} +% \begin{macrocode} +\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 +} +% \end{macrocode} +% \end{macro} +% \end{macro} +% +% % \subsubsection{Communication between \LaTeX{} and Perl} % % As shown in the previous section, when a document invokes @@ -1673,21 +1762,41 @@ # # This is a generated file. # -# Copyright (C) 2004 by Scott Pakin <scott+pt@pakin.org> +# Copyright (C) 2006, 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.2 of this +# 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.2 or later is part of all distributions of LaTeX -# version 1999/12/01 or later. +# and version 1.3c or later is part of all distributions of LaTeX +# version 2006/05/20 or later. #------------------------------------------------------------------- % \end{macrocode} % +% \subsubsection{Top-level code evaluation} +% +% In previous versions of \perltex, the |--nosafe| option created and +% ran code within a sandbox in which all operations are allowed (via +% |Opcode::full_opset()|). Unfortunately, certain operations still fail +% to work within such a sandbox. We therefore define a top-level +% ``non-sandbox'', |top_level_eval()|, in which to execute code. +% |top_level_eval()| merely calls |eval()| on its argument. However, it +% needs to be declared top-level and before anything else because +% |eval()| runs in the lexical scope of its caller. +% \changes{v1.3}{2006/06/24}{Modified \perltex\ to eschew the sandbox +% altogether when \texttt{--nosafe} is specified} +% +% \begin{macrocode} +sub top_level_eval ($) +{ + return eval $_[0]; +} +% \end{macrocode} +% % \subsubsection{Perl modules and pragmas} % % We use |Safe| and |Opcode| to implement the secure sandbox, @@ -1742,21 +1851,24 @@ my @permittedops; % \begin{perlmacro}{$doneflag} % \begin{perlmacro}{$logfile} % \begin{perlmacro}{$sandbox} +% \begin{perlmacro}{$sandbox_eval} % \begin{perlmacro}{$latexpid} -% |$progname| is the run-time name of the \perltex{} program. -% |$jobname| is the base name of the user's |.tex| file, which defaults -% to the \TeX{} default of |texput|. |@latexcmdline| is the command -% line to pass to the \LaTeX{} executable. |$toperl| defines the -% filename used for \LaTeX{}$\rightarrow$Perl communication. -% |$fromperl| defines the filename used for Perl$\rightarrow$\LaTeX{} -% communication. |$toflag| is the name of a file that will exist only -% after \LaTeX{} creates |$tofile|. |$fromflag| is the name of a file -% that will exist only after Perl creates |$fromfile|. |$doneflag| is -% the name of a file that will exist only after Perl deletes -% |$fromflag|. |$logfile| is the name of a log file to which \perltex{} -% writes verbose execution information. |$sandbox| is a secure sandbox -% in which to run code that appeared in the \LaTeX{} document. -% |$latexpid| is the process~ID of the |latex| process. +% |$progname| is the run-time name of the \perltex{} program. |$jobname| +% is the base name of the user's |.tex| file, which defaults to the +% \TeX{} default of |texput|. |@latexcmdline| is the command line to +% pass to the \LaTeX{} executable. |$toperl| defines the filename used +% for \LaTeX{}$\rightarrow$Perl communication. |$fromperl| defines the +% filename used for Perl$\rightarrow$\LaTeX{} communication. |$toflag| +% is the name of a file that will exist only after \LaTeX{} creates +% |$tofile|. |$fromflag| is the name of a file that will exist only +% after Perl creates |$fromfile|. |$doneflag| is the name of a file +% that will exist only after Perl deletes |$fromflag|. |$logfile| is the +% name of a log file to which \perltex{} writes verbose execution +% information. |$sandbox| is a secure sandbox in which to run code that +% appeared in the \LaTeX{} document. |$sandbox_eval| is a subroutine +% that evalutes a string within |$sandbox| (normally) or outside of all +% sandboxes (if |--nosafe| is specified). |$latexpid| is the process~ID +% of the |latex| process. % \begin{macrocode} my $progname = basename $0; my $jobname = "texput"; @@ -1768,6 +1880,7 @@ my $fromflag; my $doneflag; my $logfile; my $sandbox = new Safe; +my $sandbox_eval; my $latexpid; % \end{macrocode} % \end{perlmacro} @@ -1781,6 +1894,7 @@ my $latexpid; % \end{perlmacro} % \end{perlmacro} % \end{perlmacro} +% \end{perlmacro} % % \subsubsection{Command-line conversion} % @@ -1905,11 +2019,18 @@ if (!$latexpid) { % permits only operations that are deemed safe. For example, the Perl % code is allowed by default to assign variables, call functions, and % execute loops. However, it is not normally allowed to delete files, -% kill processes, or invoke other programs. +% kill processes, or invoke other programs. If \perltex\ is run with +% the |--nosafe| option we bypass the sandbox entirely and execute Perl +% code using an ordinary |eval()| statement. % \begin{macrocode} -@permittedops=(":browse") if $#permittedops==-1; -@permittedops=(Opcode::full_opset()) if !$runsafely; -$sandbox->permit_only (@permittedops); +if ($runsafely) { + @permittedops=(":browse") if $#permittedops==-1; + $sandbox->permit_only (@permittedops); + $sandbox_eval = sub {$sandbox->reval($_[0])}; +} +else { + $sandbox_eval = \&top_level_eval; +} % \end{macrocode} % % \subsubsection{Communicating with \LaTeX{}} @@ -1971,10 +2092,11 @@ while (1) { % \begin{perlmacro}{$macroname} % \begin{perlmacro}{@otherstuff} % We split the contents of |$entirefile| into an operation tag (either -% |DEF| or |USE|), the macro name, and everything else (|@otherstuff|). -% If |$optag| is |DEF| then |@otherstuff| will contain the Perl code to -% define. If |$optag| is |USE| then |@otherstuff| will be a list of -% subroutine arguments. +% |DEF|, |USE|, or |RUN|), the macro name, and everything else +% (|@otherstuff|). If |$optag| is |DEF| then |@otherstuff| will contain +% the Perl code to define. If |$optag| is |USE| then |@otherstuff| will +% be a list of subroutine arguments. If |$optag| is |RUN| then +% |@otherstuff| will be a block of Perl code to run. % \begin{macrocode} my ($optag, $macroname, @otherstuff) = map {chomp; $_} split "$separator\n", $entirefile; @@ -2007,16 +2129,17 @@ while (1) { % \end{macrocode} % % \begin{perlmacro}{$perlcode} -% There are two possible values that can be assigned to |$perlcode|. If -% |$optag| is |DEF|, then |$perlcode| is made to contain a definition of -% the user's subroutine, named |$macroname|. If |$optag| is |USE|, then -% |$perlcode| becomes an invocation of |$macroname| which gets passed -% all of the macro arguments. Figure~\ref{fig:latex-perl-define} +% There are three possible values that can be assigned to |$perlcode|. +% If |$optag| is |DEF|, then |$perlcode| is made to contain a definition +% of the user's subroutine, named |$macroname|. If |$optag| is |USE|, +% then |$perlcode| becomes an invocation of |$macroname| which gets +% passed all of the macro arguments. Finally, if |$optag| is |RUN|, +% then |$perlcode| is the unmodified Perl code passed to us from +% \perlmac. Figure~\ref{fig:latex-perl-define} presents an example +% of how the following code converts a \PerlTeX{} macro definition into +% a Perl subroutine definition and Figure~\ref{fig:latex-perl-use} % presents an example of how the following code converts a \PerlTeX{} -% macro definition into a Perl subroutine definition and -% Figure~\ref{fig:latex-perl-use} presents an example of how the -% following code converts a \PerlTeX{} macro invocation into a Perl -% subroutine invocation. +% macro invocation into a Perl subroutine invocation. % % \begin{figure}[tbp] % \centering @@ -2065,12 +2188,18 @@ while (1) { % \begin{macrocode} my $perlcode; if ($optag eq "DEF") { - $perlcode = - sprintf "sub %s {%s}\n", - $macroname, $otherstuff[0]; + $perlcode = + sprintf "sub %s {%s}\n", + $macroname, $otherstuff[0]; + } + elsif ($optag eq "USE") { + $perlcode = sprintf "%s (%s);\n", $macroname, join(", ", @otherstuff); + } + elsif ($optag eq "RUN") { + $perlcode = $otherstuff[0]; } else { - $perlcode = sprintf "%s (%s);\n", $macroname, join(", ", @otherstuff); + die "${progname}: Internal error -- unexpected operation tag \"$optag\"\n"; } % \end{macrocode} % \end{perlmacro} @@ -2083,7 +2212,7 @@ while (1) { % % \begin{perlmacro}{$result} % \begin{perlmacro}{$msg} -% We're now ready to execute the user's code using the |$sandbox->reval| +% We're now ready to execute the user's code using the |$sandbox_eval| % function. If a warning occurs we write it as a Perl comment to the % log file. If an error occurs (i.e.,~|$@| is defined) we replace the % result (|$result|) with a call to \LaTeXe's |\PackageError| macro to @@ -2101,13 +2230,13 @@ while (1) { my $warningmsg; local $SIG{__WARN__} = sub {chomp ($warningmsg=$_[0]); return 0}; - $result = $sandbox->reval ($perlcode); + $result = $sandbox_eval->($perlcode); if (defined $warningmsg) { $warningmsg =~ s/at \(eval \d+\) line \d+\W+//; print LOGFILE "# ===> $warningmsg\n\n"; } } - $result="" if !$result; + $result="" if !$result || $optag eq "RUN"; if ($@) { my $msg = $@; $msg =~ s/at \(eval \d+\) line \d+\W+//; diff --git a/Master/texmf-dist/source/latex/perltex/perltex.ins b/Master/texmf-dist/source/latex/perltex/perltex.ins index 064df9284dc..5ad134d8091 100644 --- a/Master/texmf-dist/source/latex/perltex/perltex.ins +++ b/Master/texmf-dist/source/latex/perltex/perltex.ins @@ -1,15 +1,15 @@ %% -%% Copyright (C) 2004 by Scott Pakin <scott+pt@pakin.org> +%% Copyright (C) 2006, 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.2 of this license +%% 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.2 or later is part of all distributions of LaTeX version -%% 1999/12/01 or later. +%% and version 1.3c or later is part of all distributions of LaTeX version +%% 2006/05/20 or later. %% \input docstrip.tex @@ -21,17 +21,17 @@ This is a generated file. -Copyright (C) 2004 by Scott Pakin <scott+pt@pakin.org> +Copyright (C) 2006, 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.2 of this license +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.2 or later is part of all distributions of LaTeX version -1999/12/01 or later. +and version 1.3c or later is part of all distributions of LaTeX version +2006/05/20 or later. \endpreamble diff --git a/Master/texmf-dist/tex/latex/perltex/perltex.sty b/Master/texmf-dist/tex/latex/perltex/perltex.sty index ab61d0c9f94..d3f185b88a5 100644 --- a/Master/texmf-dist/tex/latex/perltex/perltex.sty +++ b/Master/texmf-dist/tex/latex/perltex/perltex.sty @@ -8,21 +8,21 @@ %% %% This is a generated file. %% -%% Copyright (C) 2004 by Scott Pakin <scott+pt@pakin.org> +%% Copyright (C) 2006, 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.2 of this license +%% 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.2 or later is part of all distributions of LaTeX version -%% 1999/12/01 or later. +%% 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} - [2004/10/07 v1.2 LaTeX macros for use with PerlTeX] + [2006/06/24 v1.3 LaTeX macros for use with PerlTeX] \newif\ifplmac@have@perltex \plmac@have@perltextrue \@ifundefined{plmac@tag}{\plmac@have@perltexfalse}{} @@ -106,16 +106,16 @@ \plmac@cleaned@macname }% \let\plmac@hash=\relax - \plmac@argnum=1% + \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 1% + \advance\plmac@argnum by \@ne \repeat - \let\plmac@hash=##\relax + \let\plmac@hash=##% \expandafter\let\plmac@macname=\relax \ifx\plmac@defarg\relax \edef\plmac@define@command{% @@ -170,6 +170,29 @@ \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]{% \loop diff --git a/Master/texmf-dist/tpm/perltex.tpm b/Master/texmf-dist/tpm/perltex.tpm index 6c29bc706fb..2343e2c4e78 100644 --- a/Master/texmf-dist/tpm/perltex.tpm +++ b/Master/texmf-dist/tpm/perltex.tpm @@ -3,7 +3,7 @@ <rdf:Description about="http://texlive.dante.de/texlive/Package/perltex.zip"> <TPM:Name>perltex</TPM:Name> <TPM:Type>Package</TPM:Type> - <TPM:Date>2006/01/11 23:56:06</TPM:Date> + <TPM:Date>2006/06/26 16:22:00</TPM:Date> <TPM:Version>1.2 2004/10/07</TPM:Version> <TPM:Creator>rahtz</TPM:Creator> <TPM:Title>Define LaTeX macros in terms of Perl code</TPM:Title> @@ -20,15 +20,15 @@ programmability. <TPM:Author>Scott Pakin</TPM:Author> <TPM:Size>405915</TPM:Size> <TPM:Build/> - <TPM:RunFiles size="8282"> + <TPM:RunFiles size="8761"> texmf-dist/tex/latex/perltex/perltex.sty texmf-dist/tpm/perltex.tpm </TPM:RunFiles> - <TPM:DocFiles size="302645"> + <TPM:DocFiles size="339083"> texmf-dist/doc/latex/perltex/README texmf-dist/doc/latex/perltex/perltex.pdf </TPM:DocFiles> - <TPM:SourceFiles size="94988"> + <TPM:SourceFiles size="99546"> texmf-dist/source/latex/perltex/perltex.dtx texmf-dist/source/latex/perltex/perltex.ins </TPM:SourceFiles> |