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