Guido van Rossum | 9e93fb6 | 1994-01-25 20:06:09 +0000 | [diff] [blame] | 1 | # myformat.perl by Guido van Rossum <guido@cwi.nl> 25 Jan 1994 |
| 2 | # |
| 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 Drake | 4464022 | 1996-11-11 20:51:09 +0000 | [diff] [blame] | 9 | package main; |
Guido van Rossum | 9e93fb6 | 1994-01-25 20:06:09 +0000 | [diff] [blame] | 10 | |
| 11 | # \bcode and \ecode brackets around verbatim |
| 12 | |
| 13 | sub do_cmd_bcode{ @_[0]; } |
| 14 | sub do_cmd_ecode{ @_[0]; } |
| 15 | |
| 16 | # words typeset in a special way (not in HTML though) |
| 17 | |
| 18 | sub do_cmd_ABC{ join('', 'ABC', @_[0]); } |
| 19 | sub do_cmd_UNIX{ join('', 'Unix', @_[0]); } |
| 20 | sub do_cmd_ASCII{ join('', 'ASCII', @_[0]); } |
| 21 | sub do_cmd_C{ join('', 'C', @_[0]); } |
Guido van Rossum | b8b264b | 1994-08-12 13:13:50 +0000 | [diff] [blame] | 22 | sub do_cmd_Cpp{ join('', 'C++', @_[0]); } |
Guido van Rossum | 9e93fb6 | 1994-01-25 20:06:09 +0000 | [diff] [blame] | 23 | sub do_cmd_EOF{ join('', 'EOF', @_[0]); } |
| 24 | |
Fred Drake | 3e1fe89 | 1996-11-11 23:03:36 +0000 | [diff] [blame] | 25 | sub do_cmd_e{ local($_) = @_; '\' . $_; } |
Guido van Rossum | 9e93fb6 | 1994-01-25 20:06:09 +0000 | [diff] [blame] | 26 | |
Fred Drake | c384d75 | 1996-11-11 16:04:35 +0000 | [diff] [blame] | 27 | sub do_cmd_optional{ |
Guido van Rossum | 9e93fb6 | 1994-01-25 20:06:09 +0000 | [diff] [blame] | 28 | local($_) = @_; |
Fred Drake | 0d58d44 | 1996-12-06 15:09:14 +0000 | [diff] [blame] | 29 | s/$any_next_pair_pr_rx/<\/VAR><BIG>\[<\/BIG><VAR>\2<\/VAR><BIG>\]<\/BIG><VAR>/; |
Guido van Rossum | 9e93fb6 | 1994-01-25 20:06:09 +0000 | [diff] [blame] | 30 | $_; |
| 31 | } |
| 32 | |
Fred Drake | c384d75 | 1996-11-11 16:04:35 +0000 | [diff] [blame] | 33 | sub do_cmd_varvars{ |
| 34 | local($_) = @_; |
| 35 | s/$any_next_pair_pr_rx/<VAR>\2<\/VAR>/; |
| 36 | $_; |
| 37 | } |
| 38 | |
Fred Drake | 3e1fe89 | 1996-11-11 23:03:36 +0000 | [diff] [blame] | 39 | # texinfo-like formatting commands: \code{...} etc. |
| 40 | |
Fred Drake | c384d75 | 1996-11-11 16:04:35 +0000 | [diff] [blame] | 41 | sub do_cmd_code{ |
| 42 | local($_) = @_; |
| 43 | s/$any_next_pair_pr_rx/<CODE>\2<\/CODE>/; |
| 44 | $_; |
| 45 | } |
| 46 | |
| 47 | sub do_cmd_sectcode{ &do_cmd_code(@_); } |
| 48 | |
Guido van Rossum | 9e93fb6 | 1994-01-25 20:06:09 +0000 | [diff] [blame] | 49 | sub do_cmd_kbd{ |
| 50 | local($_) = @_; |
Fred Drake | c384d75 | 1996-11-11 16:04:35 +0000 | [diff] [blame] | 51 | s/$any_next_pair_pr_rx/<KBD>\2<\/KBD>/; |
Guido van Rossum | 9e93fb6 | 1994-01-25 20:06:09 +0000 | [diff] [blame] | 52 | $_; |
| 53 | } |
| 54 | |
| 55 | sub do_cmd_key{ |
| 56 | local($_) = @_; |
Fred Drake | c384d75 | 1996-11-11 16:04:35 +0000 | [diff] [blame] | 57 | s/$any_next_pair_pr_rx/<TT>\2<\/TT>/; |
Guido van Rossum | 9e93fb6 | 1994-01-25 20:06:09 +0000 | [diff] [blame] | 58 | $_; |
| 59 | } |
| 60 | |
| 61 | sub do_cmd_samp{ |
| 62 | local($_) = @_; |
Fred Drake | c384d75 | 1996-11-11 16:04:35 +0000 | [diff] [blame] | 63 | s/$any_next_pair_pr_rx/`<SAMP>\2<\/SAMP>'/; |
Guido van Rossum | 9e93fb6 | 1994-01-25 20:06:09 +0000 | [diff] [blame] | 64 | $_; |
| 65 | } |
| 66 | |
| 67 | sub do_cmd_var{ |
| 68 | local($_) = @_; |
Fred Drake | c384d75 | 1996-11-11 16:04:35 +0000 | [diff] [blame] | 69 | s/$any_next_pair_pr_rx/<VAR>\2<\/VAR>/; |
Guido van Rossum | 9e93fb6 | 1994-01-25 20:06:09 +0000 | [diff] [blame] | 70 | $_; |
| 71 | } |
| 72 | |
| 73 | sub do_cmd_file{ |
| 74 | local($_) = @_; |
Fred Drake | c384d75 | 1996-11-11 16:04:35 +0000 | [diff] [blame] | 75 | s/$any_next_pair_pr_rx/`<CODE>\2<\/CODE>'/; |
Guido van Rossum | 9e93fb6 | 1994-01-25 20:06:09 +0000 | [diff] [blame] | 76 | $_; |
| 77 | } |
| 78 | |
| 79 | sub do_cmd_dfn{ |
| 80 | local($_) = @_; |
Fred Drake | c384d75 | 1996-11-11 16:04:35 +0000 | [diff] [blame] | 81 | s/$any_next_pair_pr_rx/<I><DFN>\2<\/DFN><\/I>/; |
Guido van Rossum | 9e93fb6 | 1994-01-25 20:06:09 +0000 | [diff] [blame] | 82 | $_; |
| 83 | } |
| 84 | |
| 85 | sub do_cmd_emph{ |
| 86 | local($_) = @_; |
Fred Drake | c384d75 | 1996-11-11 16:04:35 +0000 | [diff] [blame] | 87 | s/$any_next_pair_pr_rx/<EM>\2<\/EM>/; |
Guido van Rossum | 9e93fb6 | 1994-01-25 20:06:09 +0000 | [diff] [blame] | 88 | $_; |
| 89 | } |
| 90 | |
| 91 | sub do_cmd_strong{ |
| 92 | local($_) = @_; |
Fred Drake | c384d75 | 1996-11-11 16:04:35 +0000 | [diff] [blame] | 93 | s/$any_next_pair_pr_rx/<STRONG>\2<\/STRONG>/; |
Guido van Rossum | 9e93fb6 | 1994-01-25 20:06:09 +0000 | [diff] [blame] | 94 | $_; |
| 95 | } |
| 96 | |
| 97 | # index commands |
| 98 | |
| 99 | sub do_cmd_indexii{ |
| 100 | local($_) = @_; |
| 101 | s/$next_pair_pr_rx//o; |
| 102 | local($br_id1, $str1) = ($1, $2); |
| 103 | s/$next_pair_pr_rx//o; |
| 104 | local($br_id2, $str2) = ($1, $2); |
| 105 | join('', &make_index_entry($br_id1, "$str1 $str2"), |
| 106 | &make_index_entry($br_id2, "$str2, $str1"), $_); |
| 107 | } |
| 108 | |
| 109 | sub do_cmd_indexiii{ |
| 110 | local($_) = @_; |
| 111 | s/$next_pair_pr_rx//o; |
| 112 | local($br_id1, $str1) = ($1, $2); |
| 113 | s/$next_pair_pr_rx//o; |
| 114 | local($br_id2, $str2) = ($1, $2); |
| 115 | s/$next_pair_pr_rx//o; |
| 116 | local($br_id3, $str3) = ($1, $2); |
| 117 | join('', &make_index_entry($br_id1, "$str1 $str2 $str3"), |
| 118 | &make_index_entry($br_id2, "$str2 $str3, $str1"), |
| 119 | &make_index_entry($br_id3, "$str3, $str1 $str2"), |
| 120 | $_); |
| 121 | } |
| 122 | |
| 123 | sub do_cmd_indexiv{ |
| 124 | local($_) = @_; |
| 125 | s/$next_pair_pr_rx//o; |
| 126 | local($br_id1, $str1) = ($1, $2); |
| 127 | s/$next_pair_pr_rx//o; |
| 128 | local($br_id2, $str2) = ($1, $2); |
| 129 | s/$next_pair_pr_rx//o; |
| 130 | local($br_id3, $str3) = ($1, $2); |
| 131 | s/$next_pair_pr_rx//o; |
| 132 | local($br_id4, $str4) = ($1, $2); |
| 133 | join('', &make_index_entry($br_id1, "$str1 $str2 $str3 $str4"), |
| 134 | &make_index_entry($br_id2, "$str2 $str3 $str4, $str1"), |
| 135 | &make_index_entry($br_id3, "$str3 $str4, $str1 $str2"), |
| 136 | &make_index_entry($br_id4, "$str4, $str1 $str2 $str3"), |
| 137 | $_); |
| 138 | } |
| 139 | |
| 140 | sub do_cmd_ttindex{ |
| 141 | &do_cmd_index(@_); |
| 142 | } |
| 143 | |
| 144 | sub my_typed_index_helper{ |
| 145 | local($word, $_) = @_; |
| 146 | s/$next_pair_pr_rx//o; |
| 147 | local($br_id, $str) = ($1, $2); |
| 148 | join('', &make_index_entry($br_id, "$str $word"), |
| 149 | &make_index_entry($br_id, "$word, $str"), $_); |
| 150 | } |
| 151 | |
| 152 | sub do_cmd_stindex{ &my_typed_index_helper('statement', @_); } |
| 153 | sub do_cmd_kwindex{ &my_typed_index_helper('keyword', @_); } |
| 154 | sub do_cmd_opindex{ &my_typed_index_helper('operator', @_); } |
| 155 | sub do_cmd_exindex{ &my_typed_index_helper('exception', @_); } |
| 156 | sub do_cmd_obindex{ &my_typed_index_helper('object', @_); } |
| 157 | |
| 158 | sub my_parword_index_helper{ |
| 159 | local($word, $_) = @_; |
| 160 | s/$next_pair_pr_rx//o; |
| 161 | local($br_id, $str) = ($1, $2); |
Fred Drake | c384d75 | 1996-11-11 16:04:35 +0000 | [diff] [blame] | 162 | &make_index_entry($br_id, "$str ($word)"); |
| 163 | $_; |
Guido van Rossum | 9e93fb6 | 1994-01-25 20:06:09 +0000 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | sub do_cmd_bifuncindex{ &my_parword_index_helper('built-in function', @_); } |
| 167 | sub do_cmd_bimodindex{ &my_parword_index_helper('built-in module', @_); } |
Fred Drake | c384d75 | 1996-11-11 16:04:35 +0000 | [diff] [blame] | 168 | sub do_cmd_stmodindex{ &my_parword_index_helper('standard module', @_); } |
Guido van Rossum | 9e93fb6 | 1994-01-25 20:06:09 +0000 | [diff] [blame] | 169 | sub do_cmd_bifuncindex{ &my_parword_index_helper('standard module', @_); } |
| 170 | |
Fred Drake | c384d75 | 1996-11-11 16:04:35 +0000 | [diff] [blame] | 171 | sub do_cmd_nodename{ &do_cmd_label(@_); } |
| 172 | |
| 173 | $any_next_pair_rx3 = "$O(\\d+)$C([\\s\\S]*)$O\\3$C"; |
| 174 | $new_command{"indexsubitem"} = ""; |
| 175 | |
| 176 | sub get_indexsubitem{ |
| 177 | local($result) = $new_command{"indexsubitem"}; |
| 178 | #print "\nget_indexsubitem ==> $result\n"; |
| 179 | $result; |
| 180 | } |
| 181 | |
Fred Drake | 7a7480d | 1996-10-29 15:56:57 +0000 | [diff] [blame] | 182 | sub do_env_cfuncdesc{ |
| 183 | local($_) = @_; |
| 184 | local($return_type,$function_name,$arg_list) = ('', '', ''); |
Fred Drake | 7a7480d | 1996-10-29 15:56:57 +0000 | [diff] [blame] | 185 | local($cfuncdesc_rx) = |
Fred Drake | c384d75 | 1996-11-11 16:04:35 +0000 | [diff] [blame] | 186 | "$next_pair_rx$any_next_pair_rx3$any_next_pair_rx5"; |
Fred Drake | 7a7480d | 1996-10-29 15:56:57 +0000 | [diff] [blame] | 187 | $* = 1; |
| 188 | if (/$cfuncdesc_rx/o) { |
| 189 | $return_type = "$2"; |
| 190 | $function_name = "$4"; |
| 191 | $arg_list = "$6"; |
Fred Drake | c384d75 | 1996-11-11 16:04:35 +0000 | [diff] [blame] | 192 | &make_index_entry($3,"<TT>$function_name</TT> " . &get_indexsubitem); |
Fred Drake | 7a7480d | 1996-10-29 15:56:57 +0000 | [diff] [blame] | 193 | } |
| 194 | $* = 0; |
| 195 | "<DL><DT>$return_type <STRONG><A NAME=\"$3\">$function_name</A></STRONG>" . |
| 196 | "(<VAR>$arg_list</VAR>)\n<DD>$'\n</DL>" |
| 197 | } |
| 198 | |
Fred Drake | c384d75 | 1996-11-11 16:04:35 +0000 | [diff] [blame] | 199 | sub do_env_funcdesc{ |
| 200 | local($_) = @_; |
| 201 | local($function_name,$arg_list) = ('', ''); |
| 202 | local($funcdesc_rx) = "$next_pair_rx$any_next_pair_rx3"; |
| 203 | $* = 1; |
| 204 | if (/$funcdesc_rx/o) { |
| 205 | $function_name = "$2"; |
| 206 | $arg_list = "$4"; |
| 207 | &make_index_entry($1,"<TT>$function_name</TT> " . &get_indexsubitem); |
| 208 | } |
| 209 | $* = 0; |
| 210 | "<DL><DT><STRONG><A NAME=\"$3\">$function_name</A></STRONG>" . |
| 211 | "(<VAR>$arg_list</VAR>)\n<DD>$'\n</DL>" |
| 212 | } |
| 213 | |
| 214 | sub do_env_datadesc{ |
| 215 | local($_) = @_; |
| 216 | local($data_name) = ('', ''); |
| 217 | local($datadesc_rx) = "$next_pair_rx"; |
| 218 | $* = 1; |
| 219 | if (/$datadesc_rx/o) { |
| 220 | $data_name = "$2"; |
| 221 | &make_index_entry($1,"<TT>$data_name</TT> " . &get_indexsubitem); |
| 222 | } |
| 223 | $* = 0; |
| 224 | "<DL><DT><STRONG><A NAME=\"$3\">$data_name</A></STRONG>" . |
| 225 | "\n<DD>$'\n</DL>" |
| 226 | } |
| 227 | |
| 228 | sub do_env_excdesc{ &do_env_datadesc(@_); } |
| 229 | |
Guido van Rossum | 9e93fb6 | 1994-01-25 20:06:09 +0000 | [diff] [blame] | 230 | 1; # This must be the last line |