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
|
# Support for pythontex in v. 0.16 or higher.
#
# What these definitions provide/do:
# 1. Variable specifying command string for invoking pythontex
# 2. Definition of commands for latex, pdflatex, etc to call a
# subroutine latex_python that implements the necessary
# functionality, as follows:
# a. The latex, pdflatex program, etc is run.
# b. It is determined whether a file $root.pytxcode was generated
# during the run. Here $root is the root name of the primary
# document file. The $root.pytxcode, if present, is created in
# the output directory (or more exactly, the aux directory, if
# different from the output directory. It is a symptom of the
# use of pythontex.
# c. If the file is present, a rule for running pythontex is set
# up, if it has not already been created.
# d. The source file for the rule is $root.pytxcode and the
# destination file is named $root.pytxmcr, which is always
# created in a subdirectory named pythontex-files-$root of the
# aux or output directory. The file $root.pytxmcr is always
# created when pythontex is run, and is read when a document
# using pythontex is compiled (by latex, or pdflatex, etc)
# e. If that rule is being created for the first time, a message is
# appended to the .log file of the latex run about the
# $root.pytxmcr filename (with the appropriate prefix
# directory). This ensures that at the next stage of the
# processing, when latexmk examines the run's .log file, it
# creates appropriate dependency information and links the
# pythontex rule into the network of dependencies.
# 3. Settings for the files generated by the pythontex package and the
# pythontex program so that the files are deleted in a clean-up
# operation.
$clean_ext .= " pythontex-files-%R/*";
push @generated_exts, 'pytxcode';
$pythontex = 'pythontex %O %S';
foreach my $cmd ('latex', 'lualatex', 'pdflatex', 'xelatex' ) {
${$cmd} = "internal latex_python %R %Y $cmd %O %S";
}
sub latex_python {
# Run *latex, then set pythontex rule if needed.
# Arguments: Root name, directory for aux files (with terminator),
# latex program to run, arguments for latex.
my $root = shift;
my $dir_string = shift;
my $pytx_code = "$dir_string$root.pytxcode";
my $result_dir = $dir_string."pythontex-files-$root";
my $pytx_out_file = "$result_dir/$root.pytxmcr";
my $pytx_rule_name = "pythontex $root";
my $ret = system @_;
if ( test_gen_file( $pytx_code ) ) {
print "=== Pythontex being used\n";
if (! rdb_rule_exists( $pytx_rule_name ) ) {
print "=== Creating rule '$pytx_rule_name'\n";
rdb_create_rule( $pytx_rule_name, 'external', $pythontex, '', 1,
$pytx_code, $pytx_out_file, $root, 1 );
system "echo No file \"$pytx_out_file\". >> \"$dir_string$root.log\"";
}
}
return $ret;
}
|