2 # Finds multiple hyphens not inside a verbatim environment (or \verb).
3 # Places these inside a \verb{} contruct so they will not be converted
4 # to single hyphen by latex or latex2html.
8 # The following builds the test string to identify and change multiple
9 # hyphens in the tex files. Several constructs are identified but only
10 # multiple hyphens are changed; the others are fed to the output
12 my $b = '\\\\begin\\*?\\s*\\{\\s*'; # \begin{
13 my $e = '\\\\end\\*?\\s*\\{\\s*'; # \end{
14 my $c = '\\s*\\}'; # closing curly brace
16 # This captures entire verbatim environments. These are passed to the output
18 my $verbatimenv = $b . "verbatim" . $c . ".*?" . $e . "verbatim" . $c;
20 # This captures \verb{} constructs. They are passed to the output unchanged.
21 my $verb = '\\\\verb\\*?(.).*?\\1';
23 # This identifies multiple hyphens.
24 my $hyphens = '\\-{2,}';
26 # This builds the actual test string from the above strings.
27 #my $teststr = "$verbatimenv|$verb|$tocentry|$hyphens";
28 my $teststr = "$verbatimenv|$verb|$hyphens";
32 # Get a list of include files from the top-level tex file.
35 while (my $filename = shift) {
36 # Start with the top-level latex file so it gets checked too.
37 push (@list,$filename);
39 # Get a list of all the html files in the directory.
40 open IF,"<$filename" or die "Cannot open input file $filename";
43 push @list,"$1.tex" if (/\\include\{(.*?)\}/);
53 my ($filedata,$out,$this,$thiscnt,$before,$verbenv,$cnt);
55 # Build the test string to check for the various environments.
56 # We only do the conversion if the multiple hyphens are outside of a
57 # verbatim environment (either \begin{verbatim}...\end{verbatim} or
58 # \verb{--}). Capture those environments and pass them to the output
62 foreach my $file (@files) {
63 # Open the file and load the whole thing into $filedata. A bit wasteful but
64 # easier to deal with, and we don't have a problem with speed here.
66 open IF,"<$file" or die "Cannot open input file $file";
72 # Set up to process the file data.
77 # Go through the file data from beginning to end. For each match, save what
78 # came before it and what matched. $filedata now becomes only what came
80 # Chech the match to see if it starts with a multiple-hyphen. If so
81 # change it to \verb{--}. The other possible matches in the pattern
82 # won't start with a hyphen, so we're ok with matching that.
83 while ($filedata =~ /$teststr/os) {
87 # This is where the actual conversion is done.
89 # Use this contruct for putting something in between each hyphen
90 #$thiscnt += ($this =~ s/^\-+/do {join('\\,',split('',$&));}/e);
92 # Use this construct for putting something around each hyphen.
93 $thiscnt += ($this =~ s/^\-+/\\verb\{$&\{/);
95 # Put what came before and our (possibly) changed string into
97 $out .= $before . $this;
100 # If any hyphens were converted, save the file.
102 open OF,">$file" or die "Cannot open output file $file";
103 print OF $out . $filedata;
110 ##################################################################
112 ##################################################################
117 # Examine the file pointed to by the first argument to get a list of
119 @includes = get_includes(@ARGV);
121 $cnt = convert_hyphens(@includes);
123 print "$cnt Multiple hyphen", ($cnt == 1) ? "" : "s"," Found\n";