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