home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / zkuste / Perl / ActivePerl-5.6.0.613.msi / 䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥 / _7e6299289f1826c023e4684143010a40 < prev    next >
Encoding:
Text File  |  2000-03-24  |  23.1 KB  |  690 lines

  1. @rem = '--*-Perl-*--
  2. @echo off
  3. if "%OS%" == "Windows_NT" goto WinNT
  4. perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
  5. goto endofperl
  6. :WinNT
  7. perl -x -S "%0" %*
  8. if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
  9. if %errorlevel% == 9009 echo You do not have Perl in your PATH.
  10. if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
  11. goto endofperl
  12. @rem ';
  13. #!perl
  14. #line 15
  15.     eval 'exec D:\p4-view\main\Apps\Gecko\MSI\data\ActivePerl\Perl\bin\perl.exe -S $0 ${1+"$@"}'
  16.     if $running_under_some_shell;
  17. #
  18. # pod2latex, version 1.1
  19. # by Taro Kawagish (kawagish@imslab.co.jp),  Jan 11, 1995.
  20. #
  21. # pod2latex filters Perl pod documents to LaTeX documents.
  22. #
  23. # What pod2latex does:
  24. # 1. Pod file 'perl_doc_entry.pod' is filtered to 'perl_doc_entry.tex'.
  25. # 2. Indented paragraphs are translated into
  26. #    '\begin{verbatim} ... \end{verbatim}'.
  27. # 3. '=head1 heading' command is translated into '\section{heading}'
  28. # 4. '=head2 heading' command is translated into '\subsection*{heading}'
  29. # 5. '=over N' command is translated into
  30. #        '\begin{itemize}'    if following =item starts with *,
  31. #        '\begin{enumerate}'    if following =item starts with 1.,
  32. #        '\begin{description}'    if else.
  33. #      (indentation level N is ignored.)
  34. # 6. '=item * heading' command is translated into '\item heading',
  35. #    '=item 1. heading' command is translated into '\item heading',
  36. #    '=item heading' command(other) is translated into '\item[heading]'.
  37. # 7. '=back' command is translated into
  38. #        '\end{itemize}'    if started with '\begin{itemize}',
  39. #        '\end{enumerate}'    if started with '\begin{enumerate}',
  40. #        '\end{description}'    if started with '\begin{description}'.
  41. # 8. other paragraphs are translated into strings with TeX special characters
  42. #    escaped.
  43. # 9. In heading text, and other paragraphs, the following translation of pod
  44. #    quotes are done, and then TeX special characters are escaped after that.
  45. #      I<text> to {\em text\/},
  46. #      B<text> to {\bf text},
  47. #      S<text> to text1,
  48. #        where text1 is a string with blank characters replaced with ~,
  49. #      C<text> to {\tt text2},
  50. #        where text2 is a string with TeX special characters escaped to
  51. #        obtain a literal printout,
  52. #      E<text> (HTML escape) to TeX escaped string,
  53. #      L<text> to referencing string as is done by pod2man,
  54. #      F<file> to {\em file\/},
  55. #      Z<> to a null string,
  56. # 10. those headings are indexed:
  57. #       '=head1 heading'   =>  \section{heading}\index{heading}
  58. #       '=head2 heading'   =>  \subsection*{heading}\index{heading}
  59. #                 only when heading does not match frequent patterns such as
  60. #                 DESCRIPTION, DIAGNOSTICS,...
  61. #       '=item heading'   =>  \item{heading}\index{heading}
  62. #
  63. # Usage:
  64. #     pod2latex perl_doc_entry.pod
  65. # this will write to a file 'perl_doc_entry.tex'.
  66. #
  67. # To LaTeX:
  68. # The following commands need to be defined in the preamble of the LaTeX
  69. # document:
  70. # \def\C++{{\rm C\kern-.05em\raise.3ex\hbox{\footnotesize ++}}}
  71. # \def\underscore{\leavevmode\kern.04em\vbox{\hrule width 0.4em height 0.3pt}}
  72. # and \parindent should be set zero:
  73. # \setlength{\parindent}{0pt}
  74. #
  75. # Note:
  76. # This script was written modifing pod2man.
  77. #
  78. # Bug:
  79. # If HTML escapes E<text> other than E<amp>,E<lt>,E<gt>,E<quot> are used
  80. # in C<>, translation will produce wrong character strings.
  81. # Translation of HTML escapes of various European accents might be wrong.
  82.  
  83.  
  84. # TeX special characters.
  85. ##$tt_ables = "!@*()-=+|;:'\"`,./?<>";
  86. $backslash_escapables = "#\$%&{}_";
  87. $backslash_escapables2 = "#\$%&{}";    # except _
  88. ##$nonverbables = "^\\~";
  89. ##$bracketesc = "[]";
  90. ##@tex_verb_fences = unpack("aaaaaaaaa","|#@!*+?:;");
  91.  
  92. @head1_freq_patterns        # =head1 patterns which need not be index'ed
  93.     = ("AUTHOR","Author","BUGS","DATE","DESCRIPTION","DIAGNOSTICS",
  94.        "ENVIRONMENT","EXAMPLES","FILES","INTRODUCTION","NAME","NOTE",
  95.        "SEE ALSO","SYNOPSIS","WARNING");
  96.  
  97. $indent = 0;
  98.  
  99. # parse the pods, produce LaTeX.
  100.  
  101. use Pod::Plainer;
  102. open(POD,"-|") or Pod::Plainer -> new() -> parse_from_file($ARGV[0]), exit;
  103.  
  104. ($pod=$ARGV[0]) =~ s/\.pod$//;
  105. open(LATEX,">$pod.tex");
  106. &do_hdr();
  107.  
  108. $cutting = 1;
  109. $begun = "";
  110. $/ = "";            # record separator is blank lines
  111. while (<POD>) {
  112.     if ($cutting) {
  113.     next unless /^=/;
  114.     $cutting = 0;
  115.     }
  116.     if ($begun) {
  117.        if (/^=end\s+$begun/) {
  118.            $begun = "";
  119.        }
  120.        elsif ($begun =~ /^(tex|latex)$/) {
  121.            print LATEX $_;
  122.        }
  123.        next;
  124.     }
  125.     chop;
  126.     length || (print LATEX  "\n") && next;
  127.  
  128.     # translate indented lines as a verabatim paragraph
  129.     if (/^\s/) {
  130.     @lines = split(/\n/);
  131.     print LATEX  "\\begin{verbatim}\n";
  132.     for (@lines) {
  133.         1 while s
  134.         {^( [^\t]* ) \t ( \t* ) }
  135.         { $1 . ' ' x (8 - (length($1)%8) + 8*(length($2))) }ex;
  136.         print LATEX  $_,"\n";
  137.     }
  138.     print LATEX  "\\end{verbatim}\n";
  139.     next;
  140.     }
  141.  
  142.     if (/^=for\s+(\S+)\s*/s) {
  143.     if ($1 eq "tex" or $1 eq "latex") {
  144.         print LATEX $',"\n";
  145.     } else {
  146.         # ignore unknown for
  147.     }
  148.     next;
  149.     }
  150.     elsif (/^=begin\s+(\S+)\s*/s) {
  151.     $begun = $1;
  152.     if ($1 eq "tex" or $1 eq "latex") {
  153.         print LATEX $'."\n";
  154.     }
  155.     next;
  156.     }
  157.  
  158.     # preserve '=item' line with pod quotes as they are.
  159.     if (/^=item/) {
  160.     ($bareitem = $_) =~ s/^=item\s*//;
  161.     }
  162.  
  163.     # check for things that'll hosed our noremap scheme; affects $_
  164.     &init_noremap();
  165.  
  166.     # expand strings "func()" as pod quotes.
  167.     if (!/^=item/) {
  168.     # first hide pod escapes.
  169.     # escaped strings are mapped into the ones with the MSB's on.
  170.     s/([A-Z]<[^<>]*>)/noremap($1)/ge;
  171.  
  172.     # func() is a reference to a perl function
  173.     s{\b([:\w]+\(\))}{I<$1>}g;
  174.     # func(n) is a reference to a man page
  175.     s{(\w+)(\([^\s,\051]+\))}{I<$1>$2}g;
  176.     # convert simple variable references
  177. #    s/([\$\@%][\w:]+)/C<$1>/g;
  178. #    s/\$[\w:]+\[[0-9]+\]/C<$&>/g;
  179.  
  180.     if (m{ ([\-\w]+\([^\051]*?[\@\$,][^\051]*?\))
  181.            }x && $` !~ /([LCI]<[^<>]*|-)$/ && !/^=\w/)
  182.     {
  183.         warn "``$1'' should be a [LCI]<$1> ref";
  184.     }
  185.     while (/(-[a-zA-Z])\b/g && $` !~ /[\w\-]$/) {
  186.         warn "``$1'' should be [CB]<$1> ref";
  187.     }
  188.  
  189.     # put back pod quotes so we get the inside of <> processed;
  190.     $_ = &clear_noremap($_);
  191.     }
  192.  
  193.  
  194.     # process TeX special characters
  195.  
  196.     # First hide HTML quotes E<> since they can be included in C<>.
  197.     s/(E<[^<>]+>)/noremap($1)/ge;
  198.  
  199.     # Then hide C<> type literal quotes.
  200.     # String inside of C<> will later be expanded into {\tt ..} strings
  201.     # with TeX special characters escaped as needed.
  202.     s/(C<[^<>]*>)/&noremap($1)/ge;
  203.  
  204.     # Next escape TeX special characters including other pod quotes B< >,...
  205.     #
  206.     # NOTE: s/re/&func($str)/e evaluates $str just once in perl5.
  207.     # (in perl4 evaluation takes place twice before getting passed to func().)
  208.  
  209.     # - hyphen => ---
  210.     s/(\S+)(\s+)-+(\s+)(\S+)/"$1".&noremap(" --- ")."$4"/ge;
  211.     # '-', '--', "-"  =>  '{\tt -}', '{\tt --}', "{\tt -}"
  212. ##    s/("|')(\s*)(-+)(\s*)\1/&noremap("$1$2\{\\tt $3\}$4$1")/ge;
  213. ## changed Wed Jan 25 15:26:39 JST 1995
  214.     # '-', '--', "-"  =>  '$-$', '$--$', "$-$"
  215.     s/(\s+)(['"])(-+)([^'"\-]*)\2(\s+|[,.])/"$1$2".&noremap("\$$3\$")."$4$2$5"/ge;
  216.     s/(\s+)(['"])([^'"\-]*)(-+)(\s*)\2(\s+|[,.])/"$1$2$3".&noremap("\$$4\$")."$5$2$6"/ge;
  217.     # (--|-)  =>  ($--$|$-$)
  218.     s/(\s+)\((-+)([=@%\$\+\\\|\w]*)(-*)([=@%\$\+\\\|\w]*)\)(\s+|[,.])/"$1\(".&noremap("\$$2\$")."$3".&noremap("\$$4\$")."$5\)$6"/ge;
  219.     # numeral -  =>  $-$
  220.     s/(\(|[0-9]+|\s+)-(\s*\(?\s*[0-9]+)/&noremap("$1\$-\$$2")/ge;
  221.     # -- in quotes  =>  two separate -
  222.     s/B<([^<>]*)--([^<>]*)>/&noremap("B<$1\{\\tt --\}$2>")/ge;
  223.  
  224.     # backslash escapable characters except _.
  225.     s/([$backslash_escapables2])/&noremap("\\$1")/ge;
  226.     s/_/&noremap("\\underscore{}")/ge;        # a litle thicker than \_.
  227.     # quote TeX special characters |, ^, ~, \.
  228.     s/\|/&noremap("\$|\$")/ge;
  229.     s/\^/&noremap("\$\\hat{\\hspace{0.4em}}\$")/ge;
  230.     s/\~/&noremap("\$\\tilde{\\hspace{0.4em}}\$")/ge;
  231.     s/\\/&noremap("\$\\backslash{}\$")/ge;
  232.     # quote [ and ] to be used in \item[]
  233.     s/([\[\]])/&noremap("{\\tt $1}")/ge;
  234.     # characters need to be treated differently in TeX
  235.     # keep * if an item heading
  236.     s/^(=item[ \t]+)[*]((.|\n)*)/"$1" . &noremap("*") . "$2"/ge;
  237.     s/[*]/&noremap("\$\\ast\$")/ge;    # other *
  238.  
  239.     # hide other pod quotes.
  240.     s/([ABD-Z]<[^<>]*>)/&noremap($1)/ge;
  241.  
  242.     # escape < and > as math strings,
  243.     # now that we are done with hiding pod <> quotes.
  244.     s/</&noremap("\$<\$")/ge;
  245.     s/>/&noremap("\$>\$")/ge;
  246.  
  247.     # put it back so we get the <> processed again;
  248.     $_ = &clear_noremap($_);
  249.  
  250.  
  251.     # Expand pod quotes recursively:
  252.     # (1) type face directives [BIFS]<[^<>]*> to appropriate TeX commands,
  253.     # (2) L<[^<>]*> to reference strings,
  254.     # (3) C<[^<>]*> to TeX literal quotes,
  255.     # (4) HTML quotes E<> inside of C<> quotes.
  256.  
  257.     # Hide E<> again since they can be included in C<>.
  258.     s/(E<[^<>]+>)/noremap($1)/ge;
  259.  
  260.     $maxnest = 10;
  261.     while ($maxnest-- && /[A-Z]</) {
  262.  
  263.     # bold and italic quotes
  264.     s/B<([^<>]*)>/"{\\bf $1}"/eg;
  265.     s#I<([^<>]*)>#"{\\em $1\\/}"#eg;
  266.  
  267.     # files and filelike refs in italics
  268.     s#F<([^<>]*)>#"{\\em $1\\/}"#eg;
  269.  
  270.     # no break quote -- usually we want C<> for this
  271.     s/S<([^<>]*)>/&nobreak($1)/eg;
  272.  
  273.     # LREF: a manpage(3f)
  274.     s:L<([a-zA-Z][^\s\/]+)(\([^\)]+\))?>:the {\\em $1\\/}$2 manpage:g;
  275.  
  276.     # LREF: an =item on another manpage
  277.     s{
  278.         L<([^/]+)/([:\w]+(\(\))?)>
  279.     } {the C<$2> entry in the I<$1> manpage}gx;
  280.  
  281.     # LREF: an =item on this manpage
  282.     s{
  283.        ((?:L</([:\w]+(\(\))?)>
  284.         (,?\s+(and\s+)?)?)+)
  285.     } { &internal_lrefs($1) }gex;
  286.  
  287.     # LREF: a =head2 (head1?), maybe on a manpage, maybe right here
  288.     # the "func" can disambiguate
  289.     s{
  290.         L<(?:([a-zA-Z]\S+?) /)?"?(.*?)"?>
  291.     }{
  292.         do {
  293.         $1     # if no $1, assume it means on this page.
  294.             ?  "the section on I<$2> in the I<$1> manpage"
  295.             :  "the section on I<$2>"
  296.         } 
  297.     }gex;
  298.  
  299.     s/X<([^<>]*)>/\\index{$1}/g;
  300.  
  301.     s/Z<>/\\&/g;        # the "don't format me" thing
  302.  
  303.     # comes last because not subject to reprocessing
  304.     s{
  305.         C<([^<>]*)>
  306.     }{
  307.         do {
  308.         ($str = $1) =~ tr/\200-\377/\000-\177/; #normalize hidden stuff
  309.         # expand HTML escapes if any;
  310.         # WARNING: if HTML escapes other than E<amp>,E<lt>,E<gt>,
  311.         # E<quot> are in C<>, they will not be printed correctly.
  312.         $str = &expand_HTML_escapes($str);
  313.         $strverb = &alltt($str);    # Tex verbatim escape of a string.
  314.         &noremap("$strverb");
  315.         }
  316.     }gex;
  317.  
  318. #    if ( /C<([^<>]*)/ ) {
  319. #        $str = $1;
  320. #        if ($str !~ /\|/) {        # if includes |
  321. #        s/C<([^<>]*)>/&noremap("\\verb|$str|")/eg;
  322. #        } else {
  323. #        print STDERR "found \| in C<.*> at paragraph $.\n";
  324. #        # find a character not contained in $str to use it as a
  325. #        # separator of the \verb
  326. #        ($chars = $str) =~ s/(\W)/\\$1/g;
  327. #        ## ($chars = $str) =~ s/([\$<>,\|"'\-^{}()*+?\\])/\\$1/g;
  328. #        @fence = grep(!/[ $chars]/,@tex_verb_fences);
  329. #        s/C<([^<>]*)>/&noremap("\\verb$fence[0]$str$fence[0]")/eg;
  330. #        }
  331. #    }
  332.     }
  333.  
  334.  
  335.     # process each pod command
  336.     if (s/^=//) {                # if a command
  337.     s/\n/ /g;
  338.     ($cmd, $rest) = split(' ', $_, 2);
  339.     $rest =~ s/^\s*//;
  340.     $rest =~ s/\s*$//;
  341.  
  342.     if (defined $rest) {
  343.         &escapes;
  344.     }
  345.  
  346.     $rest = &clear_noremap($rest);
  347.     $rest = &expand_HTML_escapes($rest);
  348.  
  349.     if ($cmd eq 'cut') {
  350.         $cutting = 1;
  351.         $lastcmd = 'cut';
  352.     }
  353.     elsif ($cmd eq 'head1') {    # heading type 1
  354.         $rest =~ s/^\s*//; $rest =~ s/\s*$//;
  355.         print LATEX  "\n\\subsection*{$rest}";
  356.         # put index entry
  357.         ($index = $rest) =~ s/^(An?\s+|The\s+)//i;    # remove 'A' and 'The'
  358.         # index only those heads not matching the frequent patterns.
  359.         foreach $pat (@head1_freq_patterns) {
  360.         if ($index =~ /^$pat/) {
  361.             goto freqpatt;
  362.         }
  363.         }
  364.         print LATEX  "%\n\\index{$index}\n" if ($index);
  365.       freqpatt:
  366.         $lastcmd = 'head1';
  367.     }
  368.     elsif ($cmd eq 'head2') {    # heading type 2
  369.         $rest =~ s/^\s*//; $rest =~ s/\s*$//;
  370.         print LATEX  "\n\\subsubsection*{$rest}";
  371.         # put index entry
  372.         ($index = $rest) =~ s/^(An?\s+|The\s+)//i;    # remove 'A' and 'The'
  373.         $index =~ s/^Example\s*[1-9][0-9]*\s*:\s*//; # remove 'Example :'
  374.         print LATEX  "%\n\\index{$index}\n"  if ($index);
  375.         $lastcmd = 'head2';
  376.     }
  377.     elsif ($cmd eq 'over') {    # 1 level within a listing environment
  378.         push(@indent,$indent);
  379.         $indent = $rest + 0;
  380.         $lastcmd = 'over';
  381.     }
  382.     elsif ($cmd eq 'back') {    # 1 level out of a listing environment
  383.         $indent = pop(@indent);
  384.         warn "Unmatched =back\n" unless defined $indent;
  385.         $listingcmd = pop(@listingcmd);
  386.         print LATEX  "\n\\end{$listingcmd}\n"  if ($listingcmd);
  387.         $lastcmd = 'back';
  388.     }
  389.     elsif ($cmd eq 'item') {    # an item paragraph starts
  390.         if ($lastcmd eq 'over') {    # if we have just entered listing env
  391.         # see what type of list environment we are in.
  392.         if ($rest =~ /^[0-9]\.?/) {    # if numeral heading
  393.             $listingcmd = 'enumerate';
  394.         } elsif ($rest =~ /^\*\s*/) {    # if * heading
  395.             $listingcmd = 'itemize';
  396.         } elsif ($rest =~ /^[^*]/) {    # if other headings
  397.             $listingcmd = 'description';
  398.         } else {
  399.             warn "unknown list type for item $rest";
  400.         }
  401.         print LATEX  "\n\\begin{$listingcmd}\n";
  402.         push(@listingcmd,$listingcmd);
  403.         } elsif ( !@listingcmd ) { 
  404.         warn "Illegal '=item' command without preceding 'over':";
  405.         warn "=item $bareitem";
  406.         }
  407.  
  408.         if ($listingcmd eq 'enumerate') {
  409.         $rest =~ s/^[0-9]+\.?\s*//;    # remove numeral heading
  410.         print LATEX  "\n\\item";
  411.         print LATEX  "{\\bf $rest}" if $rest;
  412.         } elsif ($listingcmd eq 'itemize') {
  413.         $rest =~ s/^\*\s*//;        # remove * heading
  414.         print LATEX  "\n\\item";
  415.         print LATEX  "{\\bf $rest}" if $rest;
  416.         } else {                # description item
  417.         print LATEX  "\n\\item[$rest]";
  418.         }
  419.         $lastcmd = 'item';
  420.         $rightafter_item = 'yes';
  421.  
  422.         # check if the item heading is short or long.
  423.         ($itemhead = $rest) =~ s/{\\bf (\S*)}/$1/g;
  424.         if (length($itemhead) < 4) {
  425.         $itemshort = "yes";
  426.         } else {
  427.         $itemshort = "no";
  428.         }
  429.         # write index entry
  430.         if ($pod =~ "perldiag") {            # skip 'perldiag.pod'
  431.         goto noindex;
  432.         }
  433.         # strip out the item of pod quotes and get a plain text entry
  434.         $bareitem =~ s/\n/ /g;            # remove newlines
  435.         $bareitem =~ s/\s*$//;            # remove trailing space
  436.         $bareitem =~ s/[A-Z]<([^<>]*)>/$1/g;    # remove <> quotes
  437.         ($index = $bareitem) =~ s/^\*\s+//;        # remove leading '*'
  438.         $index =~ s/^(An?\s+|The\s+)//i;        # remove 'A' and 'The'
  439.         $index =~ s/^\s*[1-9][0-9]*\s*[.]\s*$//; # remove numeral only
  440.         $index =~ s/^\s*\w\s*$//;            # remove 1 char only's
  441.         # quote ", @ and ! with " to be used in makeindex.
  442.         $index =~ s/"/""/g;                # quote "
  443.         $index =~ s/@/"@/g;                # quote @
  444.         $index =~ s/!/"!/g;                # quote !
  445.         ($rest2=$rest) =~ s/^\*\s+//;    # remove *
  446.         $rest2 =~ s/"/""/g;                # quote "
  447.         $rest2 =~ s/@/"@/g;                # quote @
  448.         $rest2 =~ s/!/"!/g;                # quote !
  449.         if ($pod =~ "(perlfunc|perlvar)") {    # when doc is perlfunc,perlvar
  450.         # take only the 1st word of item heading
  451.         $index =~ s/^([^{}\s]*)({.*})?([^{}\s]*)\s+.*/\1\2\3/;
  452.         $rest2 =~ s/^([^{}\s]*)({.*})?([^{}\s]*)\s+.*/\1\2\3/;
  453.         }
  454.         if ($index =~ /[A-Za-z\$@%]/) {
  455.             #  write  \index{plain_text_entry@TeX_string_entry}
  456.         print LATEX  "%\n\\index{$index\@$rest2}%\n";
  457.         }
  458.       noindex:
  459.         ;
  460.     }
  461.     elsif ($cmd eq 'pod') {
  462.         ;    # recognise the pod directive, as no op (hs)
  463.     }
  464.      elsif ($cmd eq 'pod') {
  465.          ;    # recognise the pod directive, as no op (hs)
  466.      }
  467.     else {
  468.         warn "Unrecognized directive: $cmd\n";
  469.     }
  470.     }
  471.     else {                    # if not command
  472.     &escapes;
  473.     $_ = &clear_noremap($_);
  474.     $_ = &expand_HTML_escapes($_);
  475.  
  476.     # if the present paragraphs follows an =item declaration,
  477.     # put a line break.
  478.     if ($lastcmd eq 'item' &&
  479.         $rightafter_item eq 'yes' && $itemshort eq "no") {
  480.         print LATEX  "\\hfil\\\\";
  481.         $rightafter_item = 'no';
  482.     }
  483.     print LATEX  "\n",$_;
  484.     }
  485. }
  486.  
  487. print LATEX  "\n";
  488. close(POD);
  489. close(LATEX);
  490.  
  491.  
  492. #########################################################################
  493.  
  494. sub do_hdr {
  495.     print LATEX "% LaTeX document produced by pod2latex from \"$pod.pod\".\n";
  496.     print LATEX "% The followings need be defined in the preamble of this document:\n";
  497.     print LATEX "%\\def\\C++{{\\rm C\\kern-.05em\\raise.3ex\\hbox{\\footnotesize ++}}}\n";
  498.     print LATEX "%\\def\\underscore{\\leavevmode\\kern.04em\\vbox{\\hrule width 0.4em height 0.3pt}}\n";
  499.     print LATEX "%\\setlength{\\parindent}{0pt}\n";
  500.     print LATEX "\n";
  501.     $podq = &escape_tex_specials("\U$pod\E");
  502.     print LATEX "\\section{$podq}%\n";
  503.     print LATEX "\\index{$podq}";
  504.     print LATEX "\n";
  505. }
  506.  
  507. sub nobreak {
  508.     my $string = shift;
  509.     $string =~ s/ +/~/g;        # TeX no line break
  510.     $string;
  511. }
  512.  
  513. sub noremap {
  514.     local($thing_to_hide) = shift;
  515.     $thing_to_hide =~ tr/\000-\177/\200-\377/;
  516.     return $thing_to_hide;
  517. }
  518.  
  519. sub init_noremap {
  520.     # escape high bit characters in input stream
  521.     s/([\200-\377])/"E<".ord($1).">"/ge;
  522. }
  523.  
  524. sub clear_noremap {
  525.     local($tmp) = shift;
  526.     $tmp =~ tr/\200-\377/\000-\177/;
  527.     return $tmp;
  528. }
  529.  
  530. sub expand_HTML_escapes {
  531.     local($s) = $_[0];
  532.     $s =~ s { E<((\d+)|([A-Za-z]+))> }
  533.     {
  534.     do {
  535.         defined($2) 
  536.         ? do { chr($2) }
  537.         : 
  538.         exists $HTML_Escapes{$3}
  539.         ? do { $HTML_Escapes{$3} }
  540.         : do {
  541.         warn "Unknown escape: $& in $_";
  542.         "E<$1>";
  543.         }
  544.     }
  545.     }egx;
  546.     return $s;
  547. }
  548.  
  549. sub escapes {
  550.     # make C++ into \C++, which is to be defined as
  551.     # \def\C++{{\rm C\kern-.05em\raise.3ex\hbox{\footnotesize ++}}}
  552.     s/\bC\+\+/\\C++{}/g;
  553. }
  554.  
  555. # Translate a string into a TeX \tt string to obtain a verbatim print out.
  556. # TeX special characters are escaped by \.
  557. # This can be used inside of LaTeX command arguments.
  558. # We don't use LaTeX \verb since it doesn't work inside of command arguments.
  559. sub alltt {
  560.     local($str) = shift;
  561.     # other chars than #,\,$,%,&,{,},_,\,^,~ ([ and ] included).
  562.     $str =~ s/([^${backslash_escapables}\\\^\~]+)/&noremap("$&")/eg;
  563.     # chars #,\,$,%,&,{,}  =>  \# , ...
  564.     $str =~ s/([$backslash_escapables2])/&noremap("\\$&")/eg;
  565.     # chars _,\,^,~  =>  \char`\_ , ...
  566.     $str =~ s/_/&noremap("\\char`\\_")/eg;
  567.     $str =~ s/\\/&noremap("\\char`\\\\")/ge;
  568.     $str =~ s/\^/\\char`\\^/g;
  569.     $str =~ s/\~/\\char`\\~/g;
  570.  
  571.     $str =~ tr/\200-\377/\000-\177/;        # put back
  572.     $str = "{\\tt ".$str."}";            # make it a \tt string
  573.     return $str;
  574. }
  575.  
  576. sub escape_tex_specials {
  577.     local($str) = shift;
  578.     # other chars than #,\,$,%,&,{,},  _,\,^,~ ([ and ] included).
  579.     # backslash escapable characters #,\,$,%,&,{,} except _.
  580.     $str =~ s/([$backslash_escapables2])/&noremap("\\$1")/ge;
  581.     $str =~ s/_/&noremap("\\underscore{}")/ge;    # \_ is too thin.
  582.     # quote TeX special characters |, ^, ~, \.
  583.     $str =~ s/\|/&noremap("\$|\$")/ge;
  584.     $str =~ s/\^/&noremap("\$\\hat{\\hspace{0.4em}}\$")/ge;
  585.     $str =~ s/\~/&noremap("\$\\tilde{\\hspace{0.4em}}\$")/ge;
  586.     $str =~ s/\\/&noremap("\$\\backslash{}\$")/ge;
  587.     # characters need to be treated differently in TeX
  588.     # *
  589.     $str =~ s/[*]/&noremap("\$\\ast\$")/ge;
  590.     # escape < and > as math string,
  591.     $str =~ s/</&noremap("\$<\$")/ge;
  592.     $str =~ s/>/&noremap("\$>\$")/ge;
  593.     $str =~ tr/\200-\377/\000-\177/;        # put back
  594.     return $str;
  595. }
  596.  
  597. sub internal_lrefs {
  598.     local($_) = shift;
  599.  
  600.     s{L</([^>]+)>}{$1}g;
  601.     my(@items) = split( /(?:,?\s+(?:and\s+)?)/ );
  602.     my $retstr = "the ";
  603.     my $i;
  604.     for ($i = 0; $i <= $#items; $i++) {
  605.     $retstr .= "C<$items[$i]>";
  606.     $retstr .= ", " if @items > 2 && $i != $#items;
  607.     $retstr .= " and " if $i+2 == @items;
  608.     }
  609.     $retstr .= " entr" . ( @items > 1  ? "ies" : "y" )
  610.         .  " elsewhere in this document";
  611.  
  612.     return $retstr;
  613. }
  614.  
  615. # map of HTML escapes to TeX escapes.
  616. BEGIN {
  617. %HTML_Escapes = (
  618.     'amp'    =>    '&',    #   ampersand
  619.     'lt'    =>    '<',    #   left chevron, less-than
  620.     'gt'    =>    '>',    #   right chevron, greater-than
  621.     'quot'    =>    '"',    #   double quote
  622.  
  623.     "Aacute"    =>    "\\'{A}",    #   capital A, acute accent
  624.     "aacute"    =>    "\\'{a}",    #   small a, acute accent
  625.     "Acirc"    =>    "\\^{A}",    #   capital A, circumflex accent
  626.     "acirc"    =>    "\\^{a}",    #   small a, circumflex accent
  627.     "AElig"    =>    '\\AE',        #   capital AE diphthong (ligature)
  628.     "aelig"    =>    '\\ae',        #   small ae diphthong (ligature)
  629.     "Agrave"    =>    "\\`{A}",    #   capital A, grave accent
  630.     "agrave"    =>    "\\`{a}",    #   small a, grave accent
  631.     "Aring"    =>    '\\u{A}',    #   capital A, ring
  632.     "aring"    =>    '\\u{a}',    #   small a, ring
  633.     "Atilde"    =>    '\\~{A}',    #   capital A, tilde
  634.     "atilde"    =>    '\\~{a}',    #   small a, tilde
  635.     "Auml"    =>    '\\"{A}',    #   capital A, dieresis or umlaut mark
  636.     "auml"    =>    '\\"{a}',    #   small a, dieresis or umlaut mark
  637.     "Ccedil"    =>    '\\c{C}',    #   capital C, cedilla
  638.     "ccedil"    =>    '\\c{c}',    #   small c, cedilla
  639.     "Eacute"    =>    "\\'{E}",    #   capital E, acute accent
  640.     "eacute"    =>    "\\'{e}",    #   small e, acute accent
  641.     "Ecirc"    =>    "\\^{E}",    #   capital E, circumflex accent
  642.     "ecirc"    =>    "\\^{e}",    #   small e, circumflex accent
  643.     "Egrave"    =>    "\\`{E}",    #   capital E, grave accent
  644.     "egrave"    =>    "\\`{e}",    #   small e, grave accent
  645.     "ETH"    =>    '\\OE',        #   capital Eth, Icelandic
  646.     "eth"    =>    '\\oe',        #   small eth, Icelandic
  647.     "Euml"    =>    '\\"{E}',    #   capital E, dieresis or umlaut mark
  648.     "euml"    =>    '\\"{e}',    #   small e, dieresis or umlaut mark
  649.     "Iacute"    =>    "\\'{I}",    #   capital I, acute accent
  650.     "iacute"    =>    "\\'{i}",    #   small i, acute accent
  651.     "Icirc"    =>    "\\^{I}",    #   capital I, circumflex accent
  652.     "icirc"    =>    "\\^{i}",    #   small i, circumflex accent
  653.     "Igrave"    =>    "\\`{I}",    #   capital I, grave accent
  654.     "igrave"    =>    "\\`{i}",    #   small i, grave accent
  655.     "Iuml"    =>    '\\"{I}',    #   capital I, dieresis or umlaut mark
  656.     "iuml"    =>    '\\"{i}',    #   small i, dieresis or umlaut mark
  657.     "Ntilde"    =>    '\\~{N}',    #   capital N, tilde
  658.     "ntilde"    =>    '\\~{n}',    #   small n, tilde
  659.     "Oacute"    =>    "\\'{O}",    #   capital O, acute accent
  660.     "oacute"    =>    "\\'{o}",    #   small o, acute accent
  661.     "Ocirc"    =>    "\\^{O}",    #   capital O, circumflex accent
  662.     "ocirc"    =>    "\\^{o}",    #   small o, circumflex accent
  663.     "Ograve"    =>    "\\`{O}",    #   capital O, grave accent
  664.     "ograve"    =>    "\\`{o}",    #   small o, grave accent
  665.     "Oslash"    =>    "\\O",        #   capital O, slash
  666.     "oslash"    =>    "\\o",        #   small o, slash
  667.     "Otilde"    =>    "\\~{O}",    #   capital O, tilde
  668.     "otilde"    =>    "\\~{o}",    #   small o, tilde
  669.     "Ouml"    =>    '\\"{O}',    #   capital O, dieresis or umlaut mark
  670.     "ouml"    =>    '\\"{o}',    #   small o, dieresis or umlaut mark
  671.     "szlig"    =>    '\\ss{}',    #   small sharp s, German (sz ligature)
  672.     "THORN"    =>    '\\L',        #   capital THORN, Icelandic
  673.     "thorn"    =>    '\\l',,        #   small thorn, Icelandic
  674.     "Uacute"    =>    "\\'{U}",    #   capital U, acute accent
  675.     "uacute"    =>    "\\'{u}",    #   small u, acute accent
  676.     "Ucirc"    =>    "\\^{U}",    #   capital U, circumflex accent
  677.     "ucirc"    =>    "\\^{u}",    #   small u, circumflex accent
  678.     "Ugrave"    =>    "\\`{U}",    #   capital U, grave accent
  679.     "ugrave"    =>    "\\`{u}",    #   small u, grave accent
  680.     "Uuml"    =>    '\\"{U}',    #   capital U, dieresis or umlaut mark
  681.     "uuml"    =>    '\\"{u}',    #   small u, dieresis or umlaut mark
  682.     "Yacute"    =>    "\\'{Y}",    #   capital Y, acute accent
  683.     "yacute"    =>    "\\'{y}",    #   small y, acute accent
  684.     "yuml"    =>    '\\"{y}',    #   small y, dieresis or umlaut mark
  685. );
  686. }
  687.  
  688. __END__
  689. :endofperl
  690.