Rev 6940 | Rev 7232 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
23 | reyssat | 1 | #!/usr/bin/perl |
2 | |||
3 | use strict "vars"; |
||
4 | use strict "subs"; |
||
5 | use locale; |
||
6 | use warnings; |
||
7 | use Text::Balanced qw (extract_bracketed extract_tagged); |
||
8 | |||
9 | $/ = undef; # slurp |
||
10 | # |
||
11 | ############################################################################### |
||
12 | # |
||
13 | # This file is part of latex2wims |
||
14 | # |
||
15 | # latex2wims is free software; you can redistribute it and/or modify |
||
16 | # it under the terms of the GNU General Public License as published by |
||
17 | # the Free Software Foundation; either version 2 of the License, or |
||
18 | # (at your option) any later version. |
||
19 | # |
||
20 | # latex2wims is distributed in the hope that it will be useful, |
||
21 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
22 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
23 | # GNU General Public License for more details. |
||
24 | # |
||
25 | # You should have received a copy of the GNU General Public License |
||
26 | # along with latex2wims; if not, write to the Free Software |
||
27 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
28 | # |
||
29 | ############################################################################### |
||
30 | # |
||
31 | my ($FILE, $MACRO, $EMBED, $NUMERO, $doc_DIR, $DIR, $author, $email, $worksheet, $SHEET,$ABOUT) ; |
||
32 | my $verbose = 0; |
||
33 | my $depth = 2 ; |
||
34 | my $INDEX = 0 ; |
||
734 | bpr | 35 | my $TOOLTIP = 0 ; |
23 | reyssat | 36 | my $STYLE = '' ; |
37 | my $OPTION = '' ; |
||
5696 | bpr | 38 | my $tooltip_prompt = '<img src="gifs/picto.gif" alt="picto" />' ; |
6614 | bpr | 39 | $tooltip_prompt=''; |
743 | bpr | 40 | my $linkout='' ; |
23 | reyssat | 41 | $worksheet= ''; |
42 | $SHEET = '' ; |
||
43 | $DIR = ''; |
||
44 | $doc_DIR = ''; |
||
4693 | bpr | 45 | my @SECTIONS = qw(document part chapter section subsection subsubsection); |
4850 | bpr | 46 | #my @SECTIONS = ( document part entete frame subsection subsubsection ); |
23 | reyssat | 47 | #TODO biblio dans un fichier séparé si on a rencontré \begin{thebibliography} Non, |
48 | # on n'a qu'a mettre cet environnement de type link |
||
49 | #$doc_DIR=$ENV{'w_docdir'}; |
||
50 | #$DIR=$ENV{'w_dir'}; |
||
51 | #$DIR =~ s/ +//; |
||
52 | push (@ARGV,split(' ', $ENV{'wims_exec_parm'})) if ($ENV{'wims_exec_parm'}) ; |
||
53 | |||
54 | while ($_ = shift (@ARGV)) |
||
55 | { |
||
56 | last if (!/^--/); |
||
57 | if (/^--style=(.*)$/) { $STYLE = $1; } |
||
58 | elsif (/^--macro=(.*)$/) { $MACRO = $1; } |
||
59 | elsif (/^--docdir=(.*)$/){ $doc_DIR = $1; } |
||
60 | elsif (/^--dir=(.*)$/) { $DIR = $1; } |
||
61 | elsif (/^--embed=(.*)$/) { $EMBED = $1; } |
||
62 | elsif (/^--verbose$/) { $verbose = 1; } |
||
63 | elsif (/^--author=(.*)$/){ $author = $1; } |
||
64 | elsif (/^--email=(.*)$/) { $email = $1; } |
||
65 | elsif (/^--worksheet=(.*)$/) { $worksheet = $1; } |
||
743 | bpr | 66 | elsif (/^--tooltip_prompt=(.*)$/) { $tooltip_prompt = $1; } |
4627 | bpr | 67 | elsif (/^--linkout=(.*)$/) { $linkout = $1; } |
68 | elsif (/^--cut=(.*)$/) { @SECTIONS = split(',',$1) ;} |
||
23 | reyssat | 69 | elsif (/^--help$/) { |
70 | usage(); # includes --help ! |
||
71 | exit 1; |
||
72 | } |
||
73 | } ; |
||
74 | |||
75 | $FILE = $_; |
||
76 | |||
77 | $DIR = $DIR . '/' if ($DIR) ; |
||
6858 | bpr | 78 | $doc_DIR = $doc_DIR . '/' if ($doc_DIR) ; |
79 | |||
6156 | bpr | 80 | my $LOAD = '\reload{<img src="gifs/doc/etoile.gif" alt="rechargez" style="width:20px;height:20px;" />}'; |
6612 | bpr | 81 | my $FLECHE = '→'; |
743 | bpr | 82 | $linkout = "\\doc{module=$linkout}" . $FLECHE if ($linkout) ; |
83 | |||
23 | reyssat | 84 | ################################## |
85 | ##Initialisation |
||
86 | #si je rajoute les listes : type=fold : signifierait que les item sont en fold [demande |
||
87 | #d'avoir des titres, ca serait du type description en latex |
||
88 | #pas de titre ? deb fin <ul ... > </ul> |
||
89 | #type = |
||
90 | #hash contenant les caractéristiques des environnements latex, voir \environmentwims |
||
91 | my %hash_environ = ( |
||
92 | titre => {}, |
||
93 | style => {}, |
||
94 | type => {}, |
||
95 | deb => {}, |
||
96 | fin => {}, |
||
97 | parm => {}, |
||
98 | origin => {}, |
||
734 | bpr | 99 | list => {}, |
100 | tabular => {}, |
||
23 | reyssat | 101 | ); |
102 | |||
103 | |||
104 | #hash contenant les commandes venant de \defwims, \def & co ou par defaut |
||
105 | my %hash_command = ( |
||
106 | cnt_arg => {}, |
||
107 | definition => {}, |
||
108 | origin => {}, |
||
109 | ); |
||
110 | my @liste_env_list = ('itemize', 'description', 'enumerate', 'trivlist') ; |
||
111 | $hash_environ{type}{'description_item'} = 'fold' ; |
||
112 | $hash_environ{titre}{'description_item'} = ' ' ; |
||
113 | |||
734 | bpr | 114 | my @liste_env_tabular = ('tabular') ; |
115 | |||
116 | my @liste_env_spec = ('equation', 'multline', 'latexonly', |
||
23 | reyssat | 117 | 'pmatrix','smallmatrix', 'eqnarray', 'array', 'algorithmic', 'algorithm', 'align', |
118 | 'thebibliography', 'pspicture', 'picture', 'cases', 'gather', |
||
6003 | bpr | 119 | 'displaymath', 'math', 'center', 'minipage', 'lstlisting', 'columns', 'column'); |
23 | reyssat | 120 | |
121 | my @liste_com_spec = ('paragraph', 'href', 'url', 'exercise', 'doc') ; #je ne m'en sers pas encore |
||
122 | |||
123 | #commandes par défaut : sont écrasés par un \def ou un \defwims |
||
124 | |||
125 | #$hash_command{cnt_arg}{text} = 1 ; |
||
126 | #$hash_command{definition}{text} = '\) #1 \(' ; |
||
127 | #$hash_command{origin}{text} = 'defaut' ; |
||
128 | |||
129 | $hash_command{cnt_arg}{paragraph} = 1 ; |
||
130 | $hash_command{definition}{paragraph} = '<p class="paragraph"> #1 </p>' ; |
||
131 | $hash_command{origin}{paragraph} = 'defaut' ; |
||
132 | |||
133 | $hash_command{cnt_arg}{href} = 2 ; |
||
5663 | bpr | 134 | $hash_command{definition}{href} = '<a href="http:#1" target="wims_external">#2</a>'; |
23 | reyssat | 135 | $hash_command{origin}{href} = 'defaut' ; |
136 | |||
137 | $hash_command{cnt_arg}{url} = 1 ; |
||
5663 | bpr | 138 | $hash_command{definition}{url} = '<a href="http:#1" target="wims_external">#1</a>'; |
23 | reyssat | 139 | $hash_command{origin}{url} = 'defaut' ; |
140 | |||
141 | $hash_command{cnt_arg}{exercise} = 2 ; |
||
142 | $hash_command{definition}{exercise} = "\\exercise\{\#1\}\{\#2\}"; |
||
143 | $hash_command{origin}{exercise} = 'defwims' ; |
||
144 | |||
145 | $hash_command{cnt_arg}{doc} = 2 ; |
||
146 | $hash_command{definition}{doc} = '\doc{#1&cmd=new}{#2}'; |
||
147 | $hash_command{origin}{doc} = 'defwims' ; |
||
148 | |||
149 | #a un label est associé son bloc [nom de fichier] |
||
150 | my %hash_bloc = ( |
||
151 | fichier => {}, |
||
152 | titre => {}, |
||
153 | ); |
||
154 | |||
155 | my %hash_index = ( |
||
156 | page => {}, |
||
157 | ); |
||
158 | |||
159 | #type sert à repérer les fichiers embed ou fold. |
||
160 | my %hash = ( |
||
161 | text => {}, |
||
162 | prev => {}, |
||
163 | next => {}, |
||
164 | upbl => {}, |
||
165 | titb => {}, |
||
166 | tittoc => {}, |
||
167 | keyw => {}, |
||
168 | datm => {}, |
||
169 | label => {}, |
||
170 | toc => {}, |
||
171 | chemin => {}, |
||
172 | niveau => {}, |
||
173 | type => {}, |
||
174 | author => {}, |
||
175 | title => {}, |
||
176 | email => {}, |
||
734 | bpr | 177 | toctip => {}, |
23 | reyssat | 178 | ); |
179 | |||
180 | my %hash_toc = (); |
||
181 | |||
182 | my %prefixe = ( fold => 'F_' , link => 'L_' ); |
||
4627 | bpr | 183 | |
23 | reyssat | 184 | my %hash_secinv; |
185 | for (my $i = 0; $i <= $#SECTIONS; $i++) { $hash_secinv{$SECTIONS[$i]} = $i; } |
||
186 | |||
187 | my (%errmsg); # empèche le ré-affichage d'un même warning. |
||
188 | $SIG{__WARN__} = sub { my ($x) = @_; |
||
189 | return if $errmsg{$x}; |
||
190 | $errmsg{$x} = 1; |
||
191 | print STDERR "### $x"; |
||
192 | }; |
||
193 | |||
194 | #imposé par wims |
||
195 | my $BASE = $doc_DIR . 'doc/1/src'; |
||
196 | my $BASE0= $doc_DIR . 'doc/1'; |
||
197 | system("mkdir -p $BASE0") if (!$ENV{'wims_exec_parm'}); |
||
198 | system("mkdir -p $BASE") if (!$ENV{'wims_exec_parm'}); |
||
199 | |||
200 | $hash{niveau}{'main'} = 0; |
||
201 | #pour algorithmic |
||
202 | #TODO récupérer les informations dans le fichier de l'utilisateur |
||
203 | |||
204 | my %hash_algo = ( |
||
205 | titre => {}, |
||
206 | apres => {}, |
||
207 | avant => {}, |
||
208 | suite => {} |
||
209 | ) ; |
||
210 | my $algo_noend = 0 ; |
||
211 | my $voca = %{$hash_algo{titre}} ; |
||
212 | my @liste_voca = ('FOR', 'IF','WHILE','REPEAT','ELSE','ELSIF','ENDIF','DO', |
||
213 | 'ENDWHILE', 'REQUIRE','ENSURE','ENDFOR','STATE','UNTIL','THEN', 'RETURN') ; |
||
214 | |||
215 | $hash_command{definition}{algorithmicrequire}='<b>Require</b>'; |
||
216 | $hash_command{origin}{algorithmicrequire}='defaut'; |
||
217 | $hash_command{cnt_arg}{algorithmicrequire}= 0 ; |
||
218 | $hash_command{definition}{algorithmicensure}='<b>Ensure</b>'; |
||
219 | $hash_command{definition}{algorithmicend}='<b>end</b>'; |
||
220 | $hash_command{definition}{algorithmicif}='<b>if</b>'; |
||
221 | $hash_command{definition}{algorithmicthen}='<b>then</b>'; |
||
222 | $hash_command{definition}{algorithmicelse}='<b>else</b>'; |
||
223 | $hash_command{definition}{algorithmicelsif}="<b>$hash_command{definition}{algorithmicelse} $hash_command{definition}{algorithmicif}</b>"; |
||
224 | $hash_command{definition}{algorithmicendif}="<b>$hash_command{definition}{algorithmicend} $hash_command{definition}{algorithmicif}</b>"; |
||
225 | $hash_command{definition}{algorithmicfor}='<b>for</b>'; |
||
226 | $hash_command{definition}{algorithmicforall}='<b>for all</b>'; |
||
227 | $hash_command{definition}{algorithmicdo}='<b>do</b>'; |
||
228 | $hash_command{definition}{algorithmicendfor}="<b>$hash_command{definition}{algorithmicend} $hash_command{definition}{algorithmicfor}</b>"; |
||
229 | $hash_command{definition}{algorithmicwhile}='<b>while</b>'; |
||
230 | $hash_command{definition}{algorithmicendwhile}="<b>$hash_command{definition}{algorithmicend} $hash_command{definition}{algorithmicwhile}</b>"; |
||
231 | $hash_command{definition}{algorithmicloop}='<b>loop</b>'; |
||
232 | $hash_command{definition}{algorithmicendloop}="<b>$hash_command{definition}{algorithmicend} $hash_command{definition}{algorithmicloop}</b"; |
||
233 | $hash_command{definition}{algorithmicrepeat}='<b>repeat</b>'; |
||
234 | $hash_command{definition}{algorithmicuntil}='<b>until</b>'; |
||
235 | $hash_command{definition}{algorithmicprint}='<b>print</b>'; |
||
236 | $hash_command{definition}{algorithmicreturn}='<b>return</b>'; |
||
237 | |||
238 | |||
239 | for my $cmd (@liste_voca) { $hash_command{origin}{"algorithmic\L$cmd\E"} = 'defaut' } |
||
240 | |||
241 | for my $cmd ('FOR','IF','WHILE','REPEAT','ELSE','ELSIF') { |
||
242 | $hash_algo{apres}{$cmd} = 1 ; |
||
243 | } ; |
||
244 | for my $cmd ('IF') { $hash_algo{suite}{$cmd} = 'THEN' ;} ; |
||
245 | for my $cmd ('FOR','WHILE') { $hash_algo{suite}{$cmd} = 'DO' ;} ; |
||
246 | for my $cmd ('ENDFOR','ENDIF', 'ENDWHILE','UNTIL','ELSE','ELSIF') { |
||
247 | $hash_algo{avant}{$cmd} = -1 ; |
||
248 | } ; |
||
249 | for my $cmd ('FOR','IF','WHILE','REQUIRE','ENSURE', 'STATE','UNTIL') { |
||
250 | $hash_algo{avant}{$cmd} = 0 ; |
||
251 | } ; |
||
252 | for my $cmd ('ENDFOR','ENDIF','ENDWHILE','REQUIRE','ENSURE', 'STATE','UNTIL') { |
||
253 | $hash_algo{apres}{$cmd} = 0 ; |
||
254 | } |
||
255 | |||
256 | |||
257 | # lit les fichiers wims.sty puis les fichers .tex. pour éviter : un seul fichier tex, le premier ? |
||
258 | |||
259 | my $TEXT = Init($FILE, \%hash_environ, \%hash_command, \%hash, \%hash_algo); |
||
260 | out1 ('sheet', $SHEET) ; |
||
261 | $ABOUT = $hash{about}{main} ; |
||
262 | out1 ('about.phtml', (($ABOUT)? $ABOUT :'') . ' |
||
263 | <p> |
||
6112 | bpr | 264 | Ce document a été créé par Latex2wims.</p> |
23 | reyssat | 265 | |
1692 | bpr | 266 | !changeto docu/about.phtml') ; |
23 | reyssat | 267 | if (!($hash{author}{main})) { |
268 | warn " ATTENTION : Vous devez mettre un nom d'auteur \\author{xxx}" ; |
||
269 | $hash{author}{main}=$author } ; |
||
270 | if (!($hash{title}{main})) { |
||
271 | warn " ATTENTION : Vous devez mettre un titre : \\title{xx} " ; |
||
272 | $hash{title}{main} = '??' } ; |
||
273 | if (!($hash{email}{main})) { |
||
274 | warn " ATTENTION : Vous devez mettre un email \\email{xxx}" ; |
||
275 | $hash{email}{main}=$email } ; |
||
276 | |||
277 | |||
278 | # PASSE 2: ferme les \section & co |
||
279 | my $SEC_MIN_GLOBAL = 10; # = \infty |
||
280 | #$SEC_MIN_GLOBAL = 3 ; |
||
281 | my @cnt = (0) x ($#SECTIONS + 1); |
||
282 | my ($secpattern) = join('|', @SECTIONS); |
||
283 | $TEXT =~ s/\\begin\s*{($secpattern)\s*}/cnt_section($1,\@cnt)/eg; |
||
4627 | bpr | 284 | $TEXT =~ s/\[fragile\]//g; |
23 | reyssat | 285 | $TEXT =~ s/\\end\s*{\s*($secpattern)\s*}/<\/$1>/g; |
3572 | bpr | 286 | $TEXT =~ s/\\wimsentre{($secpattern)}/\\wimsentre$1/g; |
23 | reyssat | 287 | $TEXT =~ s/\\(wimsentre)?($secpattern)\b\*?/open_close($2,\@cnt,$1)/eg; |
288 | $TEXT =~ s|</document>.*||s; |
||
289 | $TEXT =~ s|.*<document>||s; |
||
290 | if($SEC_MIN_GLOBAL == 10) {$SEC_MIN_GLOBAL = 0} ; |
||
291 | my ($NIVEAU, $NIVEAU_max) = ($SEC_MIN_GLOBAL, $SEC_MIN_GLOBAL + $depth - 1); |
||
292 | |||
293 | |||
294 | |||
295 | # PASSE 3: crée les blocs venant des sections et co |
||
296 | # et renvoie une partie de la table des matières |
||
297 | my $toc = analyse_texte ($TEXT, \%hash, 'main', $NIVEAU, $NIVEAU_max, ''); |
||
298 | # PASSE 4: création de tous les blocs ( environnements de type fold ou link) |
||
299 | { |
||
300 | my ($ref, $ref_env) = (\%hash, \%hash_environ); |
||
301 | while (my ($Id, $TEXT) = each (%{$hash{text}})) { |
||
302 | $TEXT = TraiteText ($TEXT, $ref, $ref_env, $Id); |
||
303 | #TODO non testé l'utilisation de prev etc |
||
304 | $ref->{text}{$Id} = $TEXT; |
||
305 | } |
||
306 | } |
||
307 | #récupération de tous les labels et rajout du titre en haut de la table dans la toc du tag |
||
308 | #On les traite pour que le label soit associé au nom du fichier créé automatiquement. |
||
309 | #$hash{toc}{$tag} contient les fichiers des sections en dessous de $tag |
||
310 | |||
311 | # PASSE 5 |
||
312 | for my $tag (keys %{$hash{text}}) { |
||
313 | my $T = $hash{text}{$tag}; |
||
314 | $T =~ s/\\label\s*\{([^}]+)\}/store_label($1, $tag, \%hash_bloc)/eg; |
||
315 | $T =~ s/\\index\s*\{([^}]+)\}/store_index($1, $tag, \%hash_index)/eg; |
||
316 | $hash{text}{$tag} = $T; |
||
317 | my $tagupbl = $hash{upbl}{$tag}; |
||
318 | #plus utilisé, mais j'hésite ! |
||
319 | # $hash_toc{$tag} = "\\link{$tagupbl}\n\n" . $hash{toc}{$tagupbl}; |
||
320 | } |
||
321 | |||
322 | |||
323 | # PASSE 6: sort l'index mis à jour des ref à l'aide des labels créés auparavant et rajoute |
||
324 | #TODO rajouter eqref mais ca dépend vraiment de la phrase ! |
||
325 | for my $tag (keys %{$hash{text}}) { |
||
326 | my $macro = '\\\\ref|\\\\cite|\\\\eqref'; |
||
327 | my $T = $hash{text}{$tag}; |
||
328 | my $cle = 'prev|next|upbl|titb|keyw|datm'; |
||
329 | $T =~ s/($macro)\{([^}]+)\}\{([^}]+)\}/store_ref($2, $3, $2, \%hash_bloc)/eg; |
||
330 | # repere toto~\cite{} |
||
331 | $T =~ s/([^\s]+)\~($macro)\s*([.*])?\s*\{([^}]+)\}/store_ref($4, $1 . |
||
332 | ($3||''), $4, \%hash_bloc)/eg; |
||
333 | $T =~ s/($macro)\s*([.*])?\{([^}]+)\}/store_ref($3, ($2 ? "$3: $2" : $3), $3, \%hash_bloc)/eg; |
||
334 | $T =~ s/\\($cle)\s*\{(\w*)\}/store_tag($1, $2, $tag, \%hash, \%hash_bloc)/eg; |
||
335 | $hash{text}{$tag} = $T; |
||
336 | } |
||
5664 | bpr | 337 | my @ListIndex = sort {$a cmp $b} (keys %{$hash_index{page}}) ; |
338 | out('index', selection('<div class="index">' . makeindex (\%hash_index, 0, @ListIndex) . '</div>' |
||
339 | ,'left-selection','index')) if ((@ListIndex) && $INDEX == 1 && makeindex (\%hash_index)); |
||
23 | reyssat | 340 | |
341 | #crée les blocs [entourés de la table des matières] |
||
342 | |||
343 | #crée les deux sortes de fichiers demandés par wims .def (fichier de définition général) + |
||
344 | # nom.hd qui gère les règles de navigation pour chaque bloc |
||
345 | #attention : dans le cas où il y a un \\embed{toto}, il faut créer le fichier toto.hd ... |
||
346 | #TODO : \embed{toto} : je suppose ici que le contenu de toto est du wims à ne pas |
||
347 | #interpréter |
||
348 | #pour l'instant je m'en suis servi pour stocker des programmes qui interviennent plusieurs fois. |
||
349 | |||
350 | #Crée le vrai fichier qui est mis dans le dossier src |
||
351 | #On ne met pas de table de matières si le bloc est de type fold |
||
352 | #TODO option = chemin tout seul, toc à gauche + chemin, toc à gauche et à droite + chemin, |
||
353 | #style selection droite, selection gauche |
||
354 | |||
355 | for my $tag (keys %{$hash{text}}) { |
||
356 | complete ($tag, \%hash); |
||
357 | out ("$tag.hd", hd($tag,\%hash)); |
||
358 | my $txt = traitement_final($hash{text}{$tag}); |
||
359 | my $tagupbl = $hash{upbl}{$tag}; |
||
360 | my $type = $hash{type}{$tag} ; |
||
6210 | bpr | 361 | my $style = $hash{style}{$tag}; |
23 | reyssat | 362 | #si type est non vide il est égal à embed ou fold |
363 | my $dotoc_left = ($OPTION =~ /toc_left/ && !$type); |
||
364 | my $dotoc_right = ($OPTION =~ /toc_right/ && !$type); |
||
365 | my $dotoc_up = ($OPTION =~ /toc_up/ && !$type); |
||
743 | bpr | 366 | my $dotoc_down = ($OPTION =~ /toc_down/ && !$type); |
23 | reyssat | 367 | my $CHEMIN = chemin($tag, \%hash); |
368 | #J'ai enlevé $LOAD |
||
743 | bpr | 369 | $CHEMIN = ($dotoc_up || $dotoc_down) && ($CHEMIN =~ $FLECHE) ? $CHEMIN : ''; |
3334 | bpr | 370 | my $CHEMIN_up=($dotoc_up) ? "<div id=\"up_toc\">$CHEMIN</div>": '' ; |
371 | my $CHEMIN_down=($dotoc_down) ? "<div id=\"down_toc\">$CHEMIN</div>" : '' ; |
||
23 | reyssat | 372 | my @Chemin = split(',', $hash{chemin}{$tag}); |
373 | my $TOCg = $dotoc_left ? selection($hash{toc}{main}, 'left_selection', @Chemin) : ''; |
||
6641 | bpr | 374 | my $TOCd = ($dotoc_right && $tag ne 'main' && (!($dotoc_left) || $tagupbl ne 'main' )) ? selection($hash{toc}{$tagupbl}, 'right_selection', @Chemin) : ''; |
6614 | bpr | 375 | |
23 | reyssat | 376 | my $tit_index = ($hash{titb}{index})? $hash{titb}{index} : 'Index' ; |
6614 | bpr | 377 | my $index = ($INDEX == 1 && (@ListIndex)) ? "<li>\\link{index}{$tit_index}</li>" : ''; |
6619 | bpr | 378 | my $tooltip = ""; |
6693 | bpr | 379 | ##$txt="<div class=\"fold\"> ".$txt ."<\/div>" if ($type=~/fold/) ; |
380 | my $pat= '<br\s+class="spacer"\s*/>'; |
||
381 | $txt = $tooltip . toc_HTML ($txt, clean($TOCg,\%hash), clean($TOCd,\%hash), $CHEMIN_up, $CHEMIN_down, $index); |
||
382 | $txt =~ s/$pat\s*$pat/<br class="spacer" \>/g; |
||
383 | out ($tag, $txt ); |
||
23 | reyssat | 384 | } |
385 | if ($INDEX == 1) { out ('index.hd', hd('index',\%hash) )}; |
||
386 | my @style = sortuniq(split(',',$STYLE)) if ($STYLE) ; |
||
387 | out_def ('.def', def (\%hash, @style )); |
||
388 | |||
389 | ############## |
||
390 | |||
391 | sub analyse_texte { my ($TEXT, $ref, $Id, $niveau, $niveau_max, $Toc) = @_; |
||
392 | my $link = ($niveau <= $niveau_max); |
||
393 | return $Toc if $niveau > $#SECTIONS ; |
||
394 | my $section = $SECTIONS[$niveau]; |
||
395 | my $sectiontag = "<$section>"; |
||
396 | my @decoup = split (/$sectiontag/, $TEXT); |
||
397 | my $text = $decoup[0]; |
||
398 | my $toc_titre ; |
||
399 | my ($cnt, $id) = (1, ""); |
||
400 | #On parcourt un texte $Id : $text et on enlève tous les niveaux inférieurs |
||
401 | # (boucle while) |
||
402 | while ( $decoup[$cnt]) { |
||
403 | #tient compte des titres courts pour la toc |
||
404 | my @u = extract_tagged ($decoup[$cnt],'\[','\]'); |
||
405 | $toc_titre = ($u[4]) ? $u[4] : '' ; |
||
406 | @u = extract_tagged ($u[1],'{','}'); |
||
407 | if (!$u[4]) { $NUMERO = 1 ; warn " ATTENTION : section dans $Id sans titre ; l'option numerotation a été rajoutée"}; |
||
408 | my @extract = extract_tagged ($sectiontag . $u[1], $sectiontag); |
||
409 | |||
410 | my $idold = $id; |
||
411 | $id = $Id . ($link? 'S': "$prefixe{fold}S") . $cnt; |
||
412 | $cnt++; |
||
413 | my $titre = $u[4]; |
||
414 | $toc_titre = $titre if (!$toc_titre) ; |
||
415 | $titre =~ s/\n/ /g; |
||
416 | $titre = Numero($id) . " $titre" if ($NUMERO); |
||
417 | $toc_titre = Numero($id) . " $toc_titre" if ($NUMERO); |
||
6003 | bpr | 418 | $text .= $link ?"<p>\\link{$id}</p>" |
419 | :"<p>\\fold{$id}{<span class=\"$section\">$titre</span>}</p>"; |
||
23 | reyssat | 420 | if ($link) { |
6003 | bpr | 421 | $Toc .= "<p><XXXX=\"$id\">\\link{$id}{$toc_titre}<YYYY=\"$id\"></p>"; |
23 | reyssat | 422 | } |
423 | $text .= $extract[1]; |
||
424 | $ref->{titb}{$id} = $titre; |
||
425 | $ref->{tittoc}{$id} = $toc_titre; |
||
426 | $ref->{text}{$id} = $extract[4]; |
||
734 | bpr | 427 | $ref->{type}{$id} = 'fold' if !$link ; |
23 | reyssat | 428 | $Toc = analyse_texte ($ref->{text}{$id}, $ref, $id, $niveau + 1, $niveau_max, $Toc) ; |
429 | $ref->{upbl}{$id} = $Id; |
||
430 | $ref->{prev}{$id} = $idold; |
||
431 | $ref->{next}{$idold} = $id; |
||
432 | #modifier avec selection |
||
6641 | bpr | 433 | my $tp = '' ; |
734 | bpr | 434 | if ($TOOLTIP==1) { |
6614 | bpr | 435 | if (!$ref->{toctip}{$Id}) {$ref->{toctip}{$Id}=($ref->{tittoc}{$id}) ? |
436 | "<li>\\link{$id}{$ref->{tittoc}{$id}}</li>": '' ; } |
||
437 | else { |
||
438 | $ref->{toctip}{$Id} .= ($ref->{tittoc}{$id}) ? "<li>\\link{$id}{$ref->{tittoc}{$id}}</li>": '' ; |
||
439 | } |
||
440 | #$ref->{toctip}{$Id} .= $ref->{tittoc}{$id} ; |
||
734 | bpr | 441 | $tp = "ZZZZZ$id" ; } |
6003 | bpr | 442 | $ref->{toc}{$Id} .= "\n<XXXX=\"$id\">\\link{$id}{$ref->{tittoc}{$id} |
6112 | bpr | 443 | }$tp <YYYY=\"$id\">"; |
23 | reyssat | 444 | } |
445 | #maintenant, ce qui reste dans $text est exactement ce qu'on doit mettre dans le hash->{text}{$Id} |
||
446 | $ref->{text}{$Id} = $text; |
||
447 | $ref->{titb}{main} = $ref->{title}{main}; |
||
448 | $ref->{tittoc}{main} = $ref->{title}{main} if (!$ref->{tittoc}{main}); |
||
449 | $Toc; |
||
450 | } |
||
451 | |||
452 | sub store_tag { my ($cle, $label, $tag, $ref, $ref_bloc) = @_; |
||
453 | $ref->{$cle}{$tag} = $ref_bloc->{fichier}{$label} ; |
||
454 | ''; |
||
455 | } |
||
456 | |||
457 | sub store_label { my ($label, $Id, $ref) = @_; |
||
458 | $ref->{fichier}{$label} = $Id; |
||
5894 | bpr | 459 | "<a id=\"$label\"></a>"; |
23 | reyssat | 460 | } |
461 | |||
462 | sub dbg { print STDERR "$_[0]\n" if ($verbose); } |
||
463 | |||
464 | sub store_index { my ($label, $Id, $ref_index) = @_; |
||
465 | dbg("... index: \"$label\""); |
||
466 | my $L = $ref_index->{page}{$label}; |
||
467 | $ref_index->{page}{$label} = !$L ? $Id : "$L,$Id"; |
||
5894 | bpr | 468 | "<a id=\"$label\"></a>"; |
23 | reyssat | 469 | } |
470 | |||
471 | sub class_index { my ($index,$level) = @_ ; |
||
472 | my @a = split('!', $index) ; |
||
473 | ($a[$level])? $a[$level] : $index ; |
||
474 | } |
||
475 | #!(keys %{$ref_index->{page}} |
||
476 | #sort keys %{$ref_index->{page}} ; |
||
477 | |||
5664 | bpr | 478 | sub makeindex { my ($ref_index, $level, @L ) = @_; |
23 | reyssat | 479 | return '' if (!$#L) ; |
480 | my $dejavu = '' ; |
||
481 | my $TEXT = "\n<ul class=\"index\">"; |
||
482 | for my $index (@L) { |
||
483 | next if ($dejavu =~ /\b$index\b/) ; |
||
484 | my @list = sort {$a cmp $b} grep {class_index($_, $level) eq class_index($index, $level)} @L ; |
||
485 | my @l = split('!', $index) ; |
||
486 | if ($l[$level]) { |
||
487 | $TEXT .= "<li> " ; |
||
488 | for my $ind (split(',',$ref_index->{page}{$index})) { |
||
489 | if ($ind && !($dejavu =~ /\b$ind\b/)) { |
||
490 | $TEXT .= "\\link{$ind}{". $l[$level] . " }{$ind}" ; |
||
491 | } |
||
492 | } |
||
493 | $dejavu .= ' ' . join (' , ', @list) ; |
||
494 | $TEXT .= makeindex ($ref_index, $level + 1, @list) . "</li>" ; |
||
495 | }; |
||
496 | } |
||
497 | "$TEXT </ul>"; |
||
498 | } |
||
499 | |||
500 | sub TraiteText {my ($TEXT, $ref, $ref_env, $Id) = @_; |
||
501 | $TEXT =~ s/\s*$//; # strip trailing whitespace |
||
502 | #0 ul et li sans rien |
||
503 | #1 avec style |
||
6104 | bpr | 504 | $TEXT =~ s/\\(begin|end)\s*{wimsonly}//g; |
23 | reyssat | 505 | for my $rubrique (keys %{$ref_env->{list}}) { |
506 | $TEXT = traite_list ($TEXT, $ref, $ref_env, $Id, $rubrique,1); |
||
507 | } |
||
508 | |||
509 | for my $rubrique (@liste_env_list) { |
||
510 | $TEXT = traite_list ($TEXT, $ref, $ref_env, $Id, $rubrique,0); |
||
511 | } |
||
512 | |||
734 | bpr | 513 | for my $rubrique (keys %{$ref_env->{tabular}}) { |
514 | if ($TEXT =~ /\\begin{$rubrique}/) { |
||
515 | $TEXT = traite_environ ($TEXT, $ref, $ref_env, $Id, $rubrique,0); |
||
516 | } |
||
517 | } |
||
518 | |||
519 | for my $rubrique (@liste_env_tabular) { |
||
520 | if ($TEXT =~ /\\begin{$rubrique}/) { |
||
521 | $TEXT = traite_environ ($TEXT, $ref, $ref_env, $Id, $rubrique,0); |
||
522 | } |
||
523 | } |
||
524 | |||
178 | bpr | 525 | for my $rubrique (@liste_env_spec) { |
526 | if ($TEXT =~ /\\begin{$rubrique(\*)?}/) { |
||
527 | $TEXT = traite_environ ($TEXT, $ref, $ref_env, $Id, $rubrique, 1); |
||
528 | } |
||
529 | } |
||
23 | reyssat | 530 | #le 1 et 0 servent à initialiser le compteur dans le cas ou on doit créer de nouveaux blocs dans la même page |
178 | bpr | 531 | |
23 | reyssat | 532 | for my $rubrique (keys %{$ref_env->{titre}}) { |
533 | if ($TEXT =~ /\\begin{$rubrique}/) { |
||
534 | $TEXT = traite_environ ($TEXT, $ref, $ref_env, $Id, $rubrique,1); |
||
535 | } |
||
536 | } |
||
537 | for my $rubrique (keys %{$ref_env->{list}}) { |
||
538 | $TEXT = traite_environ ($TEXT, $ref, $ref_env, $Id, $rubrique,0); |
||
539 | $TEXT = traite_environ ($TEXT, $ref, $ref_env, $Id, $rubrique . '_item',0); |
||
540 | } |
||
178 | bpr | 541 | |
23 | reyssat | 542 | if ($TEXT =~ /\\begin\{\s*(\w*)\s*\}/g) { |
6855 | bpr | 543 | warn " ATTENTION : environnement non répertorié : $1" if $1 ne 'matrix' && $1 ne 'split'; |
23 | reyssat | 544 | } |
3549 | bpr | 545 | $TEXT =~ s,<li>\n+</li>,<li></li>,g; |
6104 | bpr | 546 | $TEXT =~ s,</div>\s+</div>,</div></div>,g; |
547 | $TEXT =~ s,</div>\s+<,</div>\n<,g; |
||
6360 | bpr | 548 | $TEXT =~ s,<div ([^>]+)>\s+<,<div $1><,g; |
6693 | bpr | 549 | $TEXT =~ s/\n{2,5}/<br class=\"spacer\" \/>/g; |
23 | reyssat | 550 | $TEXT; |
551 | } |
||
552 | |||
553 | #on pourrait faire une boucle while ; on pourrait avoir deux fois le meme environnement imbrique ? |
||
554 | #begin{proof} \begin{proof} \end{proof}\end{proof} Je crois que c'est pour cela que je fais ce truc |
||
555 | #tordu. En fait split me sert uniquement à trouver le premier <$environ> |
||
556 | #$cnt sert à numéroter semi-globalement (création de blocs correspondant à un même environnement dans une meme page |
||
557 | #exemple mainS4S3F_proof1,mainS4S3F_proof2,mainS4S3F_proof3,mainS4S3F_proof4,mainS4S3F_proof5 |
||
734 | bpr | 558 | |
23 | reyssat | 559 | sub traite_list {my ($TEXT, $ref, $ref_env, $Id, $environ, $option) = @_; |
734 | bpr | 560 | my ($e_item, $b_item , $b_class, $e_class) = (' ',' ', ' ', ' '); |
23 | reyssat | 561 | if ( $option == 1 ) { |
562 | $e_item = "\\end{$environ\_item}" ; |
||
563 | $b_item = "\\begin{$environ\_item}" ; |
||
564 | my $style = $ref_env->{style}{$environ} ; |
||
565 | $style = ($style) ? $style : $environ; |
||
566 | $b_class= "ul class=\"$style\"" ; |
||
567 | $e_class= "\/ul" ; |
||
568 | } |
||
569 | { |
||
743 | bpr | 570 | if ($environ eq 'enumerate'){ $b_class = "ol class=\"enumerate\"" ; $e_class= "\/ol" ; } |
571 | elsif ($environ eq 'itemize'){ $b_class = "ul class=\"itemize\"" ; $e_class= "\/ul" ;} |
||
23 | reyssat | 572 | elsif ($environ eq 'description'){ |
573 | $b_class = "ul style=\"list-style:none;\"" ; |
||
574 | $e_class= "\/ul" ; |
||
575 | $e_item = "\\end{$environ\_item}" ; |
||
576 | $b_item = "\\begin{$environ\_item}" |
||
577 | } |
||
578 | elsif ($environ eq 'trivlist') { $b_class = "ul style=\"list-style:none;\"" ; |
||
579 | $e_class= "\/ul" ; |
||
580 | } |
||
581 | }; |
||
582 | $TEXT =~ s/\\begin{$environ(\*)?}/<$environ>/g; |
||
583 | $TEXT =~ s|\\end{$environ(\*)?}|<\/$environ>|g; |
||
584 | |||
585 | my @decoup = split ("<$environ>", $TEXT); |
||
586 | |||
587 | my $a = join ("<$environ>", @decoup[1..$#decoup]); |
||
743 | bpr | 588 | return $TEXT if (!$a) ; |
23 | reyssat | 589 | my @u = extract_tagged ("<$environ>$a", "<$environ>"); |
590 | my $milieu = "<$environ>" . $u[4] . "<\/$environ>" ; |
||
591 | #FIXME pas de listes emboitées de type différent ! |
||
743 | bpr | 592 | $milieu =~ s|<$environ>\s*\\item|<$environ><li>$b_item|g ; |
593 | $milieu =~ s|</$environ>|</li><$e_class>|g; |
||
594 | $milieu =~ s|\\item|$e_item</li><li>$b_item|g; |
||
595 | $milieu =~ s|</li><$e_class>|$e_item</li><$e_class>|g; |
||
596 | $milieu =~ s|<$environ>|<$b_class>|g; |
||
23 | reyssat | 597 | $decoup[0] . $milieu . traite_list ($u[1], $ref, $ref_env, $Id, $environ,$option); |
598 | } |
||
599 | |||
600 | sub traite_environ {my ($TEXT, $ref, $ref_env, $Id, $environ, $cnt) = @_; |
||
601 | $TEXT =~ s/\\begin{$environ\*?}/<$environ>/g; |
||
602 | $TEXT =~ s|\\end{$environ\*?}|</$environ>|g; |
||
603 | |||
604 | my @decoup = split ("<$environ>", $TEXT); |
||
605 | |||
606 | my $a = join ("<$environ>", @decoup[1..$#decoup]); |
||
607 | return $TEXT if (!$a); |
||
608 | |||
609 | my @u = extract_tagged ("<$environ>$a", "<$environ>"); |
||
610 | my $milieu = $u[4]; |
||
611 | return $TEXT if (!$milieu); |
||
612 | |||
613 | my $pat_env = join('|', @liste_env_spec); |
||
734 | bpr | 614 | my $patt_env = join('|', @liste_env_tabular); |
23 | reyssat | 615 | if ($environ =~ /\b($pat_env)\b/) { $milieu = $1->($milieu) ; } |
734 | bpr | 616 | elsif ($environ =~ /\b($patt_env)\b/) { $milieu = tabular->($milieu,$environ) ; } |
617 | else { my @milieu1 = extract_bracketed ($milieu, '{}'); |
||
23 | reyssat | 618 | if ($milieu1[0]) { $milieu = $milieu1[4] ; }; |
619 | my $type = $ref_env->{type}{$environ}; |
||
620 | |||
621 | if ($type && ($type eq 'fold' || $type eq 'link')) { |
||
622 | my $titre = $ref_env->{titre}{$environ}; |
||
623 | my $newtag = $Id . $prefixe{$type} . $environ . $cnt; |
||
624 | $ref->{type}{$newtag} = 'fold' if $type eq 'fold' ; |
||
625 | $cnt++; |
||
626 | # LaTeX interdit des [ ] imbriqués. |
||
627 | if ($milieu =~ s/^\s*\[([^\]]+)\]//) { |
||
743 | bpr | 628 | $titre = ($titre) ? "$titre [ $1 ]" : $1 ; |
23 | reyssat | 629 | } |
630 | $ref->{titb}{$newtag} = $titre; |
||
631 | $ref->{text}{$newtag} = encadrement("<$environ>$milieu<\/$environ>", $environ, $ref_env); |
||
632 | $ref->{upbl}{$newtag} = $Id; |
||
633 | $milieu = "\n\\$type\{$newtag\}\{" |
||
634 | . encadr_defaut("<$environ>$titre<\/$environ>", $environ, $ref_env,'titre') |
||
6167 | bpr | 635 | . "\}\n" ; |
23 | reyssat | 636 | } else { my $milieu1 = $milieu ; |
734 | bpr | 637 | $milieu = encadrement("<$environ>$milieu<\/$environ>", $environ, $ref_env, 'full'); |
23 | reyssat | 638 | } |
639 | } |
||
640 | $decoup[0] . $milieu . traite_environ ($u[1], $ref, $ref_env, $Id, $environ, $cnt); |
||
641 | } |
||
642 | |||
643 | sub hd {my ($tag, $ref) = @_; |
||
644 | my $txt = ''; |
||
645 | for my $cle ('prev','next','upbl','titb','keyw','datm') { |
||
646 | my $KEY = $ref->{$cle}{$tag}; |
||
647 | $txt .= "!set $cle=$KEY\n" if ($KEY); |
||
648 | } |
||
649 | $txt; |
||
650 | } |
||
651 | #rajoute un next aux section/subsection/ si cela n'existe pas [dernier] dernier sur index si il y a |
||
652 | #rajoute main pour ceux qui n'ont pas de parents. |
||
653 | sub complete {my ($tag, $ref) = @_; |
||
654 | $ref->{datm}{$tag} = isotime() if !($ref->{datm}{$tag}) ; |
||
655 | $ref->{upbl}{$tag} = 'main' if !($ref->{upbl}{$tag}) ; |
||
656 | my $upbl = $ref->{upbl}{$tag}; |
||
657 | if (!$ref->{next}{$tag}) { |
||
658 | my $a = $ref->{next}{$upbl}; |
||
659 | $ref->{next}{$tag} = $a || 'main'; |
||
660 | }; |
||
661 | if (!$ref->{prev}{$tag}) { |
||
662 | my $b = $ref->{prev}{$upbl}; |
||
663 | $ref->{prev}{$tag} = $b || 'main'; |
||
664 | }; |
||
665 | if ($INDEX == 1 && !($ref->{titb}{index})) { $ref->{titb}{index} = 'Index' ;} |
||
666 | } |
||
667 | |||
6472 | bpr | 668 | #option full <h2 class=" l2w_content defn">Définition [titre perso]</h2> <div class= " l2w_content definition"> </div> si cela existe |
23 | reyssat | 669 | #option bloc <div class= "definition"> </div> si cela existe (intérieur d'un fold ou d'un link) |
6472 | bpr | 670 | #option titre <h2 class="l2w_content defn">Définition </h2> si cela existe (titre d'un fold) |
23 | reyssat | 671 | sub encadr_defaut { my ($TEXT, $rubrique, $ref_env, $option) = @_; |
672 | my $a = $ref_env->{titre}{$rubrique}; |
||
673 | my $b = $ref_env->{style}{$rubrique}; |
||
674 | if (!$b) { |
||
675 | $b = $rubrique; |
||
676 | $ref_env->{style}{$rubrique} = $b; |
||
677 | dbg("... environnement $rubrique sans style css, par defaut $rubrique") |
||
678 | }; |
||
6472 | bpr | 679 | my $div_d = "<div class=\"l2w_content $b\">"; |
23 | reyssat | 680 | my $div_f = '</div>'; |
681 | if ( $option eq 'titre') { |
||
6472 | bpr | 682 | $TEXT =~ s/<$rubrique>/<span class=\"l2w_content $b\">/g; |
6104 | bpr | 683 | $TEXT =~ s/<\/$rubrique>/<\/span>\n/g; |
23 | reyssat | 684 | } elsif (!$a || $option eq 'bloc') { |
685 | $TEXT =~ s/<$rubrique>\s*(\[[^\]]+\])?/$div_d/g; |
||
6167 | bpr | 686 | $TEXT =~ s/<\/$rubrique>/$div_f/g; |
23 | reyssat | 687 | } elsif ($option eq 'full') { |
6472 | bpr | 688 | $TEXT =~ s/<$rubrique>\s*(\[[^\]]+\])/<h2 class=\"l2w_content $b\">$a $1<\/h2>$div_d/g; |
689 | $TEXT =~ s/<$rubrique>/<h2 class=\"l2w_content $b\">$a<\/h2>$div_d/g; |
||
6167 | bpr | 690 | $TEXT =~ s/<\/$rubrique>/$div_f/g; |
23 | reyssat | 691 | } else { |
692 | $TEXT =~ s/<$rubrique>/<span class=\"$b\">/g; |
||
6104 | bpr | 693 | $TEXT =~ s/<\/$rubrique>/<\/span>\n/g; |
23 | reyssat | 694 | } |
695 | $TEXT; |
||
696 | } |
||
697 | sub encadrement { my ($TEXT, $rubrique, $ref_env) = @_; |
||
698 | my $debut = $ref_env->{deb}{$rubrique}; |
||
699 | my $fin = $ref_env->{fin}{$rubrique}; |
||
743 | bpr | 700 | my $opt= ($ref_env->{type}{$rubrique} && $ref_env->{type}{$rubrique}=~ /fold/) ? 'bloc' : 'full' ; |
701 | return encadr_defaut ($TEXT, $rubrique, $ref_env, $opt) if (!$debut && !$fin); |
||
23 | reyssat | 702 | |
703 | $TEXT =~ s/<$rubrique>//; |
||
704 | my $cnt_arg = $ref_env->{cnt_arg}{$rubrique}; |
||
705 | my $d = join(' ', subst($TEXT, $cnt_arg, $debut, $rubrique, $ref_env)); |
||
706 | my ($com,$txt) = subst($TEXT, $cnt_arg, $fin); |
||
707 | $d =~ s/<\/$rubrique>/$com/; |
||
708 | $d; |
||
709 | } |
||
710 | |||
734 | bpr | 711 | |
712 | sub tabular { my ( $b, $style ) = @_; |
||
713 | my @v = extract_bracketed ($b, '{}') ; |
||
714 | my $stylerow = $style . "_row"; |
||
715 | my $stylecell = $style . "_cell"; |
||
3334 | bpr | 716 | $b = "<table class=\"$style\"><tr class=\"$stylerow\"><td class=\"$stylecell\">" . $v[1] . '</table>'; |
717 | $b =~ s|\&| </td><td class=\"$stylecell\"> |g; |
||
23 | reyssat | 718 | $b =~ s/\\hline//g; |
719 | $b =~ s|\\\\\s*</table>|</td></tr></table>|g; |
||
743 | bpr | 720 | my $par="\\\\\\(|\\\\\\)" ; |
721 | my @dectab = split(/$par/, $b) ; |
||
722 | $b = $dectab[0] ; |
||
3334 | bpr | 723 | $b =~ s|\\\\|</td></tr><tr class=\"$stylerow\"><td class=\"$stylecell\">|g; |
743 | bpr | 724 | my $cnt = 0; $b = '' ; |
725 | while ($cnt <= $#dectab/2) { |
||
726 | my $c = $dectab[2*$cnt] ; |
||
3334 | bpr | 727 | $c =~ s|\\\\|</td></tr><tr class=\"stylerow\"><td class=\"$stylecell\">|g; |
743 | bpr | 728 | $b .= $c . (($dectab[2*$cnt+1]) ? "\\(" . $dectab[2*$cnt+1] . "\\)" : '' ) ; |
729 | $cnt ++ ; |
||
730 | }; |
||
731 | $b ; |
||
23 | reyssat | 732 | } |
733 | |||
4852 | bpr | 734 | ###demande de convertir d'abord de manière indépendante les pdf tiff eps svg en un format d'image png |
735 | sub includegraphics{ my ( $b, $opt ) = @_; |
||
736 | $b=~ s/.(pdf|tiff|eps|svg)/.png/ ; |
||
4858 | bpr | 737 | $opt =~ s/.*(width|height)\s*=\s*([0-9]*\.?[0-9]*\s*)(\\(line|text)width)/linewidth("$2$3",$1)/eg; |
5663 | bpr | 738 | $opt =~ s/.*(width|height)\s*=\s*([0-9]*\.?[0-9]*\s*)(cm|px)/ style=\"$1:$2$3;\"/; |
6358 | bpr | 739 | "<img src=\"\\filedir\/$b\" $opt alt=\"\" />"; |
4852 | bpr | 740 | } |
741 | |||
4850 | bpr | 742 | sub minipage { my ( $b ) = @_; |
4865 | bpr | 743 | my @v = extract_bracketed ($b, '[]') ; |
744 | my $option = $v[0] ; |
||
6858 | bpr | 745 | if($option) { |
4865 | bpr | 746 | $option=~ s/\[\s*b\s*\]/bottom/ ; |
4866 | bpr | 747 | $option=~ s/\[\s*t\s*\]/top/ ; |
748 | $option=~ s/\[\s*c\s*\]/middle/ ; |
||
4865 | bpr | 749 | $option=~s/\[\s*\]/middle/; |
6858 | bpr | 750 | } else { |
751 | $option='middle'} ; |
||
4865 | bpr | 752 | @v = extract_bracketed ($v[1], '{}') ; |
4850 | bpr | 753 | my $width = $v[0] ; |
754 | $width =~ s/\{(.*)\}/$1/; |
||
6858 | bpr | 755 | $width = linewidth($width); |
4865 | bpr | 756 | "<div style=\"width:$width; display:inline-block;vertical-align:$option;\" class=\"minipage\"> |
4850 | bpr | 757 | $v[1] |
758 | </div>"; |
||
759 | } |
||
5286 | bpr | 760 | sub columns { my ( $b ) = @_; |
5289 | bpr | 761 | "<div class=\"columns\">$b</div>" |
5286 | bpr | 762 | } |
763 | |||
764 | sub column { my ( $b ) = @_; |
||
765 | my @v = extract_bracketed ($b, '[]') ; |
||
6104 | bpr | 766 | my $option = ''; |
767 | $option= $v[0] ; |
||
768 | if($option) { |
||
769 | $option=~ s/\[\s*b\s*\]/bottom/ ; |
||
770 | $option=~ s/\[\s*t\s*\]/top/ ; |
||
771 | $option=~ s/\[\s*c\s*\]/middle/ ; |
||
772 | $option=~s/\[\s*\]/middle/; |
||
773 | } |
||
774 | else{ $option='top'} ; |
||
5286 | bpr | 775 | @v = extract_bracketed ($v[1], '{}') ; |
776 | my $width = $v[0] ; |
||
777 | $width =~ s/\{(.*)\}/$1/; |
||
778 | $width = linewidth($width) ; |
||
779 | "<div style=\"width:$width; display:inline-block;vertical-align:$option;\" class=\"column\"> |
||
780 | $v[1] |
||
781 | </div>"; |
||
782 | } |
||
783 | |||
784 | |||
4851 | bpr | 785 | sub lstlisting { my ($b,$id ) = @_ ; |
786 | $b =~ s ,\\,\\\\,g ; |
||
787 | "<pre class=\"lstlisting\" id=\"lstlisting$id\">$b</pre>"; |
||
788 | } |
||
743 | bpr | 789 | |
4858 | bpr | 790 | sub verbatim { my ($b,$id ) = @_ ; |
791 | $b =~ s ,\\,\\\\,g ; |
||
792 | "<pre class=\"verbatim\" id=\"verbatim$id\">$b</pre>"; |
||
793 | } |
||
794 | |||
23 | reyssat | 795 | sub multline { my ( $b) = @_; |
5762 | bpr | 796 | $b =~ s/\\\\\s*=/\\)<br\/>\\(== /g; |
797 | $b =~ s|\\\\|\\)<br\/>\\(|g; |
||
23 | reyssat | 798 | "<div class=\"math\">\\(" . $b . "\\)</div>\n"; |
799 | } |
||
800 | |||
801 | sub equation { my ( $b) = @_; |
||
802 | $b = "\\( $b \\)"; |
||
803 | if ($b =~ s/\\label{([^\}]+)}//) { $b = "\\label{$1}" . $b }; |
||
804 | '<div class="math">' . $b . '</div>' ; |
||
805 | } |
||
806 | |||
807 | sub align1 { my ( $b) = @_; |
||
808 | $b = "\\(\\begin{matrix} $b \\end{matrix} \\)"; |
||
809 | if ($b =~ s/\\label{([^\}])}//) { $b = "\\label{$1}" . $b }; |
||
810 | '<div class="math">' . $b . '</div>' ; |
||
811 | } |
||
812 | sub align { my ( $b) = @_; |
||
6169 | bpr | 813 | $b = '<table class="wimscenter wimsnoborder tableau" style="width:100%"><tr><td>\\(' . $b . '\\\\</table>'; |
23 | reyssat | 814 | if ($b =~ s/\\label{([^\}])}//) { $b = "\\label{$1}" . $b }; |
815 | $b =~ s|\&|\\) </td><td> \\(|g; |
||
816 | $b =~ s|\\\\\s*</table>|\\)</td></tr></table>|g; |
||
817 | $b =~ s|\\\\|\\)</td></tr><tr><td>\\(|g; |
||
5291 | bpr | 818 | $b =~ s|\\\(\s+\\\)||g; |
819 | $b =~ s|\n\\\)|\\\)|g; |
||
820 | $b =~ s|\\\(\n|\\\(|g; |
||
23 | reyssat | 821 | '<div class="math">' . $b . '</div>' ; |
822 | } |
||
823 | |||
824 | sub pmatrix {"\\left ( \\begin{matrix} " . $_[0] . "\\end{matrix} \\right )" ;} |
||
825 | sub smallmatrix {"\\left ( \\begin{matrix} " . $_[0] . "\\end{matrix} \\right )" ;} |
||
826 | sub eqnarray {" <div class=\"math\">\\(\\begin{matrix} " . $_[0] . "\\end{matrix})</div> " ;} |
||
827 | sub center {" <div class=\"center\">" . $_[0] . "</div>"} |
||
828 | |||
829 | sub array {my ( $b ) = @_ ; |
||
830 | my @v = extract_bracketed ($b, '{}'); |
||
831 | "\\begin{matrix} " . $v[1] . "\\end{matrix} "; |
||
832 | } |
||
833 | #TODO pour l'instant |
||
5292 | bpr | 834 | sub cases {"\\left \\lbrace\\begin{matrix} " . $_[0] . "\\end{matrix} \\right ." ; } |
23 | reyssat | 835 | |
836 | sub gather { my ($b) = @_; |
||
837 | my @decoup = split ('\\\\intertext', $b); |
||
838 | my $cnt = 1; |
||
839 | $b = equation($decoup[0]); |
||
840 | while ($cnt <= $#decoup) { |
||
841 | my @a = extract_bracketed ( $decoup[$cnt], '{}' ); |
||
842 | my $c = $a[0]; |
||
843 | $c =~ s/\{(.*)\}/$1/; |
||
844 | $b .= $c . equation($a[1]); |
||
845 | $cnt ++; |
||
846 | } |
||
847 | $b; |
||
848 | } |
||
849 | |||
6169 | bpr | 850 | sub displaymath {"<div class=\"math\">\\(\\displaystyle{ " . $_[0]. "}\\)</div>"; } |
23 | reyssat | 851 | sub math {" \\( " . $_[0]. "\\) "; } |
852 | |||
853 | |||
854 | sub thebibliography { my ( $b ) = @_; |
||
855 | $b =~ s/\\bibitem{([^}]+)}/<\/li>\n<li>\[$1\]\\label{$1} /g; |
||
856 | $b =~ s/\{\d+\}\s*<\/li>//; |
||
857 | '<h2 class="thebibliography">' . $hash{titb}{ref} |
||
858 | . "</h2>\n<ul class=\"thebibliography\">$b </li></ul>\n"; |
||
859 | } |
||
860 | sub pspicture { '<p>dessin à faire dans wims</p>' ; } |
||
861 | sub picture { '<p>dessin à faire dans wims</p>' ; } |
||
862 | |||
863 | #decoupe ce qui se trouve à l'intérieur de \begin{wims} \end{wims} pour ne pas y toucher. |
||
4851 | bpr | 864 | # même pour verbatim, lstlisting |
23 | reyssat | 865 | sub traite_special { my ( $TEXT, $ref_spec, $ref, $environ ) = @_; |
866 | $TEXT = recup_embed($TEXT, $ref) ; |
||
867 | $TEXT =~ s/\\begin{$environ}/<$environ>/g; |
||
868 | $TEXT =~ s/\\end{$environ}/<\/$environ>/g; |
||
869 | $TEXT =~ s/\r\n/\n/gs ; |
||
870 | my @decoup = split ("<$environ>", $TEXT); |
||
871 | my $cnt = 1; |
||
872 | if ($#decoup) { |
||
873 | $TEXT = $decoup[0]; |
||
874 | while ($cnt <= $#decoup) { |
||
875 | my @a = extract_tagged("<$environ>" . $decoup[$cnt], "<$environ>"); |
||
876 | die "Bug dans $environ insertion: $decoup[$cnt]" if (!defined($a[4])); |
||
877 | $TEXT .= $environ . 'insertion' . $cnt . $a[1]; |
||
878 | $ref_spec->{$cnt} = $a[4]; |
||
879 | $cnt++; |
||
880 | } |
||
881 | } |
||
882 | $TEXT; |
||
883 | } |
||
884 | |||
885 | sub latexonly { '' } |
||
886 | |||
887 | sub store_cmd { my ($def, $id, $narg, $val, $ref_command) = @_; |
||
888 | if ($hash_secinv{$id}) { |
||
889 | warn " ATTENTION : commande perso \"$id: argument invalide\n"; |
||
890 | return ''; |
||
891 | } |
||
892 | my $origin = $ref_command->{origin}{$id}; |
||
893 | return '' if ($origin && $origin eq 'defwims' && $def ne 'defwims'); |
||
894 | $ref_command->{origin}{$id} = $def; |
||
895 | $ref_command->{cnt_arg}{$id} = $narg; |
||
896 | $ref_command->{definition}{$id} = $val; |
||
897 | dbg("... commande perso \"$id\": argument: \"$narg\" definition: \"$val\""); |
||
898 | '' ; |
||
899 | } |
||
900 | |||
901 | sub store_environ { my ($def, $cmd, $narg, $titre, $deb, $fin, $ref_env) = @_; |
||
902 | my $origin = $ref_env->{origin}{$cmd}; |
||
903 | return '' if ($origin && $origin eq 'environmentwims' && $def ne 'environmentwims'); |
||
904 | $ref_env->{deb}{$cmd} = $deb; |
||
905 | $ref_env->{fin}{$cmd} = $fin; |
||
906 | $ref_env->{cnt_arg}{$cmd} = $narg; |
||
7228 | bpr | 907 | ## one can have macro in definition of an environment - not general but useful for language |
908 | if ($titre=~/\\(\w+)/) { |
||
909 | $titre=$hash_command{definition}{$1} if $hash_command{definition}{$1} |
||
910 | } |
||
23 | reyssat | 911 | $ref_env->{titre}{$cmd} = $titre; |
912 | $ref_env->{origin}{$cmd} = $def; |
||
913 | my $style = $ref_env->{style}{$cmd} ; |
||
914 | $style = ($style)? $style : $cmd ; |
||
734 | bpr | 915 | #if (!$ref_env->{deb}{$cmd}) { $ref_env->{deb}{$cmd} = "<div class=\"$style\"> "; } |
916 | #if (!$ref_env->{fin}{$cmd}) { $ref_env->{fin}{$cmd} = "</div> "; } |
||
23 | reyssat | 917 | dbg("... environnement perso \"$cmd\" argument: \"$narg\" titre: \"$titre\" style: \"$style\" debut: \"$deb\" fin: \"$fin\""); |
918 | ''; |
||
919 | } |
||
920 | |||
921 | |||
922 | sub recup_command {my ($TEXT, $ref_command) = @_; |
||
923 | my $DEF = '(defwims|def|newcommand|renewcommand)'; |
||
924 | #FIXME ? mauvais pour def \def\toto#1#2 ... demander de le refaire avec defwims s'il y a plus de 3 arguments ? |
||
925 | $TEXT =~ s/\\$DEF\s*\\(\w*)#(\d)\{(.*)\}/store_cmd($1,$2,$3,$4,$ref_command)/eg; |
||
926 | #2 arguments |
||
927 | $TEXT =~ s/\\$DEF\s*\\(\w*)#(\d)#(\d)\{(.*)\}/store_cmd($1,$2,$4,$5,$ref_command)/eg; |
||
928 | $TEXT =~ s/\\$DEF\s*\\(\w*)\s*\{(.*)\}/store_cmd($1,$2,0,$3,$ref_command)/eg; |
||
929 | #3 arguments |
||
930 | $TEXT =~ s/\\$DEF\s*\\(\w*)#(\d)#(\d)#(\d)\{(.*)\}/store_cmd($1,$2,$5,$6,$ref_command)/eg; |
||
931 | # newcommand avec paramètres |
||
932 | $TEXT =~ s/\\$DEF\s*\{\\(\w*)\}\s*\[(\d)\]\s*\{(.*)\}/store_cmd($1,$2,$3,$4,$ref_command)/eg; |
||
933 | # newcommand sans paramètres |
||
934 | $TEXT =~ s/\\$DEF\s*\{\\(\w*)\}\s*\{(.*)\}/store_cmd($1,$2,0,$3,$ref_command)/eg; |
||
935 | $TEXT; |
||
936 | } |
||
937 | |||
938 | sub recup_config { my ($cmd, $arg, $ref_env) = @_; |
||
939 | my @L = (split (',', $arg)); |
||
940 | my $style = $L[0]; |
||
941 | my $type = 'style'; |
||
942 | if ($cmd eq 'typefold') { $style = 'fold'; $type = 'type' }; |
||
943 | if ($cmd eq 'typelink') { $style = 'link' ; $type = 'type' }; |
||
734 | bpr | 944 | if ($cmd eq 'tablewims') { $type = 'tabular' ; }; |
23 | reyssat | 945 | if ($cmd eq 'listwims') { $type = 'list' }; |
946 | for my $rubrique (@L) { |
||
947 | $ref_env->{$type}{$rubrique} = $style; |
||
948 | dbg("... commande $rubrique de $type $style"); |
||
949 | if ($cmd eq 'listwims') { $ref_env->{'style'}{$rubrique . '_item'} = $style . '_item' ; |
||
950 | $ref_env->{'titre'}{$rubrique . '_item'} = '' } |
||
951 | } |
||
734 | bpr | 952 | push @liste_env_tabular, (keys %{$ref_env->{tabular}}) ; |
23 | reyssat | 953 | ''; |
954 | } |
||
955 | sub recup_environ {my ($TEXT, $ref_env) = @_; |
||
956 | my $pat = '\s*\{(.*)\}'; |
||
734 | bpr | 957 | $TEXT =~ s/\\(typefold|typelink|samestyle|listwims|tablewims)\{([^\}]+)\}/recup_config($1,$2, $ref_env)/eg; |
23 | reyssat | 958 | # {nom}[#param]{titre}{debut}{fin} |
959 | $TEXT =~ s/\\(environmentwims|[re]?newenvironment)\s*\{(\w*)\}\[(\d)\]$pat$pat$pat/store_environ($1,$2,$3,$4,$5,$6,$ref_env)/eg; |
||
960 | # {nom}{titre}{debut}{fin} |
||
961 | $TEXT =~ s/\\(environmentwims|[re]?newenvironment)\s*\{(\w*)\}$pat$pat/store_environ($1,$2,0,'', $3,$4,$ref_env)/eg; |
||
962 | #\newtheorem{nom}[]?{titre}[]? |
||
963 | $TEXT =~ s /(\\newtheorem\*?)\s*\{(\w*)\}\s*(\[[^\]]*\])?\s*\{([^\}]*)\}\s*(\[[^\]]*\])?\s*/store_environ($1,$2,0,$4,'','',$ref_env)/ge; |
||
964 | $TEXT; |
||
965 | } |
||
966 | |||
967 | #on suppose que le texte commence par \command{}{}{}{} avec le bon nombre d'arguments |
||
968 | |||
969 | sub traite_command {my ($TEXT, $command, $ref_command) = @_; |
||
970 | my $cnt_arg = $ref_command->{cnt_arg}{$command}; |
||
971 | my $com = $ref_command->{definition}{$command}; |
||
972 | if ($cnt_arg) { |
||
973 | $TEXT =~ s/\\$command\s*\{/\{/; |
||
974 | $TEXT = join ( " ", subst($TEXT, $cnt_arg, $com)); |
||
975 | } else { |
||
976 | $TEXT =~ s/\\$command\_/$com . '_'/ge; |
||
977 | $TEXT =~ s/\\$command\b/$com/ge; |
||
978 | } |
||
979 | $TEXT; |
||
980 | } |
||
981 | #Texte = {}{}{} ou []{}{} qui sont les arguments |
||
982 | sub subst { my ($TEXT, $cnt_arg, $com, $environ, $ref_env ) = @_; |
||
983 | my (@a,$u,$v); |
||
984 | my $cnt = 0; |
||
985 | while ($cnt < $cnt_arg) { |
||
986 | @a = extract_tagged($TEXT, '{','}'); |
||
987 | ($u,$v) = ($a[1],$a[4]); |
||
988 | if (!$a[0]) { |
||
734 | bpr | 989 | @a = extract_tagged($TEXT, '\[','\]'); |
990 | ($u,$v) = ($a[1],$a[4]); |
||
23 | reyssat | 991 | } |
992 | $TEXT = $u; |
||
993 | $cnt ++; |
||
920 | bpr | 994 | my $sub="" ; |
995 | if ($v) { |
||
996 | $sub = $environ && $ref_env->{titre}{$environ} ? join (' ' , ( $ref_env->{titre}{$environ}, $v)) : $v;} |
||
997 | else {$sub=''} ; |
||
766 | bpr | 998 | if (($com) && ("#$cnt")) { $com =~ s/#$cnt/$sub/ge ; } ; |
23 | reyssat | 999 | } |
1000 | ($com, $TEXT); |
||
1001 | } |
||
1002 | |||
1003 | sub Traite_command { my ($TEXT, $command, $ref_command) = @_; |
||
1004 | my $cnt_arg = $ref_command->{cnt_arg}{$command}; |
||
1005 | if ($cnt_arg) { |
||
1006 | my @decoup = split ("\\\\$command\{", $TEXT ); |
||
1007 | my $cnt = 1; |
||
1008 | $TEXT = $decoup[0]; |
||
1009 | while ($cnt <= $#decoup) { |
||
1010 | $TEXT .= traite_command ('{' . $decoup[$cnt], $command, $ref_command); |
||
1011 | $cnt++; |
||
1012 | } |
||
1013 | } else { |
||
1014 | while( $TEXT =~ /\\$command\b/) { |
||
1015 | $TEXT = traite_command ($TEXT, $command, $ref_command); |
||
1016 | } |
||
1017 | } |
||
1018 | $TEXT; |
||
1019 | } |
||
1020 | |||
1021 | my %outagain; |
||
1022 | sub out { my ($bloc, $text) = @_; |
||
1023 | warn "Écrase $bloc" if ($outagain{$bloc}); |
||
1024 | $outagain{$bloc} = 1; |
||
1025 | open (OUT, ">$BASE/$bloc") || die "ne peut pas créer $BASE/$bloc"; |
||
1026 | print OUT $text ; close OUT; |
||
1027 | } |
||
1028 | |||
1029 | sub out1 { my ($bloc, $text) = @_; |
||
1030 | warn "Écrase $bloc" if ($outagain{$bloc}); |
||
178 | bpr | 1031 | $outagain{$bloc} = 1; |
23 | reyssat | 1032 | open (OUT, ">$doc_DIR$bloc") || die "ne peut pas créer $doc_DIR/$bloc"; |
1033 | print OUT $text ; close OUT; |
||
1034 | } |
||
1035 | |||
1036 | sub out_def { my ($bloc, $text) = @_; |
||
1037 | open (OUT, ">$BASE0/$bloc") || die "peut pas créer $BASE0/$bloc"; |
||
1038 | print OUT $text ; close OUT; |
||
1039 | } |
||
1040 | |||
1041 | # PASSE 1: développe 'input/include' |
||
1042 | sub find_expand { my ($file) = @_; |
||
1043 | if (!open(IN, $DIR . $file)) { warn "$DIR$file n'existe pas"; return; } |
||
1044 | dbg("... lecture de $file"); |
||
1045 | my $text = <IN>; close(IN); |
||
743 | bpr | 1046 | $text =~ s/([^%]\s*\\end{document})[[:print:][:space:]]+/$1/; |
1047 | $text =~ s/([^%])\s*\\endinput[[:print:][:space:]]+/$1/; |
||
1048 | $text =~ s/\%\\(input|include|wimsinclude)([^\n]+)?//g; |
||
1049 | $text =~ s/\\(input|include|wimsinclude)\s*{?([a-zA-Z0-9\-_\/]+)\.(sty|tex)\s*}?/find_expand("$2.$3")/eg; |
||
4851 | bpr | 1050 | $text =~ s/\\lstinputlisting\s*\{([a-zA-Z0-9\-_\/\.]+)\s*\}/"\\begin\{lstlisting\}\n" . find_expand($1) . "\n\\end\{lstlisting\}"/eg; |
1051 | |||
23 | reyssat | 1052 | $text; |
1053 | } |
||
1054 | |||
1055 | sub open_close { my ($sec, $cnt, $entre) = @_; |
||
1056 | my ($txt) = ''; |
||
1057 | my ($ind) = $hash_secinv{$sec}; |
||
1058 | #ferme |
||
1059 | for (my $i = $#SECTIONS; $i >= $ind; $i--) |
||
1060 | { |
||
1061 | if ($cnt->[$i]) { $txt .= "</$SECTIONS[$i]>\n"; $cnt->[$i] = 0; } |
||
1062 | } |
||
1063 | #ouvre |
||
1064 | if (!$entre) { |
||
1065 | $txt .= "<$sec>"; $cnt->[$ind] = 1; |
||
1066 | $SEC_MIN_GLOBAL = $ind if ($ind < $SEC_MIN_GLOBAL && $ind); |
||
1067 | } |
||
1068 | $txt; |
||
1069 | } |
||
1070 | |||
1071 | sub cnt_section { my ($sec, $cnt) = @_ ; |
||
1072 | my ($txt) = ''; |
||
1073 | my ($ind) = $hash_secinv{$sec}; |
||
1074 | $SEC_MIN_GLOBAL = $ind if ($ind < $SEC_MIN_GLOBAL && $ind); |
||
1075 | "<$sec>" |
||
1076 | } |
||
1077 | |||
1078 | |||
1079 | sub store { my ($ref, $cle, $id, $text, $court) = @_ ; |
||
1080 | $ref->{$cle}{$id}=$text ; |
||
1081 | if (defined($court)) { $court =~ s/\[|\]//g ; $ref->{tittoc}{$id} = $court ; } ; |
||
1082 | ''; |
||
1083 | } |
||
1084 | sub store_option { my ($A) = @_ ; $A = join(' ' , split(',', $A)) ; |
||
734 | bpr | 1085 | if ($A =~ s/numero//) { $NUMERO = 1 ;} ; |
23 | reyssat | 1086 | if ($A =~ s/index//) { $INDEX = 1 ;} |
734 | bpr | 1087 | if ($A =~ s/tooltip//) { $TOOLTIP = 1 ;} |
23 | reyssat | 1088 | if ($A =~ s/depth\s*=\s*([0-8])//) { $depth = $1 ; } |
1089 | $OPTION .= $A ; |
||
1090 | '' ; |
||
1091 | } |
||
1092 | |||
1093 | sub store_include { my ($A) = @_ ; $A = join(' ' , split(',', $A)) ; |
||
1094 | if ($A =~ s/(\w*)\.(tex|sty)//) { |
||
1095 | if ($MACRO) {$MACRO .= ",$1.$2" } else {$MACRO = "$1.$2" } |
||
1096 | }; |
||
1097 | if ($A =~ s/(\w*\.css)\b//) { if ($STYLE) {$STYLE .= ",$1" } else {$STYLE = $1 } }; |
||
1098 | if ($A =~ s/embed\s*=\s*([^}]+)//) { $EMBED = $1 ; } |
||
1099 | '' ; |
||
1100 | } |
||
1101 | |||
1102 | sub add { my ($a,$b)=@_ ; |
||
1103 | if ($a) {$a .= ",$b" } else {$a = $b } |
||
1104 | } |
||
1105 | |||
1106 | sub Init { my ($file, $ref_env, $ref_command, $ref, $ref_algo) = @_; |
||
1107 | my ($total, $TEXT) = (0, find_expand($file)); |
||
4851 | bpr | 1108 | my %hash_spec = (wims =>{}, verbatim =>{}, lstlisting => {}); |
23 | reyssat | 1109 | my $ref_spec = \%hash_spec; |
1110 | $TEXT = traite_special ($TEXT, $ref_spec->{wims}, $ref,'wims'); |
||
1111 | $TEXT = traite_special ($TEXT, $ref_spec->{verbatim}, $ref,'verbatim'); |
||
4851 | bpr | 1112 | $TEXT = traite_special ($TEXT, $ref_spec->{lstlisting}, $ref,'lstlisting'); |
23 | reyssat | 1113 | $TEXT = traitement_initial ($TEXT); |
1114 | $TEXT =~ s/\\wimsoption\s*\{([^\}]+)\}/store_option($1)/eg ; |
||
1115 | $TEXT =~ s/\\makeindex/store_option('index')/eg ; |
||
1116 | $TEXT =~ s/\\wimsinclude\s*\{([^\}]+)\}/store_include($1)/eg ; |
||
1117 | $TEXT =~ s/\\(title|email|author|about)\s*(\[[^\]]+\])?\s*\{([^\}]+)\}/store($ref,$1,'main',$3,$2)/eg ; |
||
1118 | |||
1119 | $TEXT = traite_preambule ($TEXT, $ref_env, $ref_command, $ref); |
||
1120 | for my $command (keys %{$ref_command->{definition}}) { |
||
1121 | $TEXT = Traite_command ($TEXT, $command, $ref_command); |
||
1122 | } |
||
1123 | for my $A (@liste_voca) { |
||
1124 | $ref_algo->{titre}{$A} = $ref_command->{definition}{"algorithmic\L$A\E"} if ($ref_command->{definition}{"algorithmic\L$A\E"}) ; |
||
1125 | } ; |
||
4851 | bpr | 1126 | $TEXT =~ s/wimsinsertion(\d*)/$ref_spec->{'wims'}{$1}/g; |
4858 | bpr | 1127 | $TEXT =~ s/verbatiminsertion(\d*)/verbatim($ref_spec->{'verbatim'}{$1},$1)/eg; |
4851 | bpr | 1128 | $TEXT =~ s/lstlistinginsertion(\d*)/lstlisting($ref_spec->{'lstlisting'}{$1},$1)/eg; |
23 | reyssat | 1129 | $TEXT; |
1130 | } |
||
1131 | |||
1132 | #sub store_makeindex { my ($txt) = @_ ; |
||
1133 | # $txt =~ s/\\printindex/\link{index}{Index}/ ; |
||
1134 | # } |
||
1135 | sub traitement_final { my ($TEXT) = @_; |
||
1136 | #FIXME : je ne peux pas faire ca à cause des exercices de développement dont l'adresse |
||
1137 | #contienne un ~. De toute facon |
||
1138 | #ca ne devrait pas exister, mais quand même. ou les wims only |
||
1139 | # $TEXT =~ s/~/ /g; |
||
6858 | bpr | 1140 | $TEXT =~ s:(<br class="spacer" />\s*<br class="spacer" />):<br class="spacer" />:g; |
1141 | $TEXT =~ s:<br class="spacer" />\s*(</?div):$1:g; |
||
1142 | $TEXT =~ s:(class="minipage">)\s*<br class="spacer" />:$1:g; |
||
23 | reyssat | 1143 | $TEXT; |
1144 | } |
||
1145 | |||
1146 | sub traitemath {my ($txt) = @_; |
||
1147 | my $test = 0; |
||
1148 | while ($txt =~ /\$\$/) { |
||
6169 | bpr | 1149 | $txt = $` . ($test == 0 ? '<div class="math">\\(\\displaystyle{' : '}\\)</div>') . $'; |
23 | reyssat | 1150 | $test = 1-$test; |
1151 | } |
||
1152 | $txt; |
||
1153 | } |
||
1154 | |||
1155 | sub traitement_initial { my ($TEXT) = @_; |
||
1156 | $TEXT =~ s/\s*$//; # strip trailing whitespace |
||
1157 | $TEXT =~ s/\r\n/\n/gs ; |
||
1158 | $TEXT = traitemath($TEXT); |
||
1159 | $TEXT =~ s/{\s*\\(bf|tt|it)\b/\\text$1\{/g; |
||
1160 | $TEXT =~ s/\\begin\b\s*/\\begin/g; |
||
1161 | $TEXT =~ s/\\end\b\s*/\\end/g; |
||
1162 | #$TEXT =~ s/\\text\b/\\hbox/g; |
||
1163 | $TEXT =~ s,\\\[,<p class="math">\\(,g; |
||
1164 | $TEXT =~ s,\\\],\\)</p>,g; |
||
1165 | $TEXT =~ s/\$([^\$]+)\$/\\( $1 \\)/g; |
||
1166 | |||
1167 | $TEXT =~ s/\\`\s*{a}/à/g; |
||
1168 | $TEXT =~ s/\\\^\s*{a}/â/g; |
||
1169 | $TEXT =~ s/\\'\s*{a}/á/g; |
||
1170 | $TEXT =~ s/\\'\s*{e}/é/g; |
||
1171 | $TEXT =~ s/\\`\s*{e}/è/g; |
||
1172 | $TEXT =~ s/\\\^\s*{e}/ê/g; |
||
1173 | $TEXT =~ s/\\\^\s*{i}/î/g; |
||
1174 | $TEXT =~ s/\\\`\s*{i}/ì/g; |
||
1175 | $TEXT =~ s/\\\"\s*{i}/ï/g; |
||
178 | bpr | 1176 | $TEXT =~ s/\\\"\s*{\\i}/ï/g; |
23 | reyssat | 1177 | $TEXT =~ s/\\\^\s*{o}/ô/g; |
1178 | $TEXT =~ s/\\\"\s*{o}/ö/g; |
||
1179 | $TEXT =~ s/\\\`\s*{o}/ò/g; |
||
1180 | $TEXT =~ s/\\\^\s*{u}/û/g; |
||
1181 | $TEXT =~ s/\\`\s*{u}/ù/g; |
||
1182 | $TEXT =~ s/\\c\s*\{c\}/ç/g; |
||
1183 | |||
1184 | $TEXT =~ s/\\`\s*a/à/g; |
||
1185 | $TEXT =~ s/\\\^\s*a/â/g; |
||
1186 | $TEXT =~ s/\\'\s*a/á/g; |
||
1187 | $TEXT =~ s/\\'\s*e/é/g; |
||
1188 | $TEXT =~ s/\\`\s*e/è/g; |
||
1189 | $TEXT =~ s/\\\^\s*e/ê/g; |
||
3846 | bpr | 1190 | $TEXT =~ s/\\`\s*E/È/g; |
1191 | $TEXT =~ s/\\\'\s*E/É/g; |
||
1192 | $TEXT =~ s/\\\^\s*E/Ê/g; |
||
23 | reyssat | 1193 | $TEXT =~ s/\\\^\s*i/î/g; |
1194 | $TEXT =~ s/\\\`\s*i/ì/g; |
||
1195 | $TEXT =~ s/\\\"\s*i/ï/g; |
||
1196 | $TEXT =~ s/\\\^\s*o/ô/g; |
||
1197 | $TEXT =~ s/\\\"\s*o/ö/g; |
||
1198 | $TEXT =~ s/\\\`\s*o/ò/g; |
||
1199 | $TEXT =~ s/\\\^\s*u/û/g; |
||
1200 | $TEXT =~ s/\\`\s*u/ù/g; |
||
1201 | $TEXT =~ s/\\c \s*c/ç/g; |
||
1202 | |||
1203 | $TEXT =~ s/{\s*\\`\s*a\s*}/à/g; |
||
1204 | $TEXT =~ s/{\s*\\\^\s*a\s*}/â/g; |
||
1205 | $TEXT =~ s/{\s*\\'\s*a\s*}/á/g; |
||
1206 | $TEXT =~ s/{\s*\\'\s*e\s*}/é/g; |
||
1207 | $TEXT =~ s/{\s*\\`\s*e\s*}/è/g; |
||
1208 | $TEXT =~ s/{\s*\\\^\s*e\s*}/ê/g; |
||
1209 | $TEXT =~ s/{\s*\\\^\s*i\s*}/î/g; |
||
1210 | $TEXT =~ s/{\s*\\\`\s*i\s*}/ì/g; |
||
1211 | $TEXT =~ s/{\s*\\\"\s*i\s*}/ï/g; |
||
1212 | $TEXT =~ s/{\s*\\\^\s*o\s*}/ô/g; |
||
1213 | $TEXT =~ s/{\s*\\\"\s*o\s*}/ö/g; |
||
1214 | $TEXT =~ s/{\s*\\\`\s*o\s*}/ò/g; |
||
1215 | $TEXT =~ s/{\s*\\\^\s*u\s*}/û/g; |
||
1216 | $TEXT =~ s/{\s*\\`\s*u\s*}/ù/g; |
||
1217 | $TEXT =~ s/{\s*\\c \s*c\s*}/ç/g; |
||
6693 | bpr | 1218 | $TEXT =~ s/\\maketitle//g; |
3846 | bpr | 1219 | $TEXT =~ s/{\\textquotesingle}/'/g; |
1220 | $TEXT =~ s/\\textquotesingle/'/g; |
||
1221 | $TEXT =~ s/\\guillemotleft/<</g; |
||
1222 | $TEXT =~ s/\\guillemotright/>>/g; |
||
4627 | bpr | 1223 | # MODIF YVES NOEL 19/09/2011 (debut) |
1224 | $TEXT =~ s/>>/>>/g; |
||
1225 | $TEXT =~ s/~~/ /g; |
||
1226 | $TEXT =~ s/\\onslide\+<[0-9]*>//g; |
||
1227 | $TEXT =~ s/\\onslide<[0-9]*->//g; |
||
1228 | $TEXT =~ s/\\onslide<[0-9]*>//g; |
||
1229 | $TEXT =~ s/\\onslide\+<[0-9]*\-[0-9]*>//g; |
||
1230 | $TEXT =~ s/\\onslide<[0-9]*\-[0-9]*->//g; |
||
1231 | $TEXT =~ s/\\onslide<[0-9]*\-[0-9]*>//g; |
||
6003 | bpr | 1232 | $TEXT =~ s/\[<\+->\]//g; |
1233 | |||
4627 | bpr | 1234 | # MODIF YVES NOEL 19/09/2011 (fin) |
3846 | bpr | 1235 | $TEXT =~ s/{}//g; |
1236 | $TEXT =~ s/\\selectlanguage{french}\\sffamily//g; |
||
23 | reyssat | 1237 | |
1238 | #$TEXT =~ s/([^\\])\%+/$1/g; |
||
1239 | $TEXT =~ s/([^\\])\%.*/$1/g; |
||
1240 | $TEXT =~ s/\n\%.*/\n/g; |
||
1241 | $TEXT =~ s/\\\\\[\S*\]/\n\n/g; |
||
1242 | $TEXT =~ s/\\(vspace|hspace|vskip|hskip)\**{\S*}//g; |
||
1243 | $TEXT =~ s/\\parskip=*[a-z0-9 \.]+//g; |
||
1244 | $TEXT =~ s/\\(vskip|hskip)\s*[a-z0-9 \.]+//g; |
||
1245 | $TEXT =~ s/\\smallskip/\n/g; |
||
1246 | $TEXT =~ s/\\(med|big)skip/\n\n/g; |
||
1247 | # $TEXT =~ s/\\makebox\[(\w)cm\]{ }/\ \ \ /g; |
||
1248 | $TEXT =~ s/~(:|;|\?|\!)/ $1/g; |
||
1249 | #utiliser verb uniquement dans le cas d'un mot |
||
1250 | #FIXME: $TEXT =~ s/\verb"([^"]+)"/<tt class=verb>$1<\/tt>/g; |
||
4852 | bpr | 1251 | $TEXT =~ s/\\includegraphics\s*\[(.*)\]\s*{(.*)}/includegraphics($2,$1)/eg; |
1252 | $TEXT =~ s/\\includegraphics\s*{([^}]+)}/includegraphics($1)/eg; |
||
23 | reyssat | 1253 | $TEXT =~ s/\\(begin|end){document}/\\document /g; |
1254 | $TEXT =~ s/\\exercise{module=([^\&]+)\&([^}]+)}{([^}]+)}/store_sheet($1,$2,$3,$worksheet)/eg ; |
||
734 | bpr | 1255 | $TEXT =~ s/\\xspace//g; |
5362 | bpr | 1256 | $TEXT = traite_beamer($TEXT) ; |
23 | reyssat | 1257 | $TEXT; |
1258 | } |
||
1259 | |||
5362 | bpr | 1260 | sub traite_beamer { my ($TEXT) = @_; |
1261 | $TEXT =~ s/\\uncover\s*(<([^>]+)>)?\s*{(.*)}/\\fold{.}{-->}{$3}/g ; |
||
1262 | $TEXT =~ s/\s*\\frametitle{([^}]+)}/store_frametitle($1)/ge; |
||
6104 | bpr | 1263 | $TEXT =~ s/\\pause//g; |
5362 | bpr | 1264 | $TEXT ; |
1265 | } |
||
1266 | |||
1267 | sub store_frametitle{ my ($TEXT)= @_ ; |
||
1268 | "<div class=\"frametitle\">$TEXT</div>" |
||
1269 | } |
||
4852 | bpr | 1270 | sub linewidth { my ($line,$w)= @_ ; |
4858 | bpr | 1271 | $line =~ s/1\.[0]\s*\\(line|text)width/100\%/g; |
1272 | $line =~ s/0?\.([0-9])\s*\\(line|text)width/$1 0\%/g; |
||
1273 | $line =~ s/0?\.([0-9]{2})[0-9]?\s*\\(line|text)width/$1\%/g; |
||
4850 | bpr | 1274 | $line =~ s/ //g; |
4852 | bpr | 1275 | $line = "$w=\"$line\"" if ($w) ; |
1276 | $line ; |
||
4850 | bpr | 1277 | } |
178 | bpr | 1278 | sub store_sheet { my ($ad1,$ad2,$titre,$worksheet) = @_ ; |
1279 | $ad2 =~ s/worksheet=(\d)+//g ; |
||
1280 | $SHEET .= ":$ad1\n$ad2\n$titre\n\n" ; |
||
23 | reyssat | 1281 | "\\exercise\{module=$ad1\&$ad2\&worksheet=$worksheet\}\{$titre\}" ; |
1282 | } |
||
1283 | |||
1284 | sub traite_preambule { my ($TEXT, $ref_env, $ref_command, $ref) = @_; |
||
1285 | if ($TEXT=~ s/\\usepackage\[([^]]+)\]\{algorithmic\}//) { |
||
1286 | $algo_noend = 1 if ($1 =~ /noend/); |
||
7228 | bpr | 1287 | }; |
1288 | $TEXT = recup_command($TEXT, $ref_command); |
||
1289 | $TEXT = traite_command($TEXT, $ref_command); |
||
23 | reyssat | 1290 | $TEXT = recup_environ($TEXT, $ref_env); |
7228 | bpr | 1291 | |
1292 | |||
23 | reyssat | 1293 | $TEXT = recup_embed($TEXT, $ref) ; |
1294 | for my $cmd ('ref','index') { |
||
1295 | $ref->{titb}{$cmd} = $ref_command->{definition}{$cmd . "name"} |
||
1296 | } |
||
1297 | $TEXT; |
||
1298 | } |
||
1299 | |||
1300 | sub store_embed { my ($id, $titre, $ref) = @_ ; |
||
1301 | $ref->{titb}{$id} = $titre ; $ref->{text}{$id} = `cat $EMBED/$id` ; |
||
1302 | $ref->{upbl}{$id}='main'; $ref->{type}{$id}='embed'; |
||
1303 | "\\embed{$id}{$titre}" ; |
||
1304 | } |
||
1305 | |||
1306 | sub recup_embed { my ($TEXT, $ref) = @_ ; |
||
1307 | $TEXT =~ s /\\embed\s*{([^}]+)}\s*{(.*)}/store_embed ($1, $2, $ref)/eg ; |
||
1308 | $TEXT ; |
||
1309 | } |
||
1310 | |||
1311 | #FIXME on ne peut prendre qu'un seul fichier de style |
||
1312 | #crée le fichier 1/.def |
||
1313 | sub def { my ($ref, @style) = @_; |
||
1314 | my $tit = $ref->{title}{main}; |
||
1315 | my $aut = $ref->{author}{main}; |
||
1316 | my $mail= $ref->{email}{main}; |
||
1317 | my $datm= $ref->{datm}{main}; |
||
6644 | bpr | 1318 | my $header = '<link rel="stylesheet" href="html/themes/_css/l2w.css" type="text/css" />' ; |
23 | reyssat | 1319 | my $header_tmp ; |
1320 | for my $file (@style){ |
||
1321 | if (!open(IN, $DIR . $file)) { die "le fichier $DIR$file n'existe pas";} |
||
1322 | open (IN, $DIR . $file); |
||
1323 | ($header_tmp = <IN>) =~ s/\n/\t/g; |
||
1324 | $header .= "\t $header_tmp" ; |
||
1325 | } |
||
1326 | close IN; |
||
6644 | bpr | 1327 | $header .= "\t<script type=\"text/javascript\">" |
1328 | . "jQuery(function() {jQuery( \"#left_toc\" ).menu();});" |
||
1329 | . "jQuery(function() {jQuery( \"#right_toc\" ).menu();});" |
||
6619 | bpr | 1330 | . "</script>" if ($TOOLTIP==1); |
1331 | |||
23 | reyssat | 1332 | "copyright=gnu |
1333 | docopen=yes |
||
1334 | dlang=fr |
||
1335 | tit=$tit |
||
1336 | author=$aut |
||
1337 | email=$mail |
||
1338 | header=$header |
||
1339 | datm=$datm"; |
||
1340 | } |
||
1341 | #TODO en fait il faudrait renvoyer dans le cas ou le fichier est de type fold à la page en dessus |
||
1342 | # dépliée. Je ne suis pas sure de savoir faire ! sinon, on perd la table des matières. |
||
1343 | |||
1344 | sub store_ref { my ($link, $titre, $anchor, $ref_bloc) = @_; |
||
1345 | my $txt = '' ; |
||
1346 | my @list = (split(',', $link)) ; |
||
1347 | for my $l (@list) { |
||
1348 | dbg("... référence fichier: \"$l\" titre \"$l\""); |
||
1349 | my $page = $ref_bloc->{fichier}{$l} ; |
||
1350 | warn "label $link n'existe pas" if !($page) ; |
||
1351 | $txt .= ($#list) ? " \\link{$page}{$l}{$anchor}": |
||
1352 | " \\link{$page}{$titre}{$anchor}"; |
||
1353 | } |
||
1354 | $txt ; |
||
1355 | }; |
||
1356 | |||
1357 | |||
1358 | #crée la page |
||
1359 | |||
743 | bpr | 1360 | sub toc_HTML {my ($text, $toc_g, $toc_d, $CHEMIN_up, $CHEMIN_down, $index) = @_ ; |
5362 | bpr | 1361 | my $s='' ; |
1362 | $s= "l" if($toc_g) ; $s .= "r" if($toc_d) ; |
||
23 | reyssat | 1363 | if (($toc_g) || ($toc_d)) { |
5362 | bpr | 1364 | $CHEMIN_up . '<div class="doc_latex2wims' . $s . '">' |
6638 | bpr | 1365 | . (($toc_g) ? '<ul id="left_toc" class="left_toc">'. $toc_g |
6614 | bpr | 1366 | . $index . '</ul>' : '') |
5362 | bpr | 1367 | . '<div class="wimsdoc">' |
23 | reyssat | 1368 | . $text |
5362 | bpr | 1369 | . '</div>' |
6614 | bpr | 1370 | . (($toc_d) ? '<ul id="right_toc" class="right_toc">' |
23 | reyssat | 1371 | . $toc_d |
5874 | bpr | 1372 | . '<div class="wimscenter">' |
23 | reyssat | 1373 | . $LOAD |
5874 | bpr | 1374 | . '</div></div>' : '') |
5664 | bpr | 1375 | . $CHEMIN_down . |
1376 | '</div>'; |
||
1377 | |||
5362 | bpr | 1378 | } |
1379 | |||
743 | bpr | 1380 | else {$CHEMIN_up . $text . $CHEMIN_down }; |
23 | reyssat | 1381 | } |
1382 | |||
1383 | ################################# |
||
1384 | |||
1385 | sub store_algo { my ($txt, $acc, $cmd, $comment, $indent) = @_ ; |
||
1386 | $txt .= " " . $acc ; |
||
1387 | $txt .= $hash_algo{titre}{$hash_algo{suite}{$cmd}} if ($hash_algo{suite}{$cmd}) ; |
||
1388 | $indent = $indent + $hash_algo{avant}{$cmd} ; |
||
6472 | bpr | 1389 | if($hash_algo{titre}{$cmd}) { |
1390 | $txt = "\n" . indent($indent) . $hash_algo{titre}{$cmd} . $txt if ( !($cmd =~ /END/) || $algo_noend == 0); |
||
1391 | } |
||
1392 | else |
||
1393 | { |
||
1394 | $txt = "\n" . indent($indent) . $txt if ( !($cmd =~ /END/) || $algo_noend == 0); |
||
1395 | } |
||
1396 | $txt .= indent('3') . "{<i>$comment</i>}" if ($comment) ; |
||
23 | reyssat | 1397 | $txt .= "\n" ; |
1398 | $txt =~ s/\n+/\n/ ; |
||
1399 | $indent += $hash_algo{apres}{$cmd} ; |
||
1400 | ($txt, $indent) ; |
||
1401 | } |
||
1402 | |||
1403 | sub algorithm { '<div class="algorithm">' . algorithmic (@_) . '</div>' } ; |
||
1404 | |||
1405 | sub algorithmic { my ($Text) = @_; |
||
1406 | my $text ='' ; my $indent = 0 ; |
||
1407 | my @T = split('\n', $Text); |
||
1408 | for my $i (1..$#T) { |
||
1409 | my $ligne = $T[$i]; |
||
1410 | # $ligne =~ s/\$([^\$]+)\$/$1/g; |
||
1411 | # $ligne =~ s/\\\(//g; |
||
1412 | # $ligne =~ s/\\\)//g; |
||
1413 | $ligne =~ s/\$([^\$]+)\$/\\( $1 \\)/g; |
||
1414 | $ligne =~ s/^\[H\]//; |
||
1415 | next if ($ligne =~ /\\begin\{algorithmic\}\[1\]/); |
||
1416 | $ligne = "\n\n" if ($ligne =~ /\\end\{algorithmic\}/); |
||
1417 | $ligne =~ s/\\caption\s*\{\s*([^\}]*)\}/<h4 class=\"algo_titre\"> $1 <\/h4>/; |
||
1418 | $ligne =~ s/\\cdots/.../g; |
||
1419 | $ligne =~ s/\\geq/>=/g; |
||
1420 | $ligne =~ s/\\leq/<=/g; |
||
1421 | $ligne =~ s/\\bmod/mod/g; |
||
1422 | # $ligne =~ s/\[/<i>/g; |
||
1423 | # $ligne =~ s/\]/<\/i>/g; |
||
1424 | my $cle = 'FOR|WHILE|IF|UNTIL|ELSE|ELSIF|REQUIRE|ENSURE|STATE|ENDFOR|ENDWHILE|ENDIF' ; |
||
1425 | if ($ligne =~ /\s*\\($cle)\s*(\[[^\]]+\]*)?\{([^\n]+)\}\s*([^\n]*)/) { |
||
1426 | ($ligne,$indent) = store_algo($3, $4, $1, $2, $indent) ; |
||
1427 | } |
||
1428 | if ($ligne =~ /\s*\\($cle)\s*(\[[^\]]+\]*)?\s*([^\n]*)/) {($ligne,$indent) = store_algo('',$3, $1, $2, $indent);} |
||
1429 | #TODO accepter des commentaires de plusieurs lignes ; présentation |
||
1430 | #des commentaires ? |
||
1431 | if ($ligne =~ /^\s*\\COMMENT/) { $ligne = "<i>$ligne</i>\n" }; |
||
1432 | $text .= "\n" . $ligne; |
||
6472 | bpr | 1433 | $text =~ s/\n{2,}/\n/g; |
1434 | $text =~ s/(<br\s*\/>)+/<br \/>/g; |
||
1435 | $text =~ s/(<br>)+/<br \/>/g; |
||
23 | reyssat | 1436 | } |
6472 | bpr | 1437 | $text =~ s/\n/<br \/>/g; |
23 | reyssat | 1438 | $text ; |
1439 | } |
||
1440 | |||
1441 | sub indent { my $espace = " " x 6 ; $espace x $_[0]; } |
||
1442 | |||
1443 | sub Numero { my ($id) = @_; |
||
1444 | return '' if ($id =~ /F_[^S]\d/) || ($id =~ /L_/); #cela ne provient pas d'une section et co |
||
1445 | $id =~ s /(F|L)_//g; |
||
1446 | $id =~ s/mainS(\d+)/&Roman($1)/e; |
||
1447 | $id =~ s/S(\d+)S(\d+)S(\d+)/-$1-$2-$3/; |
||
1448 | $id =~ s/S(\d+)S(\d+)/-$1-$2/; |
||
1449 | $id =~ s/S(\d+)/-$1/; |
||
1450 | $id; |
||
1451 | } |
||
1452 | |||
1453 | # permet de faire modifier quelque chose dans la table pour un tag |
||
1454 | #TODO j'ai rajouté l'option couleur, du coup je ne sais plus faire fonctionner le shif |
||
1455 | sub selection { my ($text, $couleur, @tag) = @_ ; |
||
1456 | return '' if !defined($text); |
||
1457 | for my $ta (@tag) { |
||
6614 | bpr | 1458 | $text =~ s/XXXX="$ta">/li class="$couleur">/g; |
1459 | $text =~ s/YYYY="$ta">/\/li>/g; |
||
23 | reyssat | 1460 | }; |
1461 | $text; |
||
1462 | } |
||
1463 | |||
734 | bpr | 1464 | sub clean { my ($text, $ref) = @_; |
23 | reyssat | 1465 | return '' if !defined($text); |
6614 | bpr | 1466 | $text =~ s/<XXXX="\w*">/<li class="no_selected">/g; |
1467 | $text =~ s/<YYYY="\w*">/<\/li>/g; |
||
734 | bpr | 1468 | $text =~ s/ZZZZZ(\w+)/store_tip($1,$ref)/ge; |
23 | reyssat | 1469 | $text; |
1470 | } |
||
1471 | |||
734 | bpr | 1472 | sub store_tip { my ($tag,$ref)=@_ ; |
1473 | my $tip = $ref->{toctip}{$tag} ; |
||
3552 | bpr | 1474 | my $title=$ref->{tittoc}{$tag} ; |
6614 | bpr | 1475 | #$tip =~ s/'/\\\\'/g if ($tip) ; |
1476 | $title =~ s/'/\\\\'/g if ($title) ; |
||
1477 | $ref->{toctip}{$tag} ? "<ul>$tip</ul>" : '' ; |
||
734 | bpr | 1478 | } |
1479 | |||
23 | reyssat | 1480 | sub chemin { my ($tag, $ref) = @_; |
1481 | my $tagsup = $tag; |
||
1482 | my $ch = $tag; |
||
1483 | my $txt = ($ref->{tittoc}{$tagsup}) ? $ref->{tittoc}{$tagsup} : $ref->{titb}{$tagsup} ; |
||
1484 | my $niv = 0; |
||
1485 | while ($tagsup !~ /^main\b/) { |
||
1486 | $niv++; |
||
1487 | $tagsup = $ref->{upbl}{$tagsup}; |
||
6644 | bpr | 1488 | $ch = "$tagsup,$ch"; if (!$ref->{tittoc}{$tagsup}) { $ref->{tittoc}{$tagsup}=$tagsup}; |
1489 | $txt = "\\link{$tagsup}{$ref->{tittoc}{$tagsup}} $FLECHE $txt" if ($tagsup) ; #if ($tagsup !~ /^main\b/); |
||
23 | reyssat | 1490 | } |
1491 | $ref->{chemin}{$tag} = $ch; |
||
1492 | $ref->{niveau}{$tag} = $niv; |
||
1493 | return $LOAD if (!$txt); |
||
743 | bpr | 1494 | '<div class="wims_chemin">' . $LOAD . "$linkout $txt" . '</div>';} |
23 | reyssat | 1495 | |
1496 | sub sortuniq { |
||
1497 | my $prev = "not $_[0]"; |
||
1498 | grep { $_ ne $prev && ($prev = $_, 1) } sort @_; |
||
1499 | } |
||
1500 | |||
1501 | |||
1502 | sub isotime { |
||
178 | bpr | 1503 | my ($sec,$min,$hour,$mday,$mon,$year) = localtime(time); |
23 | reyssat | 1504 | $year += 1900; |
178 | bpr | 1505 | $mon += 1 ; $mday += 1 ; |
23 | reyssat | 1506 | $mday = sprintf("%02d", $mday); |
1507 | $mon = sprintf("%02d", $mon); |
||
1508 | "$year-$mon-$mday $hour:$min:$sec"; |
||
1509 | } |
||
1510 | |||
1511 | sub usage { |
||
1512 | print STDERR << "EOT" |
||
1513 | latex2wims [--style=style.css] [--macro=wims.sty] [--dir=dossier1] [--docdir=dossier2] [--embed=dossier3] [--verbose] file |
||
1514 | |||
1515 | --style=style.css : style.css fichier de style css à utiliser |
||
1516 | (peut aussi être mis dans le fichier file : \\wimsinclude{style.css}) |
||
1517 | --macro=wims.sty : wims.sty fichier de style à utiliser |
||
1518 | (peut aussi être mis dans le fichier file : \\wimsinclude{wims.sty}) |
||
1519 | --dir=dossier1 : dossier1 est le répertoire où se trouvent tous les fichiers dont le fichier file |
||
1520 | --docdir=dossier2 : dossier2 est le répertoire dans lequel sera créé le document |
||
1521 | (un dossier dans le compte Modtool par exemple) |
||
1522 | --embed=dossier3 : les fichiers de dossier3 sont appelés dans file |
||
1523 | par la commande \embed{} (pour expert) |
||
1524 | --verbose : détails |
||
1525 | EOT |
||
1526 | ; |
||
1527 | exit 1; |
||
1528 | } |
||
1529 | |||
1530 | ##======================================================================## |
||
1531 | ## Adapted from work by OZAWA Sakuro <ozawa@prince.pe.u-tokyo.ac.jp> |
||
1532 | ## Copyright (c) 1995 OZAWA Sakuro. All rights reserved. This |
||
1533 | ## program is free software; you can redistribute it and/or modify |
||
1534 | ## it under the same terms as Perl itself. |
||
1535 | ##======================================================================## |
||
1536 | |||
1537 | sub Roman { my($arg) = shift; |
||
1538 | my %roman_digit = qw(1 IV 10 XL 100 CD 1000 MMMMMM); |
||
1539 | my @figure = reverse sort keys %roman_digit; |
||
1540 | grep($roman_digit{$_} = [split(//, $roman_digit{$_}, 2)], @figure); |
||
1541 | |||
1542 | my($x, $roman); |
||
1543 | foreach (@figure) { |
||
1544 | my($digit, $i, $v) = (int($arg / $_), @{$roman_digit{$_}}); |
||
1545 | if (1 <= $digit and $digit <= 3) { |
||
1546 | $roman .= $i x $digit; |
||
1547 | } elsif ($digit == 4) { |
||
1548 | $roman .= "$i$v"; |
||
1549 | } elsif ($digit == 5) { |
||
1550 | $roman .= $v; |
||
1551 | } elsif (6 <= $digit and $digit <= 8) { |
||
1552 | $roman .= $v . $i x ($digit - 5); |
||
1553 | } elsif ($digit == 9) { |
||
1554 | $roman .= "$i$x"; |
||
1555 | } |
||
1556 | $arg -= $digit * $_; |
||
1557 | $x = $i; |
||
1558 | } |
||
1559 | $roman |
||
1560 | } |