blob: f60bf1a20c80875a64b4a064f03b93afe12cfe1f [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
156sub do_cmd_bifuncindex{ &my_parword_index_helper('built-in function', @_); }
157sub do_cmd_bimodindex{ &my_parword_index_helper('built-in module', @_); }
Fred Drakec384d751996-11-11 16:04:35 +0000158sub do_cmd_stmodindex{ &my_parword_index_helper('standard module', @_); }
Guido van Rossum9e93fb61994-01-25 20:06:09 +0000159sub do_cmd_bifuncindex{ &my_parword_index_helper('standard module', @_); }
160
Fred Drake72df9bc1997-12-16 21:13:20 +0000161sub do_cmd_refbimodindex{ &my_parword_index_helper('built-in module', @_); }
162sub do_cmd_refstmodindex{ &my_parword_index_helper('standard module', @_); }
163
Fred Drakec384d751996-11-11 16:04:35 +0000164sub do_cmd_nodename{ &do_cmd_label(@_); }
165
166$any_next_pair_rx3 = "$O(\\d+)$C([\\s\\S]*)$O\\3$C";
167$new_command{"indexsubitem"} = "";
168
169sub get_indexsubitem{
170 local($result) = $new_command{"indexsubitem"};
171 #print "\nget_indexsubitem ==> $result\n";
172 $result;
173}
174
Fred Drake7a7480d1996-10-29 15:56:57 +0000175sub do_env_cfuncdesc{
176 local($_) = @_;
Fred Drake7c4cba81997-12-03 19:45:08 +0000177 local($return_type,$function_name,$arg_list,$idx) = ('', '', '', '');
Fred Drake7a7480d1996-10-29 15:56:57 +0000178 local($cfuncdesc_rx) =
Fred Drakec384d751996-11-11 16:04:35 +0000179 "$next_pair_rx$any_next_pair_rx3$any_next_pair_rx5";
Fred Drake7a7480d1996-10-29 15:56:57 +0000180 $* = 1;
181 if (/$cfuncdesc_rx/o) {
182 $return_type = "$2";
183 $function_name = "$4";
184 $arg_list = "$6";
Fred Drake7c4cba81997-12-03 19:45:08 +0000185 $idx = &make_str_index_entry($3,
186 "<tt>$function_name</tt> " . &get_indexsubitem);
Fred Drake7a7480d1996-10-29 15:56:57 +0000187 }
188 $* = 0;
Fred Drake7c4cba81997-12-03 19:45:08 +0000189 "<dl><dt>$return_type <strong>$idx</strong>" .
190 "(<var>$arg_list</var>)\n<dd>$'\n</dl>"
Fred Drake7a7480d1996-10-29 15:56:57 +0000191}
192
Fred Drake9dcc5a91997-10-13 22:04:17 +0000193sub do_env_ctypedesc{
194 local($_) = @_;
195 local($type_name) = ('');
196 local($cfuncdesc_rx) =
197 "$next_pair_rx";
198 $* = 1;
199 if (/$cfuncdesc_rx/o) {
200 $type_name = "$2";
Fred Drake7c4cba81997-12-03 19:45:08 +0000201 $idx = &make_str_index_entry($1,
202 "<tt>$type_name</tt> " . &get_indexsubitem);
Fred Drake9dcc5a91997-10-13 22:04:17 +0000203 }
204 $* = 0;
Fred Drake7c4cba81997-12-03 19:45:08 +0000205 "<dl><dt><strong>$idx</strong>\n<dd>$'\n</dl>"
Fred Drake9dcc5a91997-10-13 22:04:17 +0000206}
207
208sub do_env_cvardesc{
209 local($_) = @_;
Fred Drake7c4cba81997-12-03 19:45:08 +0000210 local($var_type,$var_name,$idx) = ('', '', '');
Fred Drake9dcc5a91997-10-13 22:04:17 +0000211 local($cfuncdesc_rx) =
212 "$next_pair_rx$any_next_pair_rx3";
213 $* = 1;
214 if (/$cfuncdesc_rx/o) {
215 $var_type = "$2";
216 $var_name = "$4";
Fred Drake7c4cba81997-12-03 19:45:08 +0000217 $idx = &make_str_index_entry($3,"<tt>$var_name</tt> " . &get_indexsubitem);
Fred Drake9dcc5a91997-10-13 22:04:17 +0000218 }
219 $* = 0;
Fred Drake7c4cba81997-12-03 19:45:08 +0000220 "<dl><dt>$var_type <strong>$idx</strong>\n" .
221 "<dd>$'\n</dl>";
Fred Drake9dcc5a91997-10-13 22:04:17 +0000222}
223
Fred Drakec384d751996-11-11 16:04:35 +0000224sub do_env_funcdesc{
225 local($_) = @_;
Fred Drake7c4cba81997-12-03 19:45:08 +0000226 local($function_name,$arg_list,$idx) = ('', '', '');
Fred Drakec384d751996-11-11 16:04:35 +0000227 local($funcdesc_rx) = "$next_pair_rx$any_next_pair_rx3";
228 $* = 1;
229 if (/$funcdesc_rx/o) {
230 $function_name = "$2";
231 $arg_list = "$4";
Fred Drake7c4cba81997-12-03 19:45:08 +0000232 $idx = &make_str_index_entry($3,
233 "<tt>$function_name</tt> " . &get_indexsubitem);
Fred Drakec384d751996-11-11 16:04:35 +0000234 }
235 $* = 0;
Fred Drake7c4cba81997-12-03 19:45:08 +0000236 "<dl><dt><strong>$idx</strong> (<var>$arg_list</var>)\n<dd>$'\n</dl>";
237}
238
239sub do_env_opcodedesc{
240 local($_) = @_;
241 local($opcode_name,$arg_list,$stuff,$idx) = ('', '', '', '');
242 local($opcodedesc_rx) = "$next_pair_rx$any_next_pair_rx3";
243 $* = 1;
244 if (/$opcodedesc_rx/o) {
245 $opcode_name = "$2";
246 $arg_list = "$4";
247 $idx = &make_str_index_entry($3,
248 "<tt>$opcode_name</tt> (byte code instruction)");
249 }
250 $* = 0;
251 $stuff = "<dl><dt><strong>$idx</strong>";
252 if ($arg_list) {
253 $stuff = "$stuff&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
254 }
255 $stuff . "\n<dd>$'\n</dl>";
Fred Drakec384d751996-11-11 16:04:35 +0000256}
257
258sub do_env_datadesc{
259 local($_) = @_;
Fred Drake7c4cba81997-12-03 19:45:08 +0000260 local($data_name,$idx) = ('', '');
Fred Drakec384d751996-11-11 16:04:35 +0000261 local($datadesc_rx) = "$next_pair_rx";
262 $* = 1;
263 if (/$datadesc_rx/o) {
264 $data_name = "$2";
Fred Drake7c4cba81997-12-03 19:45:08 +0000265 $idx = &make_str_index_entry($3,
266 "<tt>$data_name</tt> " . &get_indexsubitem);
Fred Drakec384d751996-11-11 16:04:35 +0000267 }
268 $* = 0;
Fred Drake7c4cba81997-12-03 19:45:08 +0000269 "<dl><dt><strong>$idx</strong>" .
270 "\n<dd>$'\n</dl>"
Fred Drakec384d751996-11-11 16:04:35 +0000271}
272
273sub do_env_excdesc{ &do_env_datadesc(@_); }
274
Fred Drake9dcc5a91997-10-13 22:04:17 +0000275sub do_env_seealso{
276 local($_) = @_;
Fred Drake7c4cba81997-12-03 19:45:08 +0000277 "<p><b>See Also:</b></p>\n" . $_;
Fred Drake9dcc5a91997-10-13 22:04:17 +0000278}
279
280sub do_cmd_seemodule{
281 local($_) = @_;
282 local($any_next_pair_pr_rx3) = "$OP(\\d+)$CP([\\s\\S]*)$OP\\3$CP";
Fred Drake7c4cba81997-12-03 19:45:08 +0000283 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 +0000284 $_;
285}
286
287sub do_cmd_seetext{
288 local($_) = @_;
289 "<p>" . $_;
290}
291
Fred Drake7c4cba81997-12-03 19:45:08 +0000292# These are located down here since they screw up fontlock.
293
294sub do_cmd_file{
295 local($_) = @_;
296 s/$any_next_pair_pr_rx/`<code>\2<\/code>'/;
297 $_;
298}
299
300sub do_cmd_samp{
301 local($_) = @_;
302 s/$any_next_pair_pr_rx/`<samp>\2<\/samp>'/;
303 $_;
304}
305
Guido van Rossum9e93fb61994-01-25 20:06:09 +00003061; # This must be the last line