# # local.perl # ################################################################################## # # Handle text-mode extensions from local.sty # sub do_cmd_dzero { join ('', "D", &do_cmd_O(@_)); } sub do_cmd_var { local($_) = @_; local($arg); s/$next_pair_pr_rx/$arg = $2; ''/eo; join ('', "", $arg, "", $_); } sub do_cmd_urlpair{ local($_) = @_; local($url); s/$next_pair_pr_rx/$url = $2; ''/eo; join('',do {qq/$url<\/A><\/tt>/;},$_); } sub do_cmd_urlbibfield{ local($_) = @_; local($url); s/$next_pair_pr_rx/$url = $2; ''/eo; # if (m/$next_pair_pr_rx/o) { # $url = $2; # $_ = substr ($_, length ($&)); # } $url =~ s/\n//; join('',do {qq/$url<\/A><\/tt>/;},$_); } sub do_cmd_eqnref { local($_) = @_; local($foo); $foo = join ('', "(", &process_ref($cross_ref_mark,$cross_ref_mark)); $foo =~ s/<\/A>/<\/A>)/; $foo; } &ignore_commands( <<_IGNORED_CMDS_); filbreak almostfilbreak newline penalty0 scriptscriptstyle marginnote # {} begingroup endgroup fmfcmd # {} hbox raggedright raggedbottom _IGNORED_CMDS_ &process_commands_in_tex ( <<_RAW_ARG_CMDS_); chem # {} metcal chisq ensuremath # {} fiso eftot met deteta et dedx efem pt pbar mht aplan progname # {} _RAW_ARG_CMDS_ ################################################################################## # # Handle feynmf # sub do_env_fmffile { local ($_) = @_; if (s/$next_pair_rx//) { local ($fmffile) = $2; $latex_body .= "\\begin{fmffile}{$fmffile}\n"; system ("cp ../$fmffile.* ."); } $_; } sub do_cmd_end { local($_) = @_; if ((s/$next_pair_pr_rx//) && ($2 eq "fmffile")) { $latex_body .= "\\end{fmffile}\n"; } $_; } ##$caption_rx = "\\\\caption\\s*([[]\\s*((($any_next_pair_rx5)|([[][^]]*[]])|[^]])*)[]])?$O(\\d+)$C([\\s\\S]*)$O\\8$C[\n]?"; ################################################################################## # # Make mcites work like cites. # sub do_cmd_mcite { local($_) = @_; local($labelstr, $id); s/$next_pair_pr_rx//eo; $labelstr = $2; $id = $1; $labelstr =~ s/\*//; join ('', "\\cite$OP$id$CP", $labelstr, "$OP$id$CP", $_); } ################################################################################## # # Squelch the spurious comma which latex2html introduces after the # optional citation text. # # This just creates a link from a label (yet to be determined) to the # cite_key in the citation file. sub do_cmd_cite { local($_) = @_; local($cite_key, @cite_keys); local($optional_text,$dummy) = &get_next_optional_argument; ### $optional_text .= "," if $optional_text; s/^\s*\\space//o; # Hack - \space is inserted in .aux s/$next_pair_pr_rx//o; if ($cite_key = $2) { @cite_keys = (split(/,/,$cite_key)); #Replace the keys... grep(do { s/\W//g; $_ = "#$_#$cite_mark#$bbl_nr#";}, @cite_keys); $optional_text = ", $optional_text" if $optional_text; $_ = join('', "[", join(',',@cite_keys), $optional_text, "]", $_); } else {print "Cannot find citation argument\n";} $_; } ################################################################################## # # Address info. # $ADDRESS = "$address_data[0]\n$address_data[1]<\/EM>"; $INFO = join('', "$t_title

\n", "This document was generated using the ", "LaTeX2HTML", " translator Version $TEX2HTMLVERSION Copyright © 1993, 1994,", " Nikos Drakos,", " Computer Based Learning Unit, University of Leeds.

\n", "With local hacks by sss.

\n", " The command line arguments were:
", "latex2html $argv.

