#! @PERL@ # -*- Mode: perl; -*- # DO NOT EDIT # This file created by configure from the "sowing" package # # Minimal processing of a BibTeX database file to make it html # Usage: # bib2html filename > output.html # bib2html -group gfilename filename > output.html # where gfilename is a file containing regular expressions for # author's names and matching URLs. See mpich.group for an example. # -ignore value specifies a field to ignore (e.g., -ignore annote eliminates # annote fields from the output. # # Add header/tail (with link to this code) # Convert comments to %...
# Convert @{ or ( to @ # # To customize for yourself, change the following three lines. $UserName = "William Gropp"; $userURL = "http://www.cs.illinois.edu/~wgropp"; # This is W. or William (the W(\.|illiam)), optionally followed by D. (the # ( D\.)?), followed by Gropp. $UserREName = "W(\.|illiam)( D\.)? Gropp"; # For names that have accents, e.g., \'e, use the HTML entity: # J(\.|orge) Mor&eaccute; # for Jorge Mor\'e # # Using styles # You can define # # and then use # $EntryStart = "

\n"; # $EntryEnd = "

\n"; # to group an entry. # Other style elements that can be used are # font-family # font-weight # text-align # color # width # margin-left # margin-right # $GroupEmphStart = ""; $GroupEmphEnd = ""; # $includeCreateTime = 1; $announce_oldstyle = 0; $groupsize = 0; $ignoresize = 0; $outlist = 0; $debug = 0; $special_entity = 1; $check_valid_fields = 0; # The following variables are often set in the listconfig file $ListHeader = ""; $ListFooter = ""; $BibFileName = ""; $EntryStart = ""; $EntryEnd = ""; # # ignorefields gives the names of fields that should not be noted as # "not known". These apply to every entry type. %ignorefields = ( 'area' => 1, 'areaseq' => 1, 'bibsource' => 1, 'ee' => 1, 'preprintof' => 1, 'doi' => 1, 'eprint' => 1, 'webloc' => 1 ); # Default Formats for outlist # Book # title, author, publisher, year. %htmlformatsBook = ( 'starttitle' => '', 'endtitle' => '' ); @fieldlistBook = ('title', 'author', 'publisher', 'note', 'year'); @fieldlistoptionalBook = ('address', 'pages', 'isbn', 'lccn', 'series', 'keywords', 'editor', 'annote', 'pubaddress', 'key', 'edition' ); # # Booklet # title, author, publisher, year. %htmlformatsBooklet = ( 'starttitle' => '', 'endtitle' => '' ); @fieldlistBooklet = ('title', 'author', 'publisher', 'note', 'month', 'year'); @fieldlistoptionalBooklet = ('address', 'pages', 'isbn', 'lccn', 'series', 'keywords', 'editor', 'annote', 'pubaddress', 'key' ); # # Article # title, author, journal, volume, number, pages, year. %htmlformatsArticle = ( 'starttitle' => '', 'endtitle' => '' ); @fieldlistArticle = ('title', 'author', 'journal', 'volume', 'number', 'pages', 'note', 'year'); @fieldlistoptionalArticle = ('month', 'annote', 'url', 'acknowledgement', 'bibdate', 'issn', 'coden', 'keywords', 'classification', 'conflocation', 'corpsource', 'conftitle', 'sponsororg', 'treatment', 'key', 'affiliation', 'thesaurus', 'key', 'journalabr', 'publisher' ); # InBook # title, author, publisher, year. %htmlformatsInBook = ( 'starttitle' => '', 'endtitle' => '' ); # chapter is the chapter title. @fieldlistInBook = ('chapter', 'author', 'title', 'publisher', 'note', 'year' ); @fieldlistoptionalInBook = ('address', 'pages', 'isbn', 'lccn', 'series', 'keywords', 'editor', 'annote', 'pubaddress', 'key', 'number' ); # # InProceedings # title, author, booktitle, editors, pages, year %htmlformatsInProc = ( 'starttitle' => '', 'endtitle' => '' ); @fieldlistInProc = ('title', 'author', 'booktitle', 'editor', 'pages', 'note', 'year'); @fieldlistoptionalInProc = ('number', 'month', 'series', 'publisher', 'address', 'volume', 'keywords', 'acknowledgement', 'treatment', 'corpsource', 'conftitle', 'classification', 'isbn', 'organization', 'confdate', 'meetingdate', 'meetingdate2', 'sponsor', 'sponsororg', 'thesaurus', 'affiliation', 'bibdate', 'annote', 'url', 'issn', 'confloc', 'eariler', 'owner', 'conflocation', 'crossref', 'editors', 'conference', 'meetingaddress', 'earlier', 'coden', 'key', 'pubaddress', 'category', 'place', 'affiliationaddress', 'journalabr', 'location', 'student' ); %htmlformatsInColl = %htmlformatsInBook; @fieldlistInColl = @fieldlistInBook; @fieldlistoptionalInColl = @fieldlistoptionalInBook; # # Techreport # title, author, institution, number, year %htmlformatsTech = ( 'starttitle' => '', 'endtitle' => '' ); @fieldlistTech = ('title', 'author', 'institution', 'organization', 'number', 'note', 'year'); @fieldlistoptionalTech = ('month', 'keywords', 'url', 'language', 'notes', 'pages', 'bibdate', 'later', 'scope', 'type', 'abstract-url', 'annote', 'address', 'key', 'location', 'category' ); # # Misc # title, author, institution, number, year %htmlformatsMisc = ( 'starttitle' => '', 'endtitle' => '' ); @fieldlistMisc = ('title', 'author', 'institution', 'organization', 'number', 'note', 'year'); @fieldlistoptionalMisc = ( 'month', 'annote', 'key', 'address', 'type', 'howpublished' ); # Manual, Unpublished come from Misc for now. We don't need to define these # because Misc is the default #%htmlformatsManual = %htmlformatsMisc; #@fieldlistManual = @fieldlistMisc; #%htmlformatsUnpublished = %htmlformatsUnpublished; #@fieldlistUnpublished = @fieldlistMisc; # Bibtex entry type mappings %shortentrynames = ( 'Book' => 'Book', 'Inbook' => 'InBook', 'Article' => 'Article', 'Inproceedings' => 'InProc', 'Incollection' => 'InColl', 'Techreport' => 'Tech', 'Misc' => 'Misc', 'Unpublished' => 'Misc', 'Manual' => 'Misc' ); # Example Header entries for a listfile configuration file. # $HeaderRE = "Section:"; # $HeaderStart = "

