home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / perl501m.zip / pod / pod2latex.SH (.txt) < prev    next >
LaTeX Document  |  1995-07-03  |  23KB  |  548 lines

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