Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

683 lines
22 KiB

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