-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpll
executable file
·300 lines (217 loc) · 7.46 KB
/
mpll
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#!/usr/bin/perl
# -*- encoding: utf-8; indent-tabs-mode: nil -*-
#
# mpll: program which merges the functionalities of perltex and lualatex
#
# Copyright (C) 2012 Jean Forget
#
# This program is free software; you can redistribute it and/or modify
# it under the same terms as Perl: either the Artistic License,
# or the GNU General Public License as published by
# the Free Software Foundation; either version 1, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License and
# the Artistic License along with this program; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307, USA.
use v5.10;
use strict;
use warnings;
my @args_p;
my @args_l;
my $dry_run;
my $job1; # explicit jobname option
my $job2; # implicit from filename.tex parameter
my $pgm1; # explicit program option
my $pgm2; # default lualatex program
$pgm2 = $ENV{PERLTEX} // 'lualatex';
while (my $arg = shift @ARGV) {
given ($arg) {
# exclusive options
when ('--help') {
exec('perldoc', $0);
}
when ('--version') {
print <<'EOF';
This is mpll version 0.1
No version given for perltex
EOF
exec(qw/lualatex --version/);
}
when ('--credits') {
print <<'EOF';
mpll by Jean Forget
perltex by Scott Pakin
Credits for lualatex:
EOF
exec(qw/lualatex --credits/);
}
when (/--dry-run/) {
$dry_run = 1;
}
# perltex options
when (/--(?:nosafe|safe|makesty|permit=.+)$/) {
push @args_p, $arg;
}
when (/--permit$/) {
push @args_p, $arg, shift @ARGV;
}
when (/--latex=(.*)$/) {
$pgm1 = $1;
push @args_p, $arg;
}
when (/--latex$/) {
$pgm1 = shift @ARGV;
push @args_p, "$arg=$pgm1";
}
# lualatex options and parameters
when (/--jobname$/) {
$job1 //= shift @ARGV;
push @args_l, "$arg=$job1";
}
when (/--jobname=(.*)$/) {
$job1 //= $1;
push @args_l, $arg;
}
when (/(.*).tex$/) {
$job2 //= $1;
push @args_l, $arg;
}
default {
push @args_l, $arg;
}
}
}
unless ($job1) {
if ($job2){
unshift @args_l, "--jobname=$job2";
}
}
unless ($pgm1) {
push @args_p, "--latex=$pgm2";
}
if ($dry_run) {
say join "\n ", 'perltex', @args_p, @args_l;
}
else {
exec 'perltex', @args_p, @args_l;
}
__END__
=head1 NAME
mpll -- metaperlualatex typeset LaTeX documents, with embedded Perl code, Lua code and METAPOST code.
=head1 SYNOPSIS
mpll [--help] [ perltex options ] [ lualatex options ]
=head1 DESCRIPTION
mpll is actually a thin wrapper around perltex and lualatex. It allows you embed Perl code,
Lua code and METAPOST at the same time inside a LaTeX document.
=head1 OPTIONS
The options are split into three categories: B<perltex> options, B<lualatex>
options and exclusive options. B<perltex> options and B<lualatex> options
are transparently given to their respective target programs.
Exclusive options are options that are not transparently transmitted
to B<perltex> or B<lualatex>. In some cases, exclusive options even prevent
the typesetting from being performed.
=head2 Exclusive Options
=over 4
=item B<--help>
Displays the basic usage information and exits.
=item B<--version>
Displays the version numbers for B<mpll> and B<lualatex> and exits (no version number is defined for B<perltex>).
=item B<--credits>
Display credits and exits.
=item B<--dry-run>
Parses the options, builds the B<perltex> commande line, prints it and exits, without running B<perltex> or B<lualatex>.
For debugging purposes.
=back
=head2 Perltex Options
(Taken nearly verbatim from B<perltex>'s documentation)
=over 4
=item B<-->[B<no>]B<safe>
Enable or disable sandboxing. With the default of B<--safe>,
B<perltex> executes the code from a C<\perlnewcommand> or
C<\perlrenewcommand> macro within a protected environment that
prohibits ``unsafe'' operations such as accessing files or executing
external programs. Specifying B<--nosafe> gives the LaTeX document
I<carte blanche> to execute any arbitrary Perl code, including that
which can harm the user's files. See L<Safe> for more information.
=item B<--permit>=I<feature>
Permit particular Perl operations to be performed. The B<--permit>
option, which can be specified more than once on the command line,
enables finer-grained control over the B<perltex> sandbox. See
L<Opcode> for more information.
=item B<--makesty>
Generate a LaTeX style file called F<noperltex.sty>. Replacing the
document's C<\usepackage{perltex}> line with C<\usepackage{noperltex}>
produces the same output but does not require PerlTeX, making the
document suitable for distribution to people who do not have PerlTeX
installed. The disadvantage is that F<noperltex.sty> is specific to
the document that produced it. Any changes to the document's PerlTeX
macro definitions or macro invocations necessitates rerunning
B<perltex> with the B<--makesty> option.
=back
=head2 Lualatex Options
B<lualatex> has many options and it is still in development. So the
actually available options for B<mpll> are the options offered
by the B<lualatex> program installed on your system.
However, here are the most frequently used options
TODO
=head1 EXAMPLES
In its simplest form, B<mpll> is run just like B<perltex> or B<latex>:
mpll myfile.tex
If LaTeX gives a ``C<trapped by operation mask>'' error and you trust
the F<.tex> file you're trying to compile not to execute malicious
Perl code (e.g., because you wrote it yourself), you can disable
B<perltex>'s safety mechanisms with B<--nosafe>:
mpll --nosafe myfile.tex
The following command gives documents only B<perltex>'s default
permissions (C<:browse>) plus the ability to open files and invoke the
C<time> command:
mpll --permit=:browse --permit=:filesys_open
--permit=time myfile.tex
TODO
=head1 ENVIRONMENT
B<perltex> and therefore B<mpll> honor the following environment variables:
=over 4
=item PERLTEX
Specify the filename of the LaTeX compiler. The LaTeX compiler
defaults to ``C<latex>''. The C<PERLTEX> environment variable
overrides this default, and the B<--latex> command-line option (see
L</OPTIONS>) overrides that.
=back
=head1 FILES
While compiling F<jobname.tex>, B<perltex> makes use of the following
files:
=over 4
=item F<jobname.lgpl>
log file written by Perl; helpful for debugging Perl macros
=item F<jobname.topl>
information sent from LuaLaTeX to Perl
=item F<jobname.frpl>
information sent from Perl to LuaLaTeX
=item F<jobname.tfpl>
``flag'' file whose existence indicates that F<jobname.topl> contains
valid data
=item F<jobname.ffpl>
``flag'' file whose existence indicates that F<jobname.frpl> contains
valid data
=item F<jobname.dfpl>
``flag'' file whose existence indicates that F<jobname.ffpl> has been
deleted
=item F<noperltex-#.tex>
file generated by F<noperltex.sty> for each PerlTeX macro invocation
=back
=head1 NOTES
B<perltex>'s sandbox defaults to what L<Opcode> calls ``C<:browse>''.
=head1 SEE ALSO
latex(1), pdflatex(1), perl(1), Safe(3pm), Opcode(3pm), luatex(1), lualatex(1), lua(1)
=head1 AUTHOR
Jean Forget
With many ideas and much documentation taken from
Scott Pakin, I<scott+pt@pakin.org>
and the LuaTeX team.