-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathajust-tex
executable file
·71 lines (60 loc) · 1.3 KB
/
ajust-tex
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
68
69
70
71
#!/usr/bin/perl
use strict;
use warnings;
use Encode;
my ($fichier) = @ARGV;
my $fic_contenu = $fichier . ".tex";
my $fic_squelette = $fichier . ".skel";
open my $f, $fic_contenu
or die "ouverture $fic_contenu $!";
my @source = <$f>;
close $f
or die "fermeture $fic_contenu $!";
my @dest;
my %ref;
for (@source) {
Encode::from_to($_, "utf8", "iso-8859-1");
if (/\\.*section\*\{(?:\d+\.\s*)?(.*?)\\label\{(.*?)\}/) {
my $cle = lc($1);
$cle =~ tr/\xc9/\xe9/;
$ref{$cle} = $2;
}
}
#print STDERR "Hachage \%ref :\n";
#for (sort keys %ref) {
# print STDERR $_, " -> ", $ref{$_}, "\n";
#}
for (@source) {
s/1re/1\\re{}/g;
s/\bTM\b/\\tm{}/g;
s/\bLATEX\b/\\LaTeX{}/g;
if (/\\(?:textsf|emph)\{(.*?)\} --- p\.\d+/) {
my $ref = $ref{lc($1)};
if ($ref) {
s/p\.\d+/p\.\\pageref\{$ref\}/;
#print STDERR "Modification $_";
}
else {
#print STDERR "Référence pour '$1' introuvable\n";
}
}
push @dest, $_;
}
open my $sk, $fic_squelette
or die "ouverture $fic_squelette $!";
open $f, '>', $fic_contenu
or die "ouverture $fic_contenu $!";
while (<$sk>) {
if (/^\\input\{$fichier\}$/) {
for (@dest) {
print $f $_;
}
}
else {
print $f $_;
}
}
close $sk
or die "fermeture $fic_squelette $!";
close $f
or die "fermeture $fic_contenu $!";