-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathTeXZillaParser.pl
46 lines (39 loc) · 1.35 KB
/
TeXZillaParser.pl
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
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# Install the Perl interface to the V8 JavaScript engine
#
# cpan JavaScript::V8
#
# and execute this program with
#
# perl TeXZillaParser.pl aTeX [aDisplay] [aRTL] [aThrowExceptionOnError]
#
use strict;
use warnings;
use File::Slurp;
use JavaScript::V8;
my $TEXZILLA_JS = "../TeXZilla-min.js";
# Verify that we have at least one argument.
my $argc = $#ARGV + 1;
if ($argc == 0) {
print "usage: perl TeXZillaParser.pl aTeX [aDisplay] [aRTL] [aThrowExceptionOnError]\n";
exit 1;
}
# Prepare the V8 Javascript engine and load TeXZilla.js
my $context = JavaScript::V8::Context->new();
$context->name_global("window");
$context->eval(scalar read_file $TEXZILLA_JS);
# Bind the arguments to Javascript variables.
$context->bind(tex => $ARGV[0]);
$context->bind(display => ($argc >= 2 && $ARGV[1] eq "true"));
$context->bind(rtl => ($argc >= 3 && $ARGV[2] eq "true"));
$context->bind(throwException => ($argc >= 4 && $ARGV[3] eq "true"));
# Execute TeXZilla.toMathMLString with the specified arguments.
my $result = $context->
eval("TeXZilla.toMathMLString(tex, display, rtl, throwException)");
if (defined $result) {
print $result;
} else {
print $@;
}