Skip to content

Commit 1701b04

Browse files
committed
(chore): setup all macroses/configuration
1 parent 765cd08 commit 1701b04

32 files changed

+2021
-0
lines changed

.latexmkrc

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
ensure_path( 'TEXINPUTS', './configuration/' );
2+
$pdf_mode=4;
3+
$lualatex = 'lualatex %O --shell-escape %S';
4+
$out_dir = '.';
5+
$aux_dir = 'build';
6+
7+
our @memoize_extract = ( 'memoize-extract.pl' );
8+
our @memoize_clean = ( 'memoize-clean.pl' );
9+
push @generated_exts, 'mmz', 'mmz.log';
10+
11+
12+
add_hook( 'after_xlatex_analysis', \&mmz_analyze );
13+
add_hook( 'after_main_pdf', \&mmz_extract_new );
14+
# add_hook( 'cleanup', \&mmz_cleanup );
15+
16+
my $mmz_has_new = '';
17+
18+
19+
#-----------------------------------------------------
20+
21+
sub mmz_analyze {
22+
use strict;
23+
my $base = $$Pbase;
24+
my $mmz_file = "$aux_dir1$base.mmz";
25+
$mmz_has_new = '';
26+
27+
if (! -e $mmz_file) {
28+
print "mmz_analyze: No mmz file '$mmz_file', so memoize is not being used.\n";
29+
return 0;
30+
}
31+
32+
if ( ! test_gen_file_time( $mmz_file) ) {
33+
warn "mmz_analyze: Mmz file '$mmz_file' exists, but wasn't generated\n",
34+
" on this run so memoize is not **currently** being used.\n";
35+
return 0;
36+
}
37+
my $mmz_fh = undef;
38+
if (! open( $mmz_fh, '<', $mmz_file ) ) {
39+
warn "mmz_analyze: Mmz file '$mmz_file' exists, but I can't read it:\n",
40+
" $!\n";
41+
return 1;
42+
}
43+
my @externs = ();
44+
my @dirs = ();
45+
while ( <$mmz_fh> ) {
46+
s/\s*$//; # Remove trailing space, including new lines
47+
if ( /^\\mmzNewExtern\s+{([^}]+)}/ ) {
48+
# We have a new memo item without a corresponding pdf file.
49+
# It will be put in the aux directory.
50+
my $file = "$aux_dir1$1";
51+
print "mmz_analyze: new extern for memoize: '$file'\n";
52+
push @externs, $file;
53+
}
54+
elsif ( /^\\mmzPrefix\s+{([^}]+)}/ ) {
55+
# Prefix.
56+
my $prefix = $1;
57+
if ( $prefix =~ m{^(.*)/[^/]*} ) {
58+
my $dir = $1;
59+
push @dirs, "$aux_dir1$1";
60+
61+
}
62+
}
63+
}
64+
close $mmz_fh;
65+
foreach (@dirs) {
66+
if ( ! -e ) {
67+
my @cmd = ( @memoize_extract, '--mkdir', $_ );
68+
print "mmz_analyze: Making directory '$_' safely by running\n",
69+
" @cmd\n";
70+
mkdir $_;
71+
}
72+
}
73+
74+
rdb_ensure_files_here( @externs );
75+
rdb_remove_files( $rule, "$mmz_file.log" );
76+
77+
if (@externs ) {
78+
$mmz_has_new = $mmz_file;
79+
}
80+
return 0;
81+
}
82+
83+
#-----------------------------------------------------
84+
85+
sub mmz_extract_new {
86+
use strict;
87+
if ( $mmz_has_new eq '' ) { return 0; }
88+
89+
my $mmz_file = $mmz_has_new;
90+
my ($mmz_file_no_path, $path) = fileparse( $mmz_file );
91+
my $pdf_file = $$Pdest;
92+
local $ENV{TEXMF_OUTPUT_DIRECTORY} = $aux_dir;
93+
for ('TEXMF_OUTPUT_DIRECTORY') {
94+
print "mmz_extract_new : ENV{$_} = '$ENV{$_}'\n";
95+
}
96+
my @cmd = (@memoize_extract, '--format', 'latex',
97+
'--pdf', $pdf_file, $mmz_file_no_path );
98+
99+
if ( ! -e $pdf_file ) {
100+
warn "mmz_extract_new: Cannot generate externs here, since no pdf file generated\n";
101+
return 1;
102+
}
103+
elsif ( ! test_gen_file($pdf_file) ) {
104+
warn "mmz_extract_new: Pdf file '$pdf_file' exists, but wasn't\n",
105+
" generated on this run. I'll run memoize-extract. Pdf file may contain\n",
106+
" extra pages generated by the memoize package.\n";
107+
return 1;
108+
}
109+
print "make_extract_new: Running\n @cmd\n";
110+
return system @cmd;
111+
}
112+
113+
#-----------------------------------------------------
114+
115+
sub mmz_cleanup {
116+
use strict;
117+
print "============= I am mmz_cleanup \n";
118+
my @cmd = ( @memoize_clean, '--all', '--yes',
119+
'--prefix', $aux_dir,
120+
"$aux_dir1$$Pbase.mmz" );
121+
print "mmz_cleanup: Running\n @cmd\n";
122+
my $ret = system @cmd;
123+
say "Return code $ret";
124+
return $ret;
125+
}
126+
127+
#-----------------------------------------------------
128+

CONTRIBUTING.md

Whitespace-only changes.

README.md

Whitespace-only changes.

0 commit comments

Comments
 (0)