Debian Codegraph @

texmf-dist/doc/latex/easy/for-latex2html/easyeqn.perl

raw
1 ############################################################################
2 # #
3 # Extension to LaTeX2HTML to load further features from #
4 # the EASYEQN package. #
5 # #
6 # date : 2002, March 18 #
7 # release : 1.1 (beta) #
8 # first release : 1999, Sept. 12 #
9 # file : easyeqn.perl #
10 # author : Enrico Bertolazzi #
11 # email : [email protected], #
12 # #
13 # This program is free software; you can redistribute it and/or modify #
14 # it under the terms of the GNU General Public License as published by #
15 # the Free Software Foundation; either version 2, or (at your option) #
16 # any later version. #
17 # #
18 # This program is distributed in the hope that it will be useful, #
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
21 # GNU General Public License for more details. #
22 # #
23 # You should have received a copy of the GNU General Public License #
24 # along with this program; if not, write to the Free Software #
25 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #
26 # #
27 # Copyright (C) 1999 #
28 # #
29 # Enrico Bertolazzi #
30 # Dipartimento di Ingegneria Meccanica e Strutturale #
31 # Universita` degli Studi di Trento #
32 # Via Mesiano 77, I-38050 Trento, Italy #
33 # #
34 # ___ ____ ___ _ _ ___ ____ ___ _ _ #
35 # / \ / / \ \ / / \ / / \ \ / #
36 # /____/ /__ /____/ \/ /____/ /__ /____/ \/ #
37 # / \ / / \ / / \ / / \ / #
38 # /____/ /____ / \ / /____/ /____ / \ / #
39 # #
40 ############################################################################
41
42 package main;
43
44 $display_env_rx = join('|', $display_env_rx, 'EQ','EQA');
45
46 %easyeqn_align = (
47 'l' => " ALIGN=\"LEFT\" ",
48 'c' => " ALIGN=\"CENTER\" ",
49 'r' => " ALIGN=\"RIGHT\" "
50 ) ;
51
52 %easyeqn_valign = (
53 't' => " VALIGN=\"TOP\" ",
54 'c' => " VALIGN=\"CENTER\" ",
55 'b' => " VALIGN=\"BOTTOM\" "
56 ) ;
57
58 $easyeqn_label_vpos = "c" ;
59 $easyeqn_label_hpos = "r" ;
60 $easyeqn_lc = "c" ;
61 $easyeqn_allnumber = 0 ;
62
63 sub do_easyeqn_leqno { $easyeqn_label_hpos = "l" ; }
64 sub do_easyeqn_fleqn { $easyeqn_lc = "l" ; }
65 sub do_easyeqn_math { }
66 sub do_easyeqn_allnumber { $easyeqn_allnumber = 1 ; }
67 sub do_easyeqn_warning { }
68
69 sub do_cmd_refeq {
70 local($_) = @_;
71 join('',&process_ref($cross_ref_mark,$cross_ref_mark,'')) ;
72 }
73
74 sub do_cmd_eqlabeltop {
75 local($_) = @_;
76 $easyeqn_label_vpos = "t" ;
77 join('',$_);
78 }
79
80 sub do_cmd_eqlabelbot {
81 local($_) = @_;
82 $easyeqn_label_vpos = "b" ;
83 join('',$_);
84 }
85
86 sub do_cmd_eqlabelcenter {
87 local($_) = @_;
88 $easyeqn_label_vpos = "c" ;
89 join('',$_);
90 }
91
92 sub do_cmd_equationcenter {
93 local($_) = @_;
94 $easyeqn_lc = "c" ;
95 join('',$_);
96 }
97
98 sub do_cmd_equationleft {
99 local($_) = @_;
100 $easyeqn_lc = "l" ;
101 join('',$_);
102 }
103
104 sub do_cmd_numberleft {
105 local($_) = @_;
106 $easyeqn_label_hpos = "l" ;
107 join('',$_);
108 }
109
110 sub do_cmd_numberright {
111 local($_) = @_;
112 $easyeqn_label_hpos = "r" ;
113 join('',$_);
114 }
115
116 sub do_env_EQ {
117 local($_) = @_;
118 $_ =~ s/\\eqlabel/\\label/g ;
119 my $label = " " ;
120 my $label_name = "";
121
122 $latex_body .= join('',
123 "\n\\setcounter{equation}{",
124 $global{'eqn_number'}, "}\n");
125
126 if ( $easy_allnumber ) { $global{'eqn_number'}++ ; }
127
128 if ( /\\label\s*\[([^\]]+)\]\s*(<<\d+>>)(.+)\2/ || /\\label\s*(\([^\)]+\))\s*(<<\d+>>)(.+)\2/ ) {
129 # \label[..]{..}
130 # \label(..){...}
131 $_ = $`. $' ;
132 $label_name = $3 ;
133 my $buffer = $1 ;
134 $buffer =~ s/~/$global{'eqn_number'}/i ;
135 $label = join('', &translate_commands($buffer) ) ;
136 }
137 elsif (/\\label\s*\[([^\]]+)\]/ || /\\label\s*(\([^\)]+\))/ ) {
138 # \label[..]
139 # \label(..)
140 $_ = $`. $' ;
141 my $buffer = $1 ;
142 $buffer =~ s/~/$global{'eqn_number'}/i ;
143 $label = join('', &translate_commands($buffer) ) ;
144 }
145 elsif ( /\\label\s*(<<\d+>>)(.+)\1/ ) {
146 # \label{...}
147 $_ = $`. $' ;
148 $label_name = $2 ;
149 $global{'eqn_number'}++ unless $easy_allnumber ;
150 $label = join('',"(", &translate_commands('\theequation'), ")" ) ;
151 }
152 elsif (/\\yesnumber/ || $easyeqn_allnumber ) {
153 $_ = $`. $' ;
154 $global{'eqn_number'}++ unless $easy_allnumber ;
155 $label = join('',"(", &translate_commands('\theequation'), ")" ) ;
156 }
157
158 $_ = &process_undefined_environment($env,$id,$_),
159
160 my $label_left = " " ;
161 my $label_right = " " ;
162 if ( $easyeqn_label_hpos eq "l" ) {
163 $label_left = $label ;
164 } else {
165 $label_right = $label ;
166 }
167
168 join('',
169 "\n<A NAME=\"", $label_name,"\">",
170 "\n <table WIDTH=\"100%\">",
171 "\n <tr",$easyeqn_align{$easyeqn_label_vpos},">",
172 "\n <td WIDTH=\"10%\" ALIGN=\"LEFT\">", $label_left, "</td>",
173 "\n <td WIDTH=\"90%\"",$easyeqn_align{$easyeqn_lc},">",
174 $_,
175 "</td>",
176 "\n <td WIDTH=\"10%\" ALIGN=\"RIGHT\">", $label_right, "</td>",
177 "\n </tr>",
178 "\n </table>",
179 "\n</A>") ;
180 }
181
182 ###############################################################################
183
184 sub do_env_EQA {
185 local($_) = @_ ;
186
187 my $local_id = $id ;
188
189 s/^\s+//g ;
190 s/^\n+/\n/g ;
191
192 $latex_body .= join('',
193 "\n\\setcounter{equation}{",
194 $global{'eqn_number'}, "}\n");
195
196 # get alignment
197 s/^\s*\[([^\]]+)\]// ;
198 my $align = $1 ;
199
200 $align =~ s/(.)/\1\,/g ;
201
202 my $ncol = 0 ;
203 my @acol ;
204 foreach my $char (split(',',$align)) {
205 $acol[$ncol] = $easyeqn_align{$char} ;
206 $ncol++ ;
207 }
208
209 # delete \\ spacing
210 s/\\\\\s*\[([^\]]+)\]/\\\\/g ;
211
212 my $letter = 'a' ;
213 my $nr = 0 ;
214 my $outeqn = "<BR>\n<table WIDTH=\"100%\">" ;
215
216 # split rows
217
218 foreach $_ ( split('\\\\\\\\',$_) ) {
219 # get label
220
221 my $label = " " ;
222 my $label_name = "";
223
224 if ( $easy_allnumber ) { $global{'eqn_number'}++ ; }
225
226 if ( /\\label\s*\[([^\]]+)\]\s*(<<\d+>>)(.+)\2/ ||
227 /\\label\s*(\([^\)]+\))\s*(<<\d+>>)(.+)\2/ ) {
228 # \label[..]{..}
229 # \label(..){...}
230 $_ = $`. $' ;
231 $label_name = $3 ;
232 my $buffer = $1 ;
233 $buffer =~ s/~/$global{'eqn_number'}/i ;
234 $label = join('', &translate_commands($buffer) ) ;
235 }
236 elsif ( /\\label\s*\[([^\]]+)\]/ ||
237 /\\label\s*(\([^\)]+\))/ ) {
238 # \label[..]
239 # \label(..)
240 $_ = $`. $' ;
241 my $buffer = $1 ;
242 $buffer =~ s/~/$global{'eqn_number'}/i ;
243 $label = join('', &translate_commands($buffer) ) ;
244 }
245 elsif ( /\\label\s*(<<\d+>>)(.+)\1/ ) {
246 # \label{...}
247 $_ = $`. $' ;
248 $label_name = $2 ;
249 $global{'eqn_number'}++ unless $easy_allnumber ;
250 $label = join('',"(", &translate_commands('\theequation'), ")" ) ;
251 }
252 elsif ( /\\yesnumber/ || $easyeqn_allnumber ) {
253 $_ = $`. $' ;
254 $global{'eqn_number'}++ unless $easy_allnumber ;
255 $label = join('',"(", &translate_commands('\theequation'), ")" ) ;
256 }
257
258 my $label_left = " " ;
259 my $label_right = " " ;
260 if ( $easyeqn_label_hpos eq "l" ) {
261 $label_left = $label ;
262 } else {
263 $label_right = $label ;
264 }
265
266 my $fill_left = "\n <td WIDTH=\"1000*\"> </td>" ;
267 my $fill_right = "\n <td WIDTH=\"1000*\"> </td>" ;
268
269 $fill_left = "\n <td WIDTH=\"0*\"> </td>" if ($easyeqn_lc eq "l") ;
270
271 $outeqn = join('',
272 $outeqn,
273 "\n<tr>",
274 "\n <td WIDTH=\"10%\" VALIGN=CENTER ALIGN=\"LEFT\">",
275 $label_left,
276 "</td>",
277 $fill_left,
278 "\n <A NAME = \"", $label_name, "\"></A>") ;
279
280 my $nc = 0 ;
281 # split columns
282 foreach ( split('\;SPMamp\;',$_) ) {
283 $id = $letter . $local_id ;
284 $_ = &process_undefined_environment("displaymath", $id, $_) ;
285 $outeqn = join('',
286 $outeqn,
287 "\n <td WIDTH=\"0*\" VALIGN=CENTER ", $acol[$nc],">",
288 $_,
289 "</td>") ;
290 $nc++ ;
291 $letter++ ;
292 }
293
294 $outeqn = join('',
295 $outeqn,
296 $fill_right,
297 "\n <td WIDTH=\"10%\" VALIGN=CENTER ALIGN=\"RIGHT\">",
298 $label_right,
299 "</td>",
300 "\n</tr>") ;
301 $nr++ ;
302 }
303 join('',$outeqn, "\n</table>\n<BR CLEAR=\"ALL\">") ;
304 }
305
306 &ignore_commands( <<_IGNORED_CMDS_);
307 _IGNORED_CMDS_
308
309 &process_commands_in_tex (<<_RAW_ARG_CMDS_);
310 _RAW_ARG_CMDS_
311
312 &process_commands_inline_in_tex (<<_RAW_ARG_CMDS_);
313 eqspacing # {}
314 eqleftmargin # {}
315 eqcolumnsep # {}
316 eqrowsep # {}
317 _RAW_ARG_CMDS_
318
319 &process_commands_nowrap_in_tex (<<_RAW_ARG_NOWRAP_CMDS_);
320 _RAW_ARG_NOWRAP_CMDS_
321
322 &process_commands_wrap_deferred (<<_RAW_ARG_DEFERRED_CMDS_);
323 eqlabeltop # &do_cmd_eqlabeltop
324 eqlabelbot # &do_cmd_eqlabelbot
325 eqlabelcenter # &do_cmd_eqlabelcenter
326 equationcenter # &do_cmd_eqnationcenter
327 equationleft # &do_cmd_eqnationleft
328 numberleft # &do_cmd_numberleft
329 numberright # &do_cmd_numberright
330 _RAW_ARG_DEFERRED_CMDS_
331
332
333 1; # This must be the last line