-
Notifications
You must be signed in to change notification settings - Fork 0
/
inlineit
executable file
·45 lines (41 loc) · 1.25 KB
/
inlineit
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
#!/usr/bin/perl
$mainfile = shift(@ARGV);
$output = shift(@ARGV);
if ($mainfile eq "" || $output eq "" || ($mainfile =~ /.tex/) || (!$output =~ /.tex/)) {
print("usage: inlineit <main> <inlined.tex>\n e.g. inlineit paper p101-blackburn.tex\n\nNOTE: This comes with no guarantee of correctness---please\n check the output carefully.\n"); exit(0);
}
open (OUT, ">$output");
inline($mainfile);
print "\n";
close OUT;
exit(0);
sub inline {
my ($inlinefile) = @_;
my ($IN, $thisline, $restofline);
if (!(($inlinefile =~ /.tex/) || ($inlinefile =~ /.bbl/) || ($inlinefile =~ /.sty/))) {
$inlinefile .= ".tex";
}
print "$inlinefile ";
die "Could not open $inlinefile" unless (open($IN, "<$inlinefile"));
while (<$IN>) {
if (/^\s*\\input\{.+\}/) {
($input,$restofline) = /\\input\{([^\}]+)\}\s*(.*)/;
# print "->$input<-";
inline($input);
print OUT $restofline;
} elsif (/^\s*\\input\s+[^\\]+/) {
($input,$restofline) = /\\input\s+([^\\\s]+)\s*(.*)/;
# print "=>$input<=";
inline($input);
print OUT $restofline;
} elsif (/^\\bibliography/) {
} elsif (/\\end\{document\}/) {
$thisline = $_;
inline($mainfile.".bbl");
print OUT $thisline;
} else {
print OUT $_;
}
}
close $IN;
}