Steffen Klupsch writes:
 > This posting corresponds to '5.2.1 Options controlling Titles,
 > File-Names and Sectioning' of the l2h manual.

Steffen,
  For the Python documentation (http://www.python.org/doc/), I use a
different approach.  I let l2h assign node#.html filenames, and then
post-process the files using the information stored about \label
commands in the markup.  So this:

        \section{My Section \label{my-section}}

ends up in my-section.html.  This also doesn't depend on the html
package provided with latex2html, and lets LaTeX verify uniqueness of
the generated file names.  Note that the my script is somewhat
sensitive to labels defined elsewhere in the section, so if you use a
lot of labels other than the ones for section headings (of whatever
level), there can be a little non-determinism, but that hasn't been a
problem in my application.
  I run the script by cd'ing into the directory containing the HTML
files and running "node2label.pl *.html"; the node2label.pl script is
available as part of the documentation source package at the link
above, or just pull off the attachment to this message.  ;-)
  I'd be interested to know if you find this useful.


  -Fred

--
Fred L. Drake, Jr.
[EMAIL PROTECTED]
Corporation for National Research Initiatives
1895 Preston White Drive    Reston, VA  20191

#! /usr/bin/env perl

use English;
$INPLACE_EDIT = '';

# read the labels, then reverse the mappings
require "labels.pl";

%nodes = ();
my $key;
# sort so that we get a consistent assignment for nodes with multiple labels 
foreach $label (sort keys %external_labels) {
  $key = $external_labels{$label};
  $key =~ s|^/||;
  $nodes{$key} = $label;
}

# This adds the "internal" labels added for indexing.  These labels will not
# be used for file names.
require "intlabels.pl";
foreach $label (keys %internal_labels) {
  $key = $internal_labels{$label};
  $key =~ s|^/||;
  if (defined($nodes{$key})) {
    $nodes{$label} = $nodes{$key};
  }
}

# collect labels that have been used
%newnames = ();

while (<>) {
  # don't want to do one s/// per line per node
  # so look for lines with hrefs, then do s/// on nodes present
  if (/(HREF|href)=\"([^\#\"]*)html[\#\"]/) {
    @parts = split(/(HREF|href)\=\"/);
    shift @parts;
    for $node (@parts) {
      $node =~ s/[\#\"].*$//g;
      chop($node);
      if (defined($nodes{$node})) {
	$label = $nodes{$node};
	if (s/(HREF|href)=\"$node([\#\"])/$1=\"$label.html$2/g) {
	  s/(HREF|href)=\"$label.html#(l2h-)?SECTION\d+/$1=\"$label.html/g;
	  $newnames{$node} = "$label.html";
	}
      }
    }
  }
  print;
}

foreach $oldname (keys %newnames) {
  rename($oldname, $newnames{$oldname});
}

Reply via email to