-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdtxmk.latexmkrc
47 lines (42 loc) · 1.49 KB
/
dtxmk.latexmkrc
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
#---
# Populate the @default_files list with the files
# generated by the docstrip \generate command
# check if one file is newer than another
sub nt {
return (stat($_[0]))[9] > (stat($_[1]))[9];
}
# slurp a file into a string
sub read_file {
my($file) = @_;
open my $fh, '<', $file or die "Can't open file $!";
read $fh, my $text, -s $fh;
return $text;
}
# the files generated by running docstrip on the given files
sub dtx_generated_files {
my @all_files = ();
foreach (@_) {
my $dtx_file = $_;
(my $dtx_log = $dtx_file) =~ s/.dtx$/.log/;
system ("tex $dtx_file") if (! (-e $dtx_log) || nt($dtx_file,$dtx_log));
# slurp log file into string.
# See https://www.perl.com/article/21/2013/4/21/Read-an-entire-file-into-a-string/
my $dtx_log_text = read_file($dtx_log);
$dtx_log_text =~ s/\n//g;
(my $gen_files_str) = $dtx_log_text =~ /Generating file\(s\) (.*?)\\openout/;
push @all_files, split(/\s/, $gen_files_str);
}
return @all_files;
}
# add the .tex files generated by any .dtx file to the argument list
# and mark the dtx files which generate .tex files for deletion from the arg list
my %dtx_togo;
foreach (@ARGV) {
next unless /\.dtx$/;
if (my @generated_tex_files = grep { /\.tex$/ } dtx_generated_files($_)) {
push @ARGV, @generated_tex_files;
$dtx_togo{$_} = 1;
}
}
# delete those marked .dtx files from the argument list.
@ARGV = grep { !$dtx_togo{$_} } @ARGV;