2
# Fixes various things within tex files.
10
# Get a list of include files from the top-level tex file.
13
foreach my $filename (@_) {
15
# Start with the top-level latex file so it gets checked too.
16
push (@list,$filename);
18
# Get a list of all the html files in the directory.
19
open IF,"<$filename" or die "Cannot open input file $filename";
22
push @list,"$1.tex" if (/\\include\{(.*?)\}/);
32
my ($linecnt,$filedata,$output,$itemcnt,$indentcnt,$cnt);
35
foreach my $file (@files) {
36
# Open the file and load the whole thing into $filedata. A bit wasteful but
37
# easier to deal with, and we don't have a problem with speed here.
39
open IF,"<$file" or die "Cannot open input file $file";
45
# We look for a line that starts with \item, and indent the two next lines (if not blank)
50
# Process a line at a time.
51
foreach (split(/\n/,$filedata)) {
52
$_ .= "\n"; # Put back the return.
53
# If this line is less than the third line past the \item command,
54
# and the line isn't blank and doesn't start with whitespace
55
# add three spaces to the start of the line. Keep track of the number
57
if ($linecnt < 3 and !/^\\item/) {
69
/^\\item / and $linecnt = 1;
73
# This is an item line. We need to process it too. If inside a \begin{description} environment, convert
74
# \item {\bf xxx} to \item [xxx] or \item [{xxx}] (if xxx contains '[' or ']'.
78
my ($before,$descrip,$this,$between);
80
# Find any \begin{description} environment
81
while ($filedata =~ /(\\begin[\s\n]*\{[\s\n]*description[\s\n]*\})(.*?)(\\end[\s\n]*\{[\s\n]*description[\s\n]*\})/s) {
86
# Search for \item {\bf xxx}
87
while ($descrip =~ /\\item[\s\n]*\{[\s\n]*\\bf[\s\n]*/s) {
90
($between,$descrip) = find_matching_brace($descrip);
92
$linecnt = $output =~ tr/\n/\n/;
93
print STDERR "Missing matching curly brace at line $linecnt in $file\n" if (!$descrip);
96
# Now do the replacement.
97
$between = '{' . $between . '}' if ($between =~ /\[|\]/);
98
$output .= "\\item \[$between\]";
103
$output .= $filedata;
105
# If any hyphens or \item commnads were converted, save the file.
106
if ($indentcnt or $itemcnt) {
107
open OF,">$file" or die "Cannot open output file $file";
110
print "$indentcnt indent", ($indentcnt == 1) ? "" : "s"," added in $file\n";
111
print "$itemcnt item", ($itemcnt == 1) ? "" : "s"," Changed in $file\n";
114
$cnt += $indentcnt + $itemcnt;
119
sub find_matching_brace {
120
# Finds text up to the next matching brace. Assumes that the input text doesn't contain
121
# the opening brace, but we want to find text up to a matching closing one.
122
# Returns the text between the matching braces, followed by the rest of the text following
123
# (which does not include the matching brace).
130
# Ignore verbatim constructs involving curly braces, or if the character preceding
131
# the curly brace is a backslash.
132
if ($str =~ /\\verb\*?\{.*?\{|\\verb\*?\}.*?\}|\{|\}/s) {
137
if ((substr($this,-1,1) eq '\\') or
138
$temp =~ /^\\verb/) {
143
$cnt += ($temp eq '{') ? 1 : -1;
144
# If this isn't the matching curly brace ($cnt > 0), include the brace.
145
$this .= $temp if ($cnt);
147
# No matching curly brace found.
148
return ($this . $str,'');
154
sub check_arguments {
155
# Checks command-line arguments for ones starting with -- puts them into
156
# a hash called %args and removes them from @ARGV.
160
for ($i = 0; $i < $#ARGV; $i++) {
161
$ARGV[$i] =~ /^\-+/ or next;
162
$ARGV[$i] =~ s/^\-+//;
163
$args{$ARGV[$i]} = "";
169
##################################################################
171
##################################################################
176
check_arguments(\%args);
177
die "No Files given to Check\n" if ($#ARGV < 0);
179
# Examine the file pointed to by the first argument to get a list of
181
@includes = get_includes(@ARGV);
183
$cnt = convert_files(@includes);
184
print "No lines changed\n" unless $cnt;