blob: 244b79306816684d0ce94fd2684f0b2d9e88cbad [file] [log] [blame]
Fred Drake8ca70061997-12-08 20:59:54 +00001# myformat.perl by Guido van Rossum <guido@cwi.nl> 25 Jan 1994 -*- perl -*-
Guido van Rossum9e93fb61994-01-25 20:06:09 +00002#
3# Extension to LaTeX2HTML for documents using myformat.sty.
4# Subroutines of the form do_cmd_<name> here define translations
5# for LaTeX commands \<name> defined in the corresponding .sty file.
6#
7# XXX Not complete: \indexii etc.; \funcitem etc.
8
Fred Drake44640221996-11-11 20:51:09 +00009package main;
Guido van Rossum9e93fb61994-01-25 20:06:09 +000010
11# \bcode and \ecode brackets around verbatim
12
13sub do_cmd_bcode{ @_[0]; }
14sub do_cmd_ecode{ @_[0]; }
15
16# words typeset in a special way (not in HTML though)
17
18sub do_cmd_ABC{ join('', 'ABC', @_[0]); }
19sub do_cmd_UNIX{ join('', 'Unix', @_[0]); }
20sub do_cmd_ASCII{ join('', 'ASCII', @_[0]); }
21sub do_cmd_C{ join('', 'C', @_[0]); }
Guido van Rossumb8b264b1994-08-12 13:13:50 +000022sub do_cmd_Cpp{ join('', 'C++', @_[0]); }
Guido van Rossum9e93fb61994-01-25 20:06:09 +000023sub do_cmd_EOF{ join('', 'EOF', @_[0]); }
Guido van Rossumd9a26ff1997-11-18 15:31:16 +000024sub do_cmd_NULL{ join('', 'NULL', @_[0]); }
Guido van Rossum9e93fb61994-01-25 20:06:09 +000025
Fred Drake3e1fe891996-11-11 23:03:36 +000026sub do_cmd_e{ local($_) = @_; '&#92;' . $_; }
Guido van Rossum9e93fb61994-01-25 20:06:09 +000027
Fred Drakec384d751996-11-11 16:04:35 +000028sub do_cmd_optional{
Guido van Rossum9e93fb61994-01-25 20:06:09 +000029 local($_) = @_;
Fred Drake7c4cba81997-12-03 19:45:08 +000030 s/$any_next_pair_pr_rx/<\/var><big>\[<\/big><var>\2<\/var><big>\]<\/big><var>/;
Guido van Rossum9e93fb61994-01-25 20:06:09 +000031 $_;
32}
33
Fred Drakec384d751996-11-11 16:04:35 +000034sub do_cmd_varvars{
35 local($_) = @_;
Fred Drake7c4cba81997-12-03 19:45:08 +000036 s/$any_next_pair_pr_rx/<var>\2<\/var>/;
Fred Drakec384d751996-11-11 16:04:35 +000037 $_;
38}
39
Fred Drake3e1fe891996-11-11 23:03:36 +000040# texinfo-like formatting commands: \code{...} etc.
41
Fred Drakec384d751996-11-11 16:04:35 +000042sub do_cmd_code{
43 local($_) = @_;
Fred Drake7c4cba81997-12-03 19:45:08 +000044 s/$any_next_pair_pr_rx/<code>\2<\/code>/;
Fred Drakec384d751996-11-11 16:04:35 +000045 $_;
46}
47
48sub do_cmd_sectcode{ &do_cmd_code(@_); }
49
Guido van Rossum9e93fb61994-01-25 20:06:09 +000050sub do_cmd_kbd{
51 local($_) = @_;
Fred Drake7c4cba81997-12-03 19:45:08 +000052 s/$any_next_pair_pr_rx/<kbd>\2<\/kbd>/;
Guido van Rossum9e93fb61994-01-25 20:06:09 +000053 $_;
54}
55
56sub do_cmd_key{
57 local($_) = @_;
Fred Drake7c4cba81997-12-03 19:45:08 +000058 s/$any_next_pair_pr_rx/<tt>\2<\/tt>/;
Guido van Rossum9e93fb61994-01-25 20:06:09 +000059 $_;
60}
61
62sub do_cmd_var{
63 local($_) = @_;
Fred Drake7c4cba81997-12-03 19:45:08 +000064 s/$any_next_pair_pr_rx/<var>\2<\/var>/;
Guido van Rossum9e93fb61994-01-25 20:06:09 +000065 $_;
66}
67
68sub do_cmd_dfn{
69 local($_) = @_;
Fred Drake7c4cba81997-12-03 19:45:08 +000070 s/$any_next_pair_pr_rx/<i><dfn>\2<\/dfn><\/i>/;
Guido van Rossum9e93fb61994-01-25 20:06:09 +000071 $_;
72}
73
74sub do_cmd_emph{
75 local($_) = @_;
Fred Drake7c4cba81997-12-03 19:45:08 +000076 s/$any_next_pair_pr_rx/<em>\2<\/em>/;
Guido van Rossum9e93fb61994-01-25 20:06:09 +000077 $_;
78}
79
80sub do_cmd_strong{
81 local($_) = @_;
Fred Drake7c4cba81997-12-03 19:45:08 +000082 s/$any_next_pair_pr_rx/<strong>\2<\/strong>/;
Guido van Rossum9e93fb61994-01-25 20:06:09 +000083 $_;
84}
85
Fred Drake7c4cba81997-12-03 19:45:08 +000086# file and samp are at the end of this file since they screw up fontlock.
87
Guido van Rossum9e93fb61994-01-25 20:06:09 +000088# index commands
89
90sub do_cmd_indexii{
91 local($_) = @_;
92 s/$next_pair_pr_rx//o;
93 local($br_id1, $str1) = ($1, $2);
94 s/$next_pair_pr_rx//o;
95 local($br_id2, $str2) = ($1, $2);
96 join('', &make_index_entry($br_id1, "$str1 $str2"),
97 &make_index_entry($br_id2, "$str2, $str1"), $_);
98}
99
100sub do_cmd_indexiii{
101 local($_) = @_;
102 s/$next_pair_pr_rx//o;
103 local($br_id1, $str1) = ($1, $2);
104 s/$next_pair_pr_rx//o;
105 local($br_id2, $str2) = ($1, $2);
106 s/$next_pair_pr_rx//o;
107 local($br_id3, $str3) = ($1, $2);
108 join('', &make_index_entry($br_id1, "$str1 $str2 $str3"),
109 &make_index_entry($br_id2, "$str2 $str3, $str1"),
110 &make_index_entry($br_id3, "$str3, $str1 $str2"),
Fred Drake72df9bc1997-12-16 21:13:20 +0000111 $_);
Guido van Rossum9e93fb61994-01-25 20:06:09 +0000112}
113
114sub do_cmd_indexiv{
115 local($_) = @_;
116 s/$next_pair_pr_rx//o;
117 local($br_id1, $str1) = ($1, $2);
118 s/$next_pair_pr_rx//o;
119 local($br_id2, $str2) = ($1, $2);
120 s/$next_pair_pr_rx//o;
121 local($br_id3, $str3) = ($1, $2);
122 s/$next_pair_pr_rx//o;
123 local($br_id4, $str4) = ($1, $2);
124 join('', &make_index_entry($br_id1, "$str1 $str2 $str3 $str4"),
125 &make_index_entry($br_id2, "$str2 $str3 $str4, $str1"),
126 &make_index_entry($br_id3, "$str3 $str4, $str1 $str2"),
127 &make_index_entry($br_id4, "$str4, $str1 $str2 $str3"),
Fred Drake72df9bc1997-12-16 21:13:20 +0000128 $_);
Guido van Rossum9e93fb61994-01-25 20:06:09 +0000129}
130
131sub do_cmd_ttindex{
132 &do_cmd_index(@_);
133}
134
135sub my_typed_index_helper{
136 local($word, $_) = @_;
137 s/$next_pair_pr_rx//o;
138 local($br_id, $str) = ($1, $2);
139 join('', &make_index_entry($br_id, "$str $word"),
140 &make_index_entry($br_id, "$word, $str"), $_);
141}
142
143sub do_cmd_stindex{ &my_typed_index_helper('statement', @_); }
144sub do_cmd_kwindex{ &my_typed_index_helper('keyword', @_); }
145sub do_cmd_opindex{ &my_typed_index_helper('operator', @_); }
146sub do_cmd_exindex{ &my_typed_index_helper('exception', @_); }
147sub do_cmd_obindex{ &my_typed_index_helper('object', @_); }
148
149sub my_parword_index_helper{
150 local($word, $_) = @_;
151 s/$next_pair_pr_rx//o;
152 local($br_id, $str) = ($1, $2);
Fred Drake72df9bc1997-12-16 21:13:20 +0000153 &make_index_entry($br_id, "$str ($word)") . $_;
Guido van Rossum9e93fb61994-01-25 20:06:09 +0000154}
155
Fred Drake84818d71997-12-17 02:59:39 +0000156sub make_mod_index_entry {
157 local($br_id,$str,$define) = @_;
158 # If TITLE is not yet available (i.e the \index command is in the title of the
159 # current section), use $ref_before.
160 $TITLE = $ref_before unless $TITLE;
161 # Save the reference
162 $str = &gen_index_id($str, $define);
163 $index{$str} .= &make_half_href("$CURRENT_FILE#$br_id");
Fred Drake8da9e6a1997-12-18 14:14:16 +0000164 "<a name=\"$br_id\">$anchor_invisible_mark<\/a>";
Fred Drake84818d71997-12-17 02:59:39 +0000165}
166
167sub my_module_index_helper{
168 local($word, $_, $define) = @_;
169 s/$next_pair_pr_rx//o;
170 local($br_id, $str) = ($1, $2);
171 &make_mod_index_entry($br_id, "<tt>$str</tt> ($word module)",
172 $define) . $_;
173}
174
Guido van Rossum9e93fb61994-01-25 20:06:09 +0000175sub do_cmd_bifuncindex{ &my_parword_index_helper('built-in function', @_); }
Fred Drake84818d71997-12-17 02:59:39 +0000176sub do_cmd_bimodindex{ &my_module_index_helper('built-in', @_, 'DEF'); }
177sub do_cmd_stmodindex{ &my_module_index_helper('standard', @_, 'DEF'); }
Guido van Rossum9e93fb61994-01-25 20:06:09 +0000178sub do_cmd_bifuncindex{ &my_parword_index_helper('standard module', @_); }
179
Fred Drake84818d71997-12-17 02:59:39 +0000180sub do_cmd_refbimodindex{ &my_module_index_helper('built-in', @_, 'REF'); }
181sub do_cmd_refstmodindex{ &my_module_index_helper('standard', @_, 'REF'); }
Fred Drake72df9bc1997-12-16 21:13:20 +0000182
Fred Drakec384d751996-11-11 16:04:35 +0000183sub do_cmd_nodename{ &do_cmd_label(@_); }
184
185$any_next_pair_rx3 = "$O(\\d+)$C([\\s\\S]*)$O\\3$C";
Fred Drake9597daf1997-12-22 22:37:34 +0000186$any_next_pair_rx5 = "$O(\\d+)$C([\\s\\S]*)$O\\5$C";
187$any_next_pair_rx7 = "$O(\\d+)$C([\\s\\S]*)$O\\7$C";
188$any_next_pair_rx9 = "$O(\\d+)$C([\\s\\S]*)$O\\9$C";
189$any_next_pair_pr_rx_5 = "$OP(\\d+)$CP([\\s\\S]*)$OP\\5$CP";
190$any_next_pair_pr_rx_7 = "$OP(\\d+)$CP([\\s\\S]*)$OP\\7$CP";
191$any_next_pair_pr_rx_9 = "$OP(\\d+)$CP([\\s\\S]*)$OP\\9$CP";
Fred Drakec384d751996-11-11 16:04:35 +0000192$new_command{"indexsubitem"} = "";
193
194sub get_indexsubitem{
195 local($result) = $new_command{"indexsubitem"};
196 #print "\nget_indexsubitem ==> $result\n";
Fred Drake9597daf1997-12-22 22:37:34 +0000197 $result ? " $result" : '';
Fred Drakec384d751996-11-11 16:04:35 +0000198}
199
Fred Drake84818d71997-12-17 02:59:39 +0000200# similar to make_index_entry(), but includes the string in the result
201# instead of the dummy filler.
202#
203sub make_str_index_entry {
204 local($br_id,$str) = @_;
205 # If TITLE is not yet available (i.e the \index command is in the title
206 # of the current section), use $ref_before.
207 $TITLE = $ref_before unless $TITLE;
208 # Save the reference
209 local($nstr) = &gen_index_id($str, '');
210 $index{$nstr} .= &make_half_href("$CURRENT_FILE#$br_id");
211 "<a name=\"$br_id\">$str<\/a>";
212}
213
Fred Drake7a7480d1996-10-29 15:56:57 +0000214sub do_env_cfuncdesc{
215 local($_) = @_;
Fred Drake7c4cba81997-12-03 19:45:08 +0000216 local($return_type,$function_name,$arg_list,$idx) = ('', '', '', '');
Fred Drake7a7480d1996-10-29 15:56:57 +0000217 local($cfuncdesc_rx) =
Fred Drakec384d751996-11-11 16:04:35 +0000218 "$next_pair_rx$any_next_pair_rx3$any_next_pair_rx5";
Fred Drake7a7480d1996-10-29 15:56:57 +0000219 $* = 1;
220 if (/$cfuncdesc_rx/o) {
221 $return_type = "$2";
222 $function_name = "$4";
223 $arg_list = "$6";
Fred Drake7c4cba81997-12-03 19:45:08 +0000224 $idx = &make_str_index_entry($3,
Fred Drake9597daf1997-12-22 22:37:34 +0000225 "<tt>$function_name</tt>" . &get_indexsubitem);
Fred Drake7a7480d1996-10-29 15:56:57 +0000226 }
227 $* = 0;
Fred Drake7c4cba81997-12-03 19:45:08 +0000228 "<dl><dt>$return_type <strong>$idx</strong>" .
229 "(<var>$arg_list</var>)\n<dd>$'\n</dl>"
Fred Drake7a7480d1996-10-29 15:56:57 +0000230}
231
Fred Drake9dcc5a91997-10-13 22:04:17 +0000232sub do_env_ctypedesc{
233 local($_) = @_;
234 local($type_name) = ('');
235 local($cfuncdesc_rx) =
236 "$next_pair_rx";
237 $* = 1;
238 if (/$cfuncdesc_rx/o) {
239 $type_name = "$2";
Fred Drake7c4cba81997-12-03 19:45:08 +0000240 $idx = &make_str_index_entry($1,
Fred Drake9597daf1997-12-22 22:37:34 +0000241 "<tt>$type_name</tt>" . &get_indexsubitem);
Fred Drake9dcc5a91997-10-13 22:04:17 +0000242 }
243 $* = 0;
Fred Drake7c4cba81997-12-03 19:45:08 +0000244 "<dl><dt><strong>$idx</strong>\n<dd>$'\n</dl>"
Fred Drake9dcc5a91997-10-13 22:04:17 +0000245}
246
247sub do_env_cvardesc{
248 local($_) = @_;
Fred Drake7c4cba81997-12-03 19:45:08 +0000249 local($var_type,$var_name,$idx) = ('', '', '');
Fred Drake9dcc5a91997-10-13 22:04:17 +0000250 local($cfuncdesc_rx) =
251 "$next_pair_rx$any_next_pair_rx3";
252 $* = 1;
253 if (/$cfuncdesc_rx/o) {
254 $var_type = "$2";
255 $var_name = "$4";
Fred Drake9597daf1997-12-22 22:37:34 +0000256 $idx = &make_str_index_entry($3,"<tt>$var_name</tt>" . &get_indexsubitem);
Fred Drake9dcc5a91997-10-13 22:04:17 +0000257 }
258 $* = 0;
Fred Drake7c4cba81997-12-03 19:45:08 +0000259 "<dl><dt>$var_type <strong>$idx</strong>\n" .
260 "<dd>$'\n</dl>";
Fred Drake9dcc5a91997-10-13 22:04:17 +0000261}
262
Fred Drakec384d751996-11-11 16:04:35 +0000263sub do_env_funcdesc{
264 local($_) = @_;
Fred Drake7c4cba81997-12-03 19:45:08 +0000265 local($function_name,$arg_list,$idx) = ('', '', '');
Fred Drakec384d751996-11-11 16:04:35 +0000266 local($funcdesc_rx) = "$next_pair_rx$any_next_pair_rx3";
267 $* = 1;
268 if (/$funcdesc_rx/o) {
269 $function_name = "$2";
270 $arg_list = "$4";
Fred Drake7c4cba81997-12-03 19:45:08 +0000271 $idx = &make_str_index_entry($3,
Fred Drake9597daf1997-12-22 22:37:34 +0000272 "<tt>$function_name</tt>" . &get_indexsubitem);
Fred Drakec384d751996-11-11 16:04:35 +0000273 }
274 $* = 0;
Fred Drake7c4cba81997-12-03 19:45:08 +0000275 "<dl><dt><strong>$idx</strong> (<var>$arg_list</var>)\n<dd>$'\n</dl>";
276}
277
278sub do_env_opcodedesc{
279 local($_) = @_;
280 local($opcode_name,$arg_list,$stuff,$idx) = ('', '', '', '');
281 local($opcodedesc_rx) = "$next_pair_rx$any_next_pair_rx3";
282 $* = 1;
283 if (/$opcodedesc_rx/o) {
284 $opcode_name = "$2";
285 $arg_list = "$4";
286 $idx = &make_str_index_entry($3,
287 "<tt>$opcode_name</tt> (byte code instruction)");
288 }
289 $* = 0;
290 $stuff = "<dl><dt><strong>$idx</strong>";
291 if ($arg_list) {
292 $stuff = "$stuff&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
293 }
294 $stuff . "\n<dd>$'\n</dl>";
Fred Drakec384d751996-11-11 16:04:35 +0000295}
296
297sub do_env_datadesc{
298 local($_) = @_;
Fred Drake7c4cba81997-12-03 19:45:08 +0000299 local($data_name,$idx) = ('', '');
Fred Drakec384d751996-11-11 16:04:35 +0000300 local($datadesc_rx) = "$next_pair_rx";
301 $* = 1;
302 if (/$datadesc_rx/o) {
303 $data_name = "$2";
Fred Drake7c4cba81997-12-03 19:45:08 +0000304 $idx = &make_str_index_entry($3,
Fred Drake9597daf1997-12-22 22:37:34 +0000305 "<tt>$data_name</tt>" . &get_indexsubitem);
Fred Drakec384d751996-11-11 16:04:35 +0000306 }
307 $* = 0;
Fred Drake7c4cba81997-12-03 19:45:08 +0000308 "<dl><dt><strong>$idx</strong>" .
309 "\n<dd>$'\n</dl>"
Fred Drakec384d751996-11-11 16:04:35 +0000310}
311
312sub do_env_excdesc{ &do_env_datadesc(@_); }
313
Fred Drake9597daf1997-12-22 22:37:34 +0000314@col_aligns = ("<td>", "<td>", "<td>");
315
316sub setup_column_alignments{
317 local($_) = @_;
318 local($j1,$a1,$a2,$a3,$j4) = split(/[|]/,$_);
319 $col_aligns[0] = (($a1 eq "c") ? "<td align=center>" : "<td>");
320 $col_aligns[1] = (($a2 eq "c") ? "<td align=center>" : "<td>");
321 $col_aligns[2] = (($a3 eq "c") ? "<td align=center>" : "<td>");
322}
323
324sub do_env_tableii{
325 local($_) = @_;
326 local($font,$h1,$h2) = ('', '', '');
327 local($tableiii_rx) =
328 "$next_pair_rx$any_next_pair_rx3$any_next_pair_rx5$any_next_pair_rx7";
329 $* = 1;
330 if (/$tableiii_rx/o) {
331 &setup_column_alignments($2);
332 $font = $4;
333 $h1 = $6;
334 $h2 = $8;
335 }
336 $globals{"lineifont"} = $font;
Fred Drake0ee35851997-12-28 03:41:07 +0000337 "<table border align=center>\n <tr><th>$h1</th>\n <th>$h2</th>$'\n"
Fred Drake9597daf1997-12-22 22:37:34 +0000338 . "</table>";
339}
340
341sub do_cmd_lineii{
342 local($_) = @_;
343 s/$next_pair_pr_rx//o;
344 local($c1) = $2;
345 s/$next_pair_pr_rx//o;
346 local($c2) = $2;
347 local($font) = $globals{"lineifont"};
348 local($c1align, $c2align) = @col_aligns[0,1];
349 "<tr>$c1align<$font>$c1</$font></td>\n"
350 . " $c2align$c2</td>$'";
351}
352
353sub do_env_tableiii{
354 local($_) = @_;
355 local($font,$h1,$h2,$h3) = ('', '', '', '');
356 local($tableiii_rx) =
357 "$next_pair_rx$any_next_pair_rx3$any_next_pair_rx5$any_next_pair_rx7"
358 . "$any_next_pair_rx9";
359 $* = 1;
360 if (/$tableiii_rx/o) {
361 &setup_column_alignments($2);
362 $font = $4;
363 $h1 = $6;
364 $h2 = $8;
365 $h3 = $10;
366 }
367 $globals{"lineifont"} = $font;
Fred Drake0ee35851997-12-28 03:41:07 +0000368 "<table border align=center>\n <tr><th>$h1</th>\n <th>$h2</th>"
Fred Drake9597daf1997-12-22 22:37:34 +0000369 . "\n <th>$h3</th>$'\n"
370 . "</table>";
371}
372
373sub do_cmd_lineiii{
374 local($_) = @_;
375 s/$next_pair_pr_rx//o;
376 local($c1) = $2;
377 s/$next_pair_pr_rx//o;
378 local($c2) = $2;
379 s/$next_pair_pr_rx//o;
380 local($c3) = $2;
381 local($font) = $globals{"lineifont"};
382 local($c1align, $c2align, $c3align) = @col_aligns;
383 "<tr>$c1align<$font>$c1</$font></td>\n"
384 . " $c2align$c2</td>\n"
385 . " $c3align$c3</td>$'";
386}
387
Fred Drake9dcc5a91997-10-13 22:04:17 +0000388sub do_env_seealso{
389 local($_) = @_;
Fred Drake7c4cba81997-12-03 19:45:08 +0000390 "<p><b>See Also:</b></p>\n" . $_;
Fred Drake9dcc5a91997-10-13 22:04:17 +0000391}
392
393sub do_cmd_seemodule{
394 local($_) = @_;
395 local($any_next_pair_pr_rx3) = "$OP(\\d+)$CP([\\s\\S]*)$OP\\3$CP";
Fred Drake7c4cba81997-12-03 19:45:08 +0000396 s/$next_pair_pr_rx$any_next_pair_pr_rx3/<p><code><b>\2<\/b><\/code> (\4)<\/p>/;
Fred Drake9dcc5a91997-10-13 22:04:17 +0000397 $_;
398}
399
400sub do_cmd_seetext{
401 local($_) = @_;
402 "<p>" . $_;
403}
404
Fred Drake7c4cba81997-12-03 19:45:08 +0000405# These are located down here since they screw up fontlock.
406
407sub do_cmd_file{
408 local($_) = @_;
409 s/$any_next_pair_pr_rx/`<code>\2<\/code>'/;
410 $_;
411}
412
413sub do_cmd_samp{
414 local($_) = @_;
415 s/$any_next_pair_pr_rx/`<samp>\2<\/samp>'/;
416 $_;
417}
418
Guido van Rossum9e93fb61994-01-25 20:06:09 +00004191; # This must be the last line