"; # $HeaderEnd = "

"; # $LiteralHTML = "LiteralHTML:"; while ($_ = $ARGV[0]) { shift; if ($_ eq "-group") { # Read from group file $ARGV[0] # Format is RE!URL # (RE is regular expression for matching the name) $groupname = $ARGV[0]; shift; open( GROUP, "<$groupname" ) || die "Could not open group $groupname!\n"; while () { chop; if ($_ ne "") { # Do we want !/^\s*$/? ($GroupREName[$groupsize],$GroupURL[$groupsize]) = split(/!/); $groupsize ++; } } } elsif ($_ eq "-ignore") { # Read name from cmdline $IgnoreFields[$ignoresize] = lc( $ARGV[0] ); $ignoresize++; shift; } elsif ($_ eq "-listfile") { $outlist = 1; $listfile = $ARGV[0]; shift; } elsif ($_ eq "-listconfig") { $listconfig = $ARGV[0]; shift; } elsif ($_ eq "-title") { $TitleString = $ARGV[0]; shift; } elsif ($_ eq "-debug") { $debug = 1; } elsif ($_ eq "-nospecials") { $special_entity = 0; } elsif ($_ eq "-nooldstyle") { $announce_oldstyle = 1; } elsif ($_ eq "-nocreatetime") { # Mostly useful in automating tests $includeCreateTime = 0; } elsif ($_ eq "-check") { $check_valid_fields = 1; } elsif ($_ eq "-help" || $_ eq "-usage") { print "bib2html [ -listfile name ] [ -listconfig name ] \ [ -group name ] [ -ignore name ] [ -title name ] [ -nospecials ]\ [ -nooldstyle ] [ -check ] filename \ -listfile name - output a bibliography listing on file name\ -listconfig name - Use file name to control the format of\ the list file. This is a Perl script defining\ \$ListHeader - HTML file header (to BODY)\ \$ListFooter - HTML file footer (from BODY)\ \$BibFileName - Name of bib file (used for links)\ \$HeaderRE - Regular expression that will be matched in TeX comments for a header\ \$HeaderStart - HTML inserted in listfile before header\ \$HeaderEnd - HTML inserted in listfile after header\ \$LiteralHTML - Regular expression that will be matched in TeX comments for explicit HTML in output\ \$GroupEmphStart - HTML inserted before names found in the\ group file\ \$GroupEmphEnd - HTML inserted after names found in the\ group file\ \%htmlformatsBook - A Perl has containing HTML commands for\ formatting a Book entry\ \@fieldlistBook - A Perl array containing the BibTeX fields\ to use when formatting a book\ (Similarly for Article, Techreport, InProc (proceedings)\ and Misc)\ A typical listconfig file might contain:\ \ \$ListHeader = \"Bib for me\\\ \ \\n\";\ \$ListFooter = \"\\n\";\ \$BibFileName = \"mpich2-bib.htm\";\ \$EntryStart = \"\";\ \$EntryEnd = \"

\\n\";\ \$HeaderRE = \"Section:\";\ \$HeaderStart = \"

\";\ \$HeaderEnd = \"

\";\ \$LiteralHTML = \"LiteralHTML:\";\ \$GroupEmphStart = \"\";\ \$GroupEmphEnd = \"\";\ 1;\n\ -group name - File containing author names and associated URLs\ -ignore name - Ignore field \"name\" in each bib entry\ -title name - Name to use in the title of the BiBTeX page\ -nospecials - Do not use certain valid HTML character entities\ such as endash that some older browers do not \ recognize.\ -nooldstyle - Print uses of oldstyle LaTeX to stderr.\ -check - Warn about unrecogonized BibTeX fields names.\ \n"; print "To customize the display of an entry, you can modify the\ \"htmlformats\" hash to define how to display each entry. For example,\ the default definition for the \"InBook\" entry type is\ \ %htmlformatsInBook = ( \'starttitle\' => \'\', \'endtitle\' => \'\' ); \ You could redefine these for each entry that you wanted to change. The names\ of the keys are start and end, where is one of the\ recognized fields (e.g., title, author, year). The recognized fields are\ defined by the fieldlist array, where is an entry type.\n"; print "The entry names must be chosen from the right hand side of the\ following list; the left hand side is the full (BibTeX) name of the entry.\ If the entry name is not listed here, use the BibTeX name, with the first \ character capitalized and the other characters in lower case (e.g., Booklet,\ not BookLet)\n"; foreach my $key (keys(%shortentrynames)) { my $name = $shortentrynames{$key}; print " $key => $name\n"; } exit 0; } else { $bibfile=$_; } } open( BIB, "<$bibfile" ) || die "Could not open $bibfile!\n"; if ($outlist) { open( LISTFILE, ">$listfile" ) || die "Could not open $listfile\n"; if (defined($listconfig) && $listconfig ne "") { require $listconfig; print LISTFILE $ListHeader; } } if (!defined($TitleString) || $TitleString eq "") { $TitleString = "Bibliography for $UserName"; } print "\n"; print "\n\n\n"; print "$TitleString\n"; print "\n"; print "\n"; print "\n"; print "\n"; # # Still to do: # Process @string(name=value); replace all uses of @name with # value in formatted (listfile) version. # Allow multiple HeaderRE's # Allow fields in the entryinfo to modify the formatting. For example, # we might let @field@ be replaced by the value of entryinfo{'field'}. # %bibstrings = (); $inrow = ""; $intable = 0; $dooutput = 1; $line_count = 0; $MakeBold = ""; $fieldname = ""; # Format as table. Output to stdout is the formatted version of the # bib database file, and includes any comments from the bib file. # while () { s/\r//g; # remove DOS newlines $line = $_; $line_count++; # Look for a new bib entry starting a line if (/^\s*\@[Ss][Tt][Rr][Ii][Nn][Gg]\s*[\(\{]\s*([^=\s]*)\s*=\s*(.*)\s*[\)\}]/) { # Found @string name = value $bibstrings{$1} = $2; next; } elsif (/^\s*\@([a-zA-Z]*)\s*[\(\{]/) { # Found the beginning of a BibTeX entry (@....) $entry_type = lc( $1 ); if ($intable == 1) { # Finish off the previous table print "\n"; } #$line = $entryinfo{$fieldname}; #$line =~ s%[^=]*=%%; #$entryinfo{$fieldname} = $line; %entryinfo = (); # Clear entry info $entryinfo{"entry_type"} = $entry_type; $inrow = ""; $intable = 1; $dooutput = 1; # Check for a name on the entry type line # Note that the containing test ensures there are only blanks # before the @ if (/\@([a-zA-Z]*)([\(\{])\s*(.*)\s*,\s*$/) { $_ = "\@$1$2$3,\n\n"; } else { print STDERR "Entry $entry_type without a key on the same line\n"; } #s%\@([a-zA-Z]*)([\(\{])\s*(.*)\s*,\s*$%\@$1$2$3,\n
%g; $entryinfo{'key'} = $3; # Setup the list of expected field names based on the entry_type %knownfields = (); $entryname = ucfirst $entry_type; if (defined($shortentrynames{$entryname})) { $entryname = $shortentrynames{$entryname}; } $fieldref = "fieldlist$entryname"; # @$fieldref is the array @fieldlist$entryname #$fieldref->[i] accesses the ith element of the fieldlist %knownfields = (); for ($k=0; $k <= $#$fieldref; $k++) { $knownfields{$fieldref->[$k]} = 1; } $fieldoptref = "fieldlistoptional$entryname"; for ($k=0; $k <= $#$fieldoptref; $k++) { $knownfields{$fieldoptref->[$k]} = 1; } $knownfields{'abstract'} = 1; } elsif (defined($HeaderRE) && $HeaderRE ne "" && /^\s*%\s*($HeaderRE)(.*)$/) { # Found a special comment that we want modified and added to the # LISTFILE. $headertext = $2; if ($outlist && ($HeaderRE ne "" || $HeaderEnd ne "" || $HeaderStart ne "")) { print LISTFILE "$HeaderStart $headertext $HeaderEnd\n"; } } elsif (defined($LiteralHTML) && $LiteralHTML ne "" && /^\s*%\s*($LiteralHTML)(.*)$/) { # Found a special comment that we want modified and added to the # LISTFILE. $headertext = $2; print LISTFILE "$headertext\n"; # Also add to stdout, and bypass any further processing of this line # Add a BR to preserve formating outside of tables if ($intable == 0) { s/$/
/; } print $headertext . "\n" if $dooutput == 1; next; } else { # Look for a new item entry in a bib entry # We may want to skip some items # One thing to be careful of is multi-line items. # Ignore lines that are NOT field asignments, such as # abstract entries that include an = sign. # (This isn't quite right, because a line within an entry that # is = will still match if (/^\s*(\w+)\s*=/) { # Found field = .... print "matched $1 in $_" if $debug; $fieldname = lc($1); # First, a field name outside of an entry is an error if ($intable == 0) { print STDERR "Missing bibtex entry type for line #$line_count:$_\n"; print "
\n"; $intable = 1; } # Finish off the previous line print "$MakeBold$inrow\n" ; $inrow = ""; # Check to see if this line is one that we wish to # suppress # ---- not completely implemented if ($fieldname eq "") { print STDERR "Matched empty field in $_"; } else { for ($i = 0; $i <= $#IgnoreFields; $i++) { if ($IgnoreFields[$i] eq $fieldname) { $dooutput=0; last; } } if ($check_valid_fields && !defined($knownfields{$fieldname})) { # Ignore "opt" fieldnames if (! ($fieldname =~ /^opt/) && ! defined($ignorefields{$fieldname}) ) { print STDERR "Field $fieldname not known for $entryname on line $line_count\n"; } } $entryinfo{$fieldname} = ""; print "Found $fieldname\n" if $debug; if ($fieldname eq "title" || $fieldname eq "chapter") { $MakeBold=""; } else { $MakeBold = ""; } } $line =~ s/^\s*[^=%]*\s*=//; # ---- # Make the "title" text bold, others regular # Output this line # (tr style="vertical-align:top") s%^([^=]*)[ ]*=\s*(.*)\s*$%
$1 = $MakeBold$2%; if ($MakeBold ne "") { $MakeBold = ""; } } # Check of the end of entry (must be alone on a separate line) # fix emacs broken matching mode })} else { if (/^\s*[\}\)]\s*$/) { if ($dooutput == 1) { #({ s%^\s*([\}\)])\s*$%
\n$1%; } else { s%^\s*([\}\)])\s*$%\n$1%; } if ($outlist && defined($entryinfo{"entry_type"})) { &PrintEntry( %entryinfo ); } elsif ($debug && $outlist) { print %entryinfo; } %entryinfo = (); # Clear entry info $fieldname = ""; $intable = 0; $dooutput = 1; } elsif (/^\s*%/) { # Note that for a comment, we need to convert raw text # to valid html. This is handled below. $dooutput = 1; } } } print "Current line[$line_count] = \"$line\"\n" if $debug; $original_line = $line; # # Fix HTML reserved characters # $line =~ s%[\\]+&%&%; # $line =~ s%[\\]+<%<%; # $line =~ s%[\\]+>%>%; # # Convert various TeX commands # # $...$ # $line =~ s%\$([^\$]*)\$%$1%; # # ~ (but not \~) # $line =~ s%([^\\]{1})~%$1 %; # # \textrm{} (currently only strips out the command) # $line =~ s%\\textrm{([^}]*)}%$1%; # # \textem{} (set to em, won't work if nested) # $line =~ s%\\textem{([^}]*)}%$1%; # # \texttt{} (set to tt, won't work if nested) # $line =~ s%\\texttt{([^}]*)}%$1%; # # \url{} # $line =~ s%\\url{([^}]*)}%$1%; # # {\tt ... } # if ($announce_oldstyle && /\\tt /) { # print STDERR "line $line_count: \\tt in $original_line"; # } # $line =~ s%{\\tt([^}]*)}%$1%; # # {\it ... } # if ($announce_oldstyle && /\\it /) { # print STDERR "line $line_count: \\it in $original_line"; # } # $line =~ s%{\\it([^}]*)}%$1%; # # \~{ } # $line =~ s%\\~\{\s*\}%~%g; # # \# # $line =~ s%\\#%#%g; # # \o # $line =~ s%\\o([^A-Za-z]{1})%ø$1%; # # \O # $line =~ s%\\O([^A-Za-z]{1})%Ø$1%; # # _{} -> ... # # ^{} -> ... # # \_ -> _ # # \{ -> { # # \} -> } # # \(.*\) -> ... # # \'{letter} {} is optional # $line =~ s%\\'\{([AEIOUYaeiouy]{1})\}%&$1acute;%; # $line =~ s%\\'([AEIOUYaeiouy]{1})%&$1acute;%; # # \~ # $line =~ s%\\~\{([ANOano]{1})\}%&$1tilde;%; # $line =~ s%\\~([ANOano]{1})%&$1tilde;%; # # \" # $line =~ s%\\"\{([AEIOUaeiou]{1})\}%&$1uml;%; # $line =~ s%\\"([AEIOUYaeiouy]{1})%&$1uml;%; # # \` # $line =~ s%\\`\{([AEIOUaeiou]{1})\}%&$1grave;%; # $line =~ s%\\`([AEIOUaeiou]{1})%&$1grave;%; # # # # \. # $line =~ s%\\`\{([AEIOUaeiou]{1})\}%&$1circ;%; # $line =~ s%\\`([AEIOUaeiou]{1})%&$1circ;%; # # --- -> — # $line =~ s%---%—% if $special_entity; # # -- -> – # $line =~ s%--%–% if $special_entity; if ($line =~ /^\s*%/) { $line = &CleanHTML($line); } else { $line = &CleanLaTeX($line); } if (defined($fieldname) && $fieldname ne "") { print "Adding field $fieldname with text $line" if $debug; $entryinfo{ $fieldname } .= $line; } # else { # # Add this info to an "empty" element. This holds, for example, # # comments from the bibtex file # #$entryinfo{ "" } .= $line; # } # Turn URLs into links in $_ s%(http:[^ }"]*)%$1%g; s%(ftp:[^ }"]*)%$1%g; # Comment the following to not use links for author names # This also makes the author name bold s%($UserREName)%$GroupEmphStart$1$GroupEmphEnd%g; # For a group's bibliography, an array of UserREs and the corresponding # URLs could be used (preloaded as an option to this command) for ($i = 1; $i <= $#GroupURL; $i++) { s%($GroupREName[$i])%$GroupEmphStart$1$GroupEmphEnd%g; } # Add a BR to preserve formating outside of tables if ($intable == 0) { s/$/
/; } print $_ if $dooutput == 1; } if ($includeCreateTime) { $curtime = localtime; print "Generated on $curtime with bib2html\n"; } print "\n"; print "\n"; if (defined($listconfig) && $listconfig ne "") { print LISTFILE $ListFooter; } # # This routine replaces @xxx@ with the value of xxx in the entry info. # This allows you to use bibtex fields to control formatting by using # the class=name style directive. sub ReplaceParms { $textline = $_[0]; $default = $_[1]; if ($textline =~ /\@([a-z]+)\@/) { $token = $1; $replacement = $entryinfo{$token}; $replacement =~ s/^\s*//; if ($replacement eq "") { $replacement = $default; } $textline =~ s/\@$token\@/$replacement/; } return $textline; } # Print out an entry sub PrintEntry { my $entry_type = $entryinfo{"entry_type"}; print "Printing $entry_type\n" if $debug; # First, clean up values foreach $key (keys %entryinfo) { $value = $entryinfo{$key}; $value =~ s/,\s*$//s; $value =~ s/^\s*(\"|\{){1}(.*)(\"|\}){1}/$2/s; chomp $value; $entryinfo{$key} = $value; } if ($debug) { print %entryinfo ; } if (defined($entryinfo{'key'})) { my $keyname = $entryinfo{'key'}; print LISTFILE "\n"; } if ($EntryStart ne "") { $textline = &ReplaceParms( $EntryStart ); print LISTFILE $textline; } if ($entry_type eq "book") { &PrintBook; } elsif ($entry_type eq "article") { &PrintArticle; } elsif ($entry_type eq "inproceedings") { &PrintInProceedings; } elsif ($entry_type eq "incollection") { &PrintInCollection; } elsif ($entry_type eq "techreport") { &PrintTechreport; } else { # Works for manual, unpublished, misc, etc &PrintArbEntry( $entry_type ); } if ($EntryEnd ne "") { $textline = &ReplaceParms( $EntryEnd ); print LISTFILE $textline; } } sub TitleCase { # Convert to title case, but don't change case inside of {}. # FIXME: To be implemented } # Clean up an author list (name and name and name ... goes to name, name, # ..., and name; may also map authors to URLs). sub AuthorList { my $fieldname = $_[0]; # Convert all but last "and" into , if (defined($entryinfo{$fieldname})) { $author = $entryinfo{$fieldname}; @authors = split /\s+and\s+/, $author; print @authors if $debug; print "n = $#authors\n" if $debug; if ($#authors > 1) { $author = ""; for ($i=0; $i<$#authors; $i++) { $author .= $authors[$i]; $author .= ", "; } $author .= "and $authors[$#authors]"; } # Comment the following to not use links for author names # This also makes the author name bold $author =~ s%($UserREName)%$GroupEmphStart$1$GroupEmphEnd%g; # For a group's bibliography, an array of UserREs and the corresponding # URLs could be used (preloaded as an option to this command) for ($i = 1; $i <= $#GroupURL; $i++) { $author =~ s%($GroupREName[$i])%$GroupEmphStart$1$GroupEmphEnd%g; } $entryinfo{$fieldname} = $author; } } sub PrintBook { # title, author, publisher, year. %htmlformats = %htmlformatsBook; # We should really check for author; if no author but an editor, # use the editor field instead. @fieldlist = @fieldlistBook; if (!defined($entryinfo{'author'}) && defined($entryinfo{'editor'})) { for ($i=0; $i<$#fieldlist; $i++) { if ($fieldlist[$i] eq 'author') { $fieldlist[$i] = 'editor'; last; } } } &PrintGeneral; } sub PrintArticle { # title, author, journal, volume, number, pages, year. %htmlformats = %htmlformatsArticle; @fieldlist = @fieldlistArticle; &PrintGeneral; } sub PrintInProceedings { # title, author, booktitle, editors, pages, year %htmlformats = %htmlformatsInProc; @fieldlist = @fieldlistInProc; &PrintGeneral; } # # Print an arbitrary entry type. Use Misc if the type is not defined sub PrintArbEntry { my $entrytype = $1; my $entryname = ucfirst $entry_type; my $var = "htmlformats$entryname"; if (%$var) { %htmlformats = %$var; } else { print "No $var found for entry $entry_type\n"; %htmlformats = %htmlformatsMisc; } $var = "fieldlist$entryname"; if (@$var) { @fieldlist = @$var; } else { print "No $var found for entry $entry_type\n"; @fieldlist = @fieldlistMisc; } &PrintGeneral; } sub PrintInBook { # chapter, author, title, editors, pages, year %htmlformats = %htmlformatsInBook; @fieldlist = @fieldlistInBook; &PrintGeneral; } sub PrintInCollection { # chapter, author, title, editors, pages, year %htmlformats = %htmlformatsInBook; @fieldlist = @fieldlistInBook; &PrintGeneral; } sub PrintTechreport { # title, author, institution, number, year %htmlformats = %htmlformatsTech; @fieldlist = @fieldlistTech; &PrintGeneral; } sub PrintMisc { # title, author, institution, number, year %htmlformats = %htmlformatsMisc; @fieldlist = @fieldlistMisc; &PrintGeneral; } sub CleanString { $value = $_[0]; # Remove extra {} pairs $value =~ s/{([^{}]*)}/$1/gs; return $value; } sub PrintGeneral { # Clean up any author or editor list &AuthorList( 'author' ); &AuthorList( 'editor' ); $firstitem = 1; foreach $key (@fieldlist) { if (!defined($entryinfo{$key})) { next; } $value = $entryinfo{$key}; if ($value eq "") { next; } if (!$firstitem) { print LISTFILE ", ";} else { $firstitem = 0; } $keyname = "start$key"; if (defined($htmlformats{$keyname})) { print LISTFILE "$htmlformats{$keyname}"; } $value = &CleanString( $value ); # # Here is where we look for @name and then look up name # in bibstrings. Or we could just keep a list of strings and # replacements (just like the GroupREName and GroupURL) if ($key eq 'title' && defined($entryinfo{'officialurl'})) { $url = $entryinfo{'officialurl'}; print LISTFILE "$value"; } elsif ($key eq 'title' && defined($entryinfo{'url'})) { $url = $entryinfo{'url'}; print LISTFILE "$value"; } else { print LISTFILE "$value"; } $keyname = "end$key"; if (defined($htmlformats{$keyname})) { print LISTFILE "$htmlformats{$keyname}"; } } print LISTFILE ".\n"; if ($BibFileName ne "") { # If the BibFileName is not set, this link will not be correct print LISTFILE "BibTeX\n"; } } # Replace latex commands with HTML sub CleanLaTeX { my $line = $_[0]; # Fix HTML reserved characters $line =~ s%[\\]+&%&%; $line =~ s%[\\]+<%<%; $line =~ s%[\\]+>%>%; # Convert various TeX commands # $...$ $line =~ s%\$([^\$]*)\$%$1%; # ~ (but not \~) $line =~ s%([^\\]{1})~%$1 %; # \textrm{} (currently only strips out the command) $line =~ s%\\textrm{([^}]*)}%$1%; # \textem{} (set to em, won't work if nested) $line =~ s%\\textem{([^}]*)}%$1%; # \texttt{} (set to tt, won't work if nested) $line =~ s%\\texttt{([^}]*)}%$1%; # \url{} $line =~ s%\\url{([^}]*)}%$1%; # {\tt ... } if ($announce_oldstyle && /\\tt /) { print STDERR "line $line_count: \\tt in $original_line"; } $line =~ s%{\\tt([^}]*)}%$1%; # {\it ... } if ($announce_oldstyle && /\\it /) { print STDERR "line $line_count: \\it in $original_line"; } $line =~ s%{\\it([^}]*)}%$1%; # \~{ } $line =~ s%\\~\{\s*\}%~%g; # \# $line =~ s%\\#%#%g; # \o $line =~ s%\\o([^A-Za-z]{1})%ø$1%; # \O $line =~ s%\\O([^A-Za-z]{1})%Ø$1%; # _{} -> ... # ^{} -> ... # \_ -> _ # \{ -> { # \} -> } # \(.*\) -> ... # \'{letter} {} is optional $line =~ s%\\'\{([AEIOUYaeiouy]{1})\}%&$1acute;%; $line =~ s%\\'([AEIOUYaeiouy]{1})%&$1acute;%; # \~ $line =~ s%\\~\{([ANOano]{1})\}%&$1tilde;%; $line =~ s%\\~([ANOano]{1})%&$1tilde;%; # \" $line =~ s%\\"\{([AEIOUaeiou]{1})\}%&$1uml;%; $line =~ s%\\"([AEIOUYaeiouy]{1})%&$1uml;%; # \` $line =~ s%\\`\{([AEIOUaeiou]{1})\}%&$1grave;%; $line =~ s%\\`([AEIOUaeiou]{1})%&$1grave;%; # # \. $line =~ s%\\`\{([AEIOUaeiou]{1})\}%&$1circ;%; $line =~ s%\\`([AEIOUaeiou]{1})%&$1circ;%; # --- -> — $line =~ s%---%—% if $special_entity; # -- -> – $line =~ s%--%–% if $special_entity; return $line; } sub CleanHTML { my $line = $_[0]; $line =~ s%&%--amp--%g; $line =~ s%<%<%g; $line =~ s%>%>%g; $line =~ s%--amp--%&%g; return $line; }