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