", "The translation was initiated by $address_data[0] on $address_data[1]"); system "cp ../local.perl ."; ################################################################################## # # LaTeX2html doesn't expand input's in .aux files, such are are produced # if the document is segmented with \include. # Redefine process_ext_file to expand those `by hand'. # sub read_ext_file { local($fname) = @_; local($found) = 0; print "\nReading $fname ..."; local($file) = &fulltexpath("$fname"); $global{'warnings'} .= "\n$FILE.tex is newer than $fname: Please rerun latex" . (($fname =~ /.*\.bbl/) ? " and bibtex.\n" : ".\n") if ( ($found = (-f $file)) && &newer(&fulltexpath("$FILE.tex"), $file)); if ( $found ) { &slurp_input($file); } $found; } sub expand_ext_includes { local($save) = $_; $save =~ s/\\\@input{(.*)}/&read_ext_file($1); $_/eog; $_ = $save; } sub process_ext_file { local($ext) = @_; local($found) = 0; $found = &read_ext_file("$FILE.$ext"); if ( $found ) { &expand_ext_includes; &pre_process; # Hack: get rid of the contents of any \@setckpt's. # Otherwise, any \setcounter's they contain will end up at the # start of images.tex and screw up the numbering. s/\\\@setckpt$any_next_pair_rx()$any_next_pair_rx4//go; &substitute_meta_cmds if /$meta_cmd_rx/; &wrap_shorthand_environments; $_ = &translate_commands(&translate_environments($_)); }; $found; } ################################################################################## # # Modify this latex2html routine so more forms of equation can be translated # directly into html, rather than changing them to bitmaps. # sub translate_math_hack { local($s) = @_; &translate_environments (&make_new_math_wrap ($s)); } sub special_env { local($unit); local($changed) = 0; local($not_really_changed) = 0; local($savemat); local($pat) = "^\\\$[\\s%]*" . $any_next_pair_rx . "\\\$"; # Modifies $contents in its caller $changed = ($contents =~ s/^\$(\s*([\d\.]+)\s*)\$/$1/igo || $contents =~ s/^\$(\s*([a-zA-Z]+)\s*)\$/$1<\/i>/igo || $contents =~ s/^\$(\s*($html_specials_inv_rx|[\da-z<>|=\-+,\s])+\s*)\$/$1/igo || # Local idioms. $contents =~ s/^\$\s*([\d\.]+)\s*\\%\s*\$/$1\\%/igo || $contents =~ s/^\$\s*\\jets\s*\$/jets/igo || $contents =~ s/^\$\s*([\d\.]+)\s*\\(gev|gevc|gevcc|mev|kev|tev|Hz|m|s|cm|MHz|mm|kV|ns|kHz|MB|gev\/c|um|us|ps|pb)\s*\$/$savemat=$1;$unit=&translate_unit($2);"$savemat $unit"/igoe || # Strip off braces surrounding the entire expression. $contents =~ s/$pat/$unit=&translate_math_hack($2);"$unit"/igoe || $contents =~ s/^\$\s*(|[^{}<>\$]*[^^])\s*([\/=+-]|;SPM_(lt|gt);|\\pm |\\approx |\\rightarrow )\s*([^{}<>\$]*)\s*\$/$unit=&hack_relation($1,$2,$4);"$unit"/igoe ); if ($not_really_changed) { $changed = 0; } $changed; } sub translate_unit { local($unit) = @_; local($newunit); if ($unit eq "gev") { $newunit = "GeV"; } elsif ($unit eq "mev") { $newunit = "MeV"; } elsif ($unit eq "kev") { $newunit = "keV"; } elsif ($unit eq "tev") { $newunit = "TeV"; } elsif ($unit eq "gev/c") { $newunit = "GeV/c"; } elsif ($unit eq "gevc") { $newunit = "GeV/c"; } elsif ($unit eq "gevcc") { $newunit = ("GeV/" . &make_new_math_wrap("c^2")); $newunit = &translate_environments ($newunit); } elsif ($unit eq "us" || $unit eq "um") { $newunit = (&make_new_math_wrap("\\mu") . substr ($unit, 1)); $newunit = &translate_environments ($newunit); } else { $newunit = $unit; } $newunit; } sub is_cached { local($x) = @_; $x = "\\begin{tex2html_wrap_inline}\$$x\$\\end{tex2html_wrap_inline}"; $cached_env_img{&encode($x)}; } $likely_to_expand_rx = "^\\s*([\\d\\.]+\\s*(\\\\gev|\\\\gevcc|\\\\pb|\\\\%)?|[a-zA-Z]+)\\s*\$"; sub hack_relation { local($lhs, $rel, $rhs) = @_; if (($lhs || $rhs) && ($lhs =~ /$likely_to_expand_rx/o || $rhs =~ /$likely_to_expand_rx/o || &is_cached($lhs) || &is_cached($rhs))) { # A bit of a gamble, this. if ($rel =~ /^\\/) { $rel = join ('', &make_math_beg_wrapper, $rel, &make_math_end_wrapper); } local($new) = ""; if (!($lhs eq "")) { $new = join ('', $new, &make_math_beg_wrapper, $lhs, &make_math_end_wrapper); } $new = $new . " $rel "; if (!($rhs eq "")) { $new = join ('', $new, &make_math_beg_wrapper, $rhs, &make_math_end_wrapper); } &translate_environments ($new); } else { $not_really_changed = 1; join ('', '$', $lhs, $rel, $rhs, '$'); } } sub make_new_math_wrap { local($stuff) = @_; local($wrapper) = "tex2html_wrap_inline"; join ('', &make_math_beg_wrapper, $stuff, &make_math_end_wrapper); } sub make_math_beg_wrapper { &make_any_wrapper(1,"tex2html_wrap_inline") . '$'; } sub make_math_end_wrapper { '$' . &make_any_wrapper(0,"tex2html_wrap_inline"); } ################################################################################## # # These patches to latex2html cause it to reuse images for duplicated # equations within a document, rather than generating a separate image # for each. # sub process_undefined_environment { local($env, $id, $contents) = @_; local($name,$cached,$raw_contents,$uucontents) = ("$env$id"); $contents = "% latex2html id marker $id\n$contents" if $contents =~ /$order_sensitive_rx/; $contents = "\\begin{$env}$contents\\end{$env}"; $latex_body{$name} = $contents; $uucontents = &encode($contents); if ($NOLATEX) { $id_map{$name} = "[$name]";} elsif ($cached = $cached_env_img{$uucontents}) { if ($cached =~ /(img\d+)\.gif/ && -r "$1.old") { ++$global_page_num; ($cached =~ s/(img\d+)\.gif/img$global_page_num.gif/o); rename("$1.old", "img$global_page_num.gif"); $cached_env_img{$uucontents} = $cached; } if (! defined $id_map{$name}) { $id_map{$name} = $cached; #!1$orig_name_map{$new_id_map{$name}} = $cached; } } else { &clear_images_dbm_database unless $new_page_num; $new_id_map{$name} = $id_map{$name} = ++$global_page_num . "#" . ++$new_page_num; $orig_name_map{$id_map{$name}} = $name; $img_params{$name} = join('#', &extract_parameters($contents)); $raw_contents = &revert_to_raw_tex($contents); if ($env =~ /inline/) { $raw_contents = &make_box("$name", $raw_contents); } $raw_contents =~ s/\\pagebreak/\\\\/go; $latex_body .= "{\\newpage\n\\clearpage\n\\samepage $raw_contents\n}\n\n"; $cached_env_img{$uucontents} = "sameas_$name"; } &do_labels($contents,"$image_mark#$name#"); # Anchor the labels and put a marker in the text; } sub make_images { local($name, $contents, $raw_contents, $uucontents, $page_num, $uucontents, %page_map, $img); # It is necessary to run LaTeX this early because we need the log file # which contains information used to determine equation alignment if ( $latex_body =~ /newpage/) { print "\n"; system("$LATEX images.tex"); &process_log_file("images.log"); # Get eqn size info } if ($NO_IMAGES) { system("cp $LATEX2HTMLDIR/icons/image.gif .") if (-e "$LATEX2HTMLDIR/icons/image.gif") } elsif ((!$NOLATEX) && ($latex_body =~ /newpage/)) { print "\nGenerating postscript images using dvips ...\n"; system("$DVIPS -M -S 1 -i -o $$\_image images.dvi") && print "Error: $!\n"; open(IMAGE, "echo $$\_image* | tr -s ' \t\r\f' '\\012\\012\\012\\012'|"); while () {chop; rename($_, "$_.ps") if /\d\d\d$/}; } while ( ($name, $page_num) = each %id_map) { $contents = $latex_body{$name}; if ($page_num =~ /sameas_(.*)/) { # Defer } elsif ($page_num =~ /^\d+\#\d+$/) { # If it is a page number do { # Extract the page, convert and save it $img = &extract_image($page_num,$orig_name_map{$page_num}); $uucontents = &encode($contents); # Arrggh if (! ($contents =~ /$order_sensitive_rx/)) { $cached_env_img{$uucontents} = $img; } else { # Blow it away so it is not saved for next time delete $cached_env_img{$uucontents} } $page_map{$page_num} = $img; } unless ($img = $page_map{$page_num}); # unless we've just done it $id_map{$name} = $img; } else { $img = $page_num;}} # it is already available from previous runs while ( ($name, $page_num) = each %id_map) { if ($page_num =~ /sameas_(.*)/) { $id_map{$name} = $id_map{$1}; } } $global{'warnings'} .= "\nOne of the images is more than one page long.\n". "This may cause the rest of the images to get out of sync.\n\n" if (-f sprintf("%s%.3d%s", "$$\_image", ++$new_page_num, ".ps")); &cleanup; } ################################################################################## # # If a figure contains multiple captions, put them out in the correct order. # sub extract_captions { # Uses and modifies $contents defined in translate_environments # and modifies $figure_captions, $table_captions, $before and $after local($env) = @_; local(%captions, %optional_captions, $key, $caption, $optional_caption, $item, $type, $list, $number, @tmp, $_); # associate the br_id of the caption with the argument of the caption $contents =~ s/$caption_rx/do { $optional_captions{$8} = ($2 ? $2 : $9); $captions{$8} = $9; ''}/ego; $after = join("","

",$after); $before .= "

"; if ($env eq 'figure') { $type = "Figure"; $list = "\$figure_captions"; } elsif ($env eq 'table') { $type = "Table"; $list = "\$table_captions"; } foreach $key (sort {$b <=> $a;} keys %captions){ # Sort numerically $caption = &translate_commands(&translate_environments($captions{$key})); $optional_caption = &translate_commands(&translate_environments($optional_captions{$key})); $item .= "

  • " . &make_href("$CURRENT_FILE#$key", $caption) . "\n"; $before .= "$anchor_mark"; $_ = ($optional_caption || $caption); &text_cleanup; &replace_cross_references if /$cross_ref_mark/; $_ = &encode_title($_); @tmp = split(/$;/, eval ("\$encoded_$env" . "_number{\$_}")); $number = shift(@tmp); $number = "" if ($number eq "-1"); $warnings .= "No number for \"$caption\"\n" if (! $number); eval("\$encoded_$env" . "_number{\$_} = join(\$;, \@tmp)"); undef $_; undef @tmp; $after = join("", "\n
    $type", ($number ? " $number:" : ":"), " $caption
    \n", $after); } eval "$list .= \$item"; } # Handle my `captionplus' macro. { local($id) = ++$global{'max_id'}; $new_command{"captionplus"} = "2:!:\\caption[#1]$O$id$C#1 #2$O$id$C"; } ################################################################################## # # latex2html will nuke inlined math in section titles. # But i use math in some section headings, so i don't really want that to happen. # Try removing the call to extract_pure_text from here. This sort of works, # but of course the inlined bitmaps are not bolded/scaled up to match the # style of the section headings. Still better than nothing, though. # sub do_cmd_section_helper { local($H,$key) = @_; local($section_number, @tmp); # if we have a $key the current section is not of the *-form, so we need # to update the counters. do { $latex_body .= "\\stepcounter{$key}\n"; } if $key; # Ignore optional toc entry local($_) = $after; &get_next_optional_argument; $after = $_; $after =~ s/$next_pair_rx/do {$TITLE = $2; ''}/eo; $TITLE =~ s/\\(label|index)$any_next_pair_rx//; $TITLE = &translate_commands(&translate_environments($TITLE)); $_ = $TITLE; ##&extract_pure_text; $TITLE = $_ ; # This is the LaTeX section number read from the $FILE.aux file @tmp = split(/$;/,$encoded_section_number{&encode_title($_)}); $section_number = shift(@tmp); $section_number = "" if ($section_number eq "-1"); $encoded_section_number{&encode_title($_)} = join($;, @tmp); $TITLE = "$section_number " . $_; $after = join('', &make_section_heading($TITLE, $H), $after); $TITLE =~ s/

    //g; # Remove newlines $after;} 1;