Subversion Repositories wimsdev

Rev

Rev 11039 | Rev 11275 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
11274 schaersvoo 1
#!/usr/local/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
27
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 = '' ;
5696 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; }
7387 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) ;
82
 
7232 bpr 83
my $BASE = $doc_DIR . "doc/$SUBDIR/src";
84
my $BASE0= $doc_DIR . "doc/$SUBDIR";
85
 
6156 bpr 86
my $LOAD = '\reload{<img src="gifs/doc/etoile.gif" alt="rechargez" style="width:20px;height:20px;" />}';
6612 bpr 87
my $FLECHE = '&#8594;';
7387 bpr 88
$linkout = "\\doc{module=$linkout}" . $FLECHE if ($linkout) ;
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',
7387 bpr 124
  'displaymath', 'math', 'center', 'minipage', 'lstlisting', 'columns', 'column', 'figure');
23 reyssat 125
 
7387 bpr 126
my @liste_com_spec = ('paragraph', 'href', 'url', 'exercise', 'doc') ; #je ne m'en sers pas encore
23 reyssat 127
 
10824 bpr 128
#commandes par defaut : sont ecrases par un \def ou un \defwims
7387 bpr 129
 
23 reyssat 130
#$hash_command{cnt_arg}{text} = 1 ;
131
#$hash_command{definition}{text} = '\) #1 \(' ;
132
#$hash_command{origin}{text} = 'defaut' ;
133
 
134
$hash_command{cnt_arg}{paragraph} = 1 ;
135
$hash_command{definition}{paragraph} = '<p class="paragraph"> #1 </p>' ;
136
$hash_command{origin}{paragraph} = 'defaut' ;
137
 
138
$hash_command{cnt_arg}{href} = 2 ;
5663 bpr 139
$hash_command{definition}{href} = '<a href="http:#1" target="wims_external">#2</a>';
23 reyssat 140
$hash_command{origin}{href} = 'defaut' ;
141
 
142
$hash_command{cnt_arg}{url} = 1 ;
5663 bpr 143
$hash_command{definition}{url} = '<a href="http:#1" target="wims_external">#1</a>';
23 reyssat 144
$hash_command{origin}{url} = 'defaut' ;
145
 
146
$hash_command{cnt_arg}{exercise} = 2 ;
147
$hash_command{definition}{exercise} = "\\exercise\{\#1\}\{\#2\}";
148
$hash_command{origin}{exercise} = 'defwims' ;
149
 
150
$hash_command{cnt_arg}{doc} = 2 ;
151
$hash_command{definition}{doc} = '\doc{#1&cmd=new}{#2}';
152
$hash_command{origin}{doc} = 'defwims' ;
153
 
10824 bpr 154
#a un label est associe son bloc [nom de fichier]
23 reyssat 155
my %hash_bloc = (
156
  fichier  => {},
157
  titre    => {},
158
);
159
 
160
my %hash_index = (
161
  page    => {},
162
);
163
 
10824 bpr 164
#type sert a reperer les fichiers embed ou fold.
23 reyssat 165
my %hash = (
166
  text   => {},
167
  prev   => {},
168
  next   => {},
169
  upbl   => {},
170
  titb   => {},
171
  tittoc => {},
172
  keyw   => {},
173
  datm   => {},
174
  label  => {},
175
  toc    => {},
176
  chemin => {},
177
  niveau => {},
7387 bpr 178
  type   => {},
23 reyssat 179
  author => {},
180
  title => {},
181
  email => {},
734 bpr 182
  toctip => {},
23 reyssat 183
);
184
 
185
my %hash_toc = ();
186
 
187
my %prefixe = ( fold => 'F_' , link => 'L_' );
4627 bpr 188
 
23 reyssat 189
my %hash_secinv;
190
for (my $i = 0; $i <= $#SECTIONS; $i++) { $hash_secinv{$SECTIONS[$i]} = $i; }
191
 
10824 bpr 192
my (%errmsg); # empeche le re-affichage d'un même warning.
23 reyssat 193
$SIG{__WARN__} = sub { my ($x) = @_;
194
  return if $errmsg{$x};
195
  $errmsg{$x} = 1;
196
  print STDERR "### $x";
197
};
198
 
199
system("mkdir -p $BASE0") if (!$ENV{'wims_exec_parm'});
200
system("mkdir -p $BASE") if (!$ENV{'wims_exec_parm'});
201
 
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',
7387 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
343
#attention : dans le cas où il y a un \\embed{toto}, il faut creer le fichier toto.hd ...
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/) ;
380
  my $pat= '<br\s+class="spacer"\s*/>';
10837 bpr 381
  $txt = $tooltip . toc_HTML ($txt, clean($TOCg,\%hash), clean($TOCd,\%hash), clean($TOCp,\%hash), $CHEMIN_up, $CHEMIN_down, $index);
6693 bpr 382
  $txt =~ s/$pat\s*$pat/<br class="spacer" \>/g;
383
  out ($tag, $txt );
23 reyssat 384
}
385
if ($INDEX == 1) { out ('index.hd', hd('index',\%hash) )};
386
my @style = sortuniq(split(',',$STYLE)) if ($STYLE) ;
387
out_def ('.def', def (\%hash, @style ));
388
 
389
##############
390
 
391
sub analyse_texte { my ($TEXT, $ref, $Id, $niveau, $niveau_max, $Toc) = @_;
392
  my $link = ($niveau <= $niveau_max);
393
  return $Toc if $niveau > $#SECTIONS ;
394
  my $section = $SECTIONS[$niveau];
395
  my $sectiontag = "<$section>";
396
  my @decoup = split (/$sectiontag/, $TEXT);
397
  my $text = $decoup[0];
398
  my $toc_titre ;
399
  my ($cnt, $id) = (1, "");
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] : '' ;
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
}
450
 
451
sub store_tag { my ($cle, $label, $tag, $ref, $ref_bloc) = @_;
452
  $ref->{$cle}{$tag} = $ref_bloc->{fichier}{$label} ;
453
  '';
454
}
455
 
456
sub store_label { my ($label, $Id, $ref) = @_;
7387 bpr 457
   $ref->{fichier}{$label} = $Id;
5894 bpr 458
   "<a id=\"$label\"></a>";
23 reyssat 459
}
460
 
461
sub dbg { print STDERR "$_[0]\n" if ($verbose); }
462
 
463
sub store_index { my ($label, $Id, $ref_index) = @_;
464
   dbg("... index: \"$label\"");
465
   my $L = $ref_index->{page}{$label};
10234 bpr 466
   $ref_index->{page}{$label} = !$L ? $Id : "$L,$Id";
5894 bpr 467
   "<a id=\"$label\"></a>";
23 reyssat 468
}
469
 
7387 bpr 470
sub class_index { my ($index,$level) = @_ ;
471
     my @a = split('!', $index) ;
472
     ($a[$level])? $a[$level] : $index ;
23 reyssat 473
 }
474
 #!(keys %{$ref_index->{page}}
7387 bpr 475
 #sort keys %{$ref_index->{page}} ;
23 reyssat 476
 
5664 bpr 477
sub makeindex { my ($ref_index, $level, @L ) = @_;
23 reyssat 478
   return '' if (!$#L) ;
479
   my $dejavu = '' ;
480
   my $TEXT = "\n<ul class=\"index\">";
481
   for my $index (@L) {
7387 bpr 482
      next if ($dejavu =~ /\b$index\b/) ;
23 reyssat 483
      my @list = sort {$a cmp $b} grep {class_index($_, $level) eq class_index($index, $level)} @L ;
7387 bpr 484
      my @l = split('!', $index) ;
23 reyssat 485
      if ($l[$level]) {
7387 bpr 486
          $TEXT .= "<li> " ;
23 reyssat 487
          for my $ind (split(',',$ref_index->{page}{$index})) {
7387 bpr 488
             if ($ind && !($dejavu =~ /\b$ind\b/)) {
10234 bpr 489
                 $TEXT .= "\\link{$ind}{". $l[$level] . " }{$ind}" ;
23 reyssat 490
             }
491
          }
492
          $dejavu .= ' ' . join (' , ', @list) ;
493
          $TEXT .= makeindex ($ref_index, $level + 1, @list) . "</li>" ;
494
      };
495
   }
496
   "$TEXT </ul>";
497
}
498
 
499
sub TraiteText {my ($TEXT, $ref, $ref_env, $Id) = @_;
500
  $TEXT =~ s/\s*$//; # strip trailing whitespace
501
 #0 ul et li sans rien
502
 #1 avec style
11039 bpr 503
 $TEXT =~ s/\\(begin|end)\s*\{wimsonly\}//g;
23 reyssat 504
 for my $rubrique (keys %{$ref_env->{list}}) {
505
     $TEXT = traite_list ($TEXT, $ref, $ref_env, $Id, $rubrique,1);
506
 }
507
 
508
 for my $rubrique (@liste_env_list) {
509
     $TEXT = traite_list ($TEXT, $ref, $ref_env, $Id, $rubrique,0);
510
 }
511
 
734 bpr 512
for my $rubrique (keys %{$ref_env->{tabular}}) {
11039 bpr 513
     if ($TEXT =~ /\\begin\{$rubrique\}/) {
734 bpr 514
       $TEXT = traite_environ ($TEXT, $ref, $ref_env, $Id, $rubrique,0);
515
     }
516
 }
7387 bpr 517
 
734 bpr 518
for my $rubrique (@liste_env_tabular) {
11039 bpr 519
   if ($TEXT =~ /\\begin\{$rubrique\}/) {
734 bpr 520
     $TEXT = traite_environ ($TEXT, $ref, $ref_env, $Id, $rubrique,0);
521
   }
522
}
7387 bpr 523
 
178 bpr 524
 for my $rubrique (@liste_env_spec) {
11039 bpr 525
    if ($TEXT =~ /\\begin\{$rubrique(\*)?\}/) {
178 bpr 526
      $TEXT = traite_environ ($TEXT, $ref, $ref_env, $Id, $rubrique, 1);
527
    }
528
  }
10824 bpr 529
#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 530
 
10234 bpr 531
  for my $rubrique (keys %{$ref_env->{titre}}) {
11039 bpr 532
    if ($TEXT =~ /\\begin\{$rubrique\}/) {
23 reyssat 533
      $TEXT = traite_environ ($TEXT, $ref, $ref_env, $Id, $rubrique,1);
534
    }
535
  }
536
  for my $rubrique (keys %{$ref_env->{list}}) {
537
     $TEXT = traite_environ ($TEXT, $ref, $ref_env, $Id, $rubrique,0);
538
     $TEXT = traite_environ ($TEXT, $ref, $ref_env, $Id, $rubrique . '_item',0);
539
  }
7387 bpr 540
 
23 reyssat 541
  if ($TEXT =~ /\\begin\{\s*(\w*)\s*\}/g) {
6855 bpr 542
     warn " ATTENTION : environnement non répertorié : $1" if $1 ne 'matrix' && $1 ne 'split';
23 reyssat 543
  }
3549 bpr 544
  $TEXT =~ s,<li>\n+</li>,<li></li>,g;
6104 bpr 545
  $TEXT =~ s,</div>\s+</div>,</div></div>,g;
546
  $TEXT =~ s,</div>\s+<,</div>\n<,g;
6360 bpr 547
  $TEXT =~ s,<div ([^>]+)>\s+<,<div $1><,g;
6693 bpr 548
  $TEXT =~ s/\n{2,5}/<br class=\"spacer\" \/>/g;
23 reyssat 549
  $TEXT;
550
}
551
 
10234 bpr 552
#on pourrait faire une boucle while ; on pourrait avoir deux fois le meme environnement imbrique ?
23 reyssat 553
#begin{proof} \begin{proof} \end{proof}\end{proof} Je crois que c'est pour cela que je fais ce truc
10824 bpr 554
#tordu. En fait split me sert uniquement a trouver le premier <$environ>
555
#$cnt sert a numeroter semi-globalement (creation de blocs correspondant a un même environnement dans une meme page
23 reyssat 556
#exemple mainS4S3F_proof1,mainS4S3F_proof2,mainS4S3F_proof3,mainS4S3F_proof4,mainS4S3F_proof5
734 bpr 557
 
23 reyssat 558
sub traite_list {my ($TEXT, $ref, $ref_env, $Id, $environ, $option) = @_;
734 bpr 559
 my ($e_item, $b_item , $b_class, $e_class) = (' ',' ', ' ', ' ');
23 reyssat 560
  if ( $option == 1 ) {
561
         $e_item = "\\end{$environ\_item}" ;
562
         $b_item = "\\begin{$environ\_item}" ;
563
      my $style = $ref_env->{style}{$environ} ;
564
      $style = ($style) ? $style : $environ;
565
      $b_class= "ul class=\"$style\"" ;
7387 bpr 566
      $e_class= "\/ul" ;
23 reyssat 567
      }
568
      {
743 bpr 569
        if    ($environ eq 'enumerate'){ $b_class = "ol class=\"enumerate\"" ; $e_class= "\/ol" ; }
10234 bpr 570
        elsif ($environ eq 'itemize'){ $b_class = "ul class=\"itemize\"" ; $e_class= "\/ul" ;}
23 reyssat 571
        elsif ($environ eq 'description'){
7387 bpr 572
              $b_class = "ul style=\"list-style:none;\"" ;
23 reyssat 573
              $e_class= "\/ul" ;
574
              $e_item = "\\end{$environ\_item}" ;
575
              $b_item = "\\begin{$environ\_item}"
576
              }
10824 bpr 577
        elsif ($environ eq 'trivlist') { $b_class = "ul class=\"wims_nopuce\"" ;
23 reyssat 578
               $e_class= "\/ul" ;
579
        }
7387 bpr 580
      };
11039 bpr 581
  $TEXT =~ s/\\begin\{$environ(\*)?\}/<$environ>/g;
582
  $TEXT =~ s|\\end\{$environ(\*)?\}|<\/$environ>|g;
7387 bpr 583
 
23 reyssat 584
  my @decoup = split ("<$environ>", $TEXT);
585
 
586
  my $a = join ("<$environ>", @decoup[1..$#decoup]);
743 bpr 587
  return $TEXT if (!$a) ;
23 reyssat 588
  my @u = extract_tagged ("<$environ>$a", "<$environ>");
10234 bpr 589
  my $milieu = "<$environ>" . $u[4] . "<\/$environ>" ;
10824 bpr 590
#FIXME pas de listes emboitees de type different !
743 bpr 591
  $milieu =~ s|<$environ>\s*\\item|<$environ><li>$b_item|g ;
592
  $milieu =~ s|</$environ>|</li><$e_class>|g;
593
  $milieu =~ s|\\item|$e_item</li><li>$b_item|g;
594
  $milieu =~ s|</li><$e_class>|$e_item</li><$e_class>|g;
7387 bpr 595
  $milieu =~ s|<$environ>|<$b_class>|g;
23 reyssat 596
  $decoup[0] . $milieu . traite_list ($u[1], $ref, $ref_env, $Id, $environ,$option);
597
}
7387 bpr 598
 
23 reyssat 599
sub traite_environ {my ($TEXT, $ref, $ref_env, $Id, $environ, $cnt) = @_;
11039 bpr 600
  $TEXT =~ s/\\begin\{$environ\*?\}/<$environ>/g;
601
  $TEXT =~ s|\\end\{$environ\*?\}|</$environ>|g;
7387 bpr 602
 
23 reyssat 603
  my @decoup = split ("<$environ>", $TEXT);
604
 
605
  my $a = join ("<$environ>", @decoup[1..$#decoup]);
606
  return $TEXT if (!$a);
7387 bpr 607
 
23 reyssat 608
  my @u = extract_tagged ("<$environ>$a", "<$environ>");
609
  my $milieu = $u[4];
610
  return $TEXT if (!$milieu);
611
 
612
  my $pat_env = join('|', @liste_env_spec);
7387 bpr 613
  my $patt_env = join('|', @liste_env_tabular);
23 reyssat 614
  if ($environ =~ /\b($pat_env)\b/) { $milieu = $1->($milieu) ; }
734 bpr 615
  elsif ($environ =~ /\b($patt_env)\b/) { $milieu = tabular->($milieu,$environ) ; }
616
  else { my @milieu1 = extract_bracketed ($milieu, '{}');
23 reyssat 617
    if ($milieu1[0]) { $milieu = $milieu1[4] ; };
618
    my $type = $ref_env->{type}{$environ};
619
 
620
    if ($type && ($type eq 'fold' || $type eq 'link')) {
621
      my $titre = $ref_env->{titre}{$environ};
622
      my $newtag = $Id . $prefixe{$type} . $environ . $cnt;
623
      $ref->{type}{$newtag} = 'fold' if $type eq 'fold' ;
624
      $cnt++;
10824 bpr 625
      # LaTeX interdit des [ ] imbriques.
23 reyssat 626
      if ($milieu =~ s/^\s*\[([^\]]+)\]//) {
10234 bpr 627
        $titre = ($titre) ? "$titre [ $1 ]" : $1 ;
23 reyssat 628
      }
629
      $ref->{titb}{$newtag} = $titre;
630
      $ref->{text}{$newtag} = encadrement("<$environ>$milieu<\/$environ>", $environ, $ref_env);
631
      $ref->{upbl}{$newtag} = $Id;
632
      $milieu = "\n\\$type\{$newtag\}\{"
633
        . encadr_defaut("<$environ>$titre<\/$environ>", $environ, $ref_env,'titre')
6167 bpr 634
        . "\}\n" ;
10234 bpr 635
    } else { my $milieu1 = $milieu ;
734 bpr 636
      $milieu = encadrement("<$environ>$milieu<\/$environ>", $environ, $ref_env, 'full');
23 reyssat 637
    }
638
  }
639
  $decoup[0] . $milieu . traite_environ ($u[1], $ref, $ref_env, $Id, $environ, $cnt);
640
}
641
 
642
sub hd {my ($tag, $ref) = @_;
643
  my $txt = '';
10234 bpr 644
  for my $cle ('prev','next','upbl','titb','keyw','datm') {
23 reyssat 645
    my $KEY = $ref->{$cle}{$tag};
646
    $txt .= "!set $cle=$KEY\n" if ($KEY);
647
  }
648
  $txt;
649
}
650
#rajoute un next aux section/subsection/ si cela n'existe pas [dernier] dernier sur index si il y a
7387 bpr 651
#rajoute main pour ceux qui n'ont pas de parents.
23 reyssat 652
sub complete {my ($tag, $ref) = @_;
10234 bpr 653
  $ref->{datm}{$tag} = isotime() if !($ref->{datm}{$tag}) ;
654
  $ref->{upbl}{$tag} = 'main' if !($ref->{upbl}{$tag}) ;
23 reyssat 655
  my $upbl = $ref->{upbl}{$tag};
656
  if (!$ref->{next}{$tag}) {
657
    my $a = $ref->{next}{$upbl};
658
    $ref->{next}{$tag} = $a || 'main';
659
  };
660
  if (!$ref->{prev}{$tag}) {
661
    my $b = $ref->{prev}{$upbl};
662
    $ref->{prev}{$tag} = $b || 'main';
663
  };
664
  if ($INDEX == 1 && !($ref->{titb}{index})) { $ref->{titb}{index} = 'Index' ;}
665
}
666
 
10824 bpr 667
#option full <h3 class="l2w_content defn">Definition [titre perso]</h3> <div class= "l2w_content definition">  </div> si cela existe
668
#option bloc <div class= "definition"> </div> si cela existe (interieur d'un fold ou d'un link)
669
#option titre <h3 class="l2w_content defn">Definition </h3> si cela existe (titre d'un fold)
23 reyssat 670
sub encadr_defaut { my ($TEXT, $rubrique, $ref_env, $option) = @_;
671
  my $a = $ref_env->{titre}{$rubrique};
672
  my $b = $ref_env->{style}{$rubrique};
673
  if (!$b) {
674
    $b = $rubrique;
675
    $ref_env->{style}{$rubrique} = $b;
676
    dbg("... environnement $rubrique sans style css, par defaut $rubrique")
677
  };
6472 bpr 678
  my $div_d = "<div class=\"l2w_content $b\">";
23 reyssat 679
  my $div_f = '</div>';
7387 bpr 680
  if ( $option eq 'titre') {
6472 bpr 681
    $TEXT =~ s/<$rubrique>/<span class=\"l2w_content $b\">/g;
6104 bpr 682
    $TEXT =~ s/<\/$rubrique>/<\/span>\n/g;
23 reyssat 683
  } elsif (!$a || $option eq 'bloc') {
684
    $TEXT =~ s/<$rubrique>\s*(\[[^\]]+\])?/$div_d/g;
6167 bpr 685
    $TEXT =~ s/<\/$rubrique>/$div_f/g;
23 reyssat 686
  } elsif ($option eq 'full') {
10316 bpr 687
    $TEXT =~ s/<$rubrique>\s*(\[[^\]]+\])/<h3 class=\"l2w_content $b\">$a $1<\/h3>$div_d/g;
688
    $TEXT =~ s/<$rubrique>/<h3 class=\"l2w_content $b\">$a<\/h3>$div_d/g;
6167 bpr 689
    $TEXT =~ s/<\/$rubrique>/$div_f/g;
10234 bpr 690
  } else {
23 reyssat 691
    $TEXT =~ s/<$rubrique>/<span class=\"$b\">/g;
6104 bpr 692
    $TEXT =~ s/<\/$rubrique>/<\/span>\n/g;
23 reyssat 693
  }
694
  $TEXT;
695
}
10234 bpr 696
sub encadrement { my ($TEXT, $rubrique, $ref_env) = @_;
23 reyssat 697
  my $debut = $ref_env->{deb}{$rubrique};
698
  my $fin   = $ref_env->{fin}{$rubrique};
7387 bpr 699
  my $opt= ($ref_env->{type}{$rubrique} && $ref_env->{type}{$rubrique}=~ /fold/) ? 'bloc' : 'full' ;
743 bpr 700
  return encadr_defaut ($TEXT, $rubrique, $ref_env, $opt) if (!$debut && !$fin);
23 reyssat 701
 
702
  $TEXT =~ s/<$rubrique>//;
703
  my $cnt_arg = $ref_env->{cnt_arg}{$rubrique};
704
  my $d = join('   ', subst($TEXT, $cnt_arg, $debut, $rubrique, $ref_env));
705
  my ($com,$txt) = subst($TEXT, $cnt_arg, $fin);
706
  $d =~ s/<\/$rubrique>/$com/;
707
  $d;
708
}
709
 
7387 bpr 710
sub tabular { my ( $b, $style ) = @_;
711
  my @v = extract_bracketed ($b, '{}') ;
734 bpr 712
  my $stylerow = $style . "_row";
713
  my $stylecell = $style . "_cell";
10234 bpr 714
  $b = "<table class=\"$style\"><tr class=\"$stylerow\"><td class=\"$stylecell\">" . $v[1] . '</table>';
3334 bpr 715
  $b =~ s|\&|&nbsp;</td><td class=\"$stylecell\">&nbsp;|g;
23 reyssat 716
  $b =~ s/\\hline//g;
717
  $b =~ s|\\\\\s*</table>|</td></tr></table>|g;
743 bpr 718
  my $par="\\\\\\(|\\\\\\)" ;
7387 bpr 719
  my @dectab = split(/$par/, $b) ;
720
  $b = $dectab[0] ;
3334 bpr 721
  $b =~ s|\\\\|</td></tr><tr class=\"$stylerow\"><td class=\"$stylecell\">|g;
7387 bpr 722
  my $cnt = 0; $b = '' ;
723
  while ($cnt <= $#dectab/2) {
724
     my $c = $dectab[2*$cnt] ;
3334 bpr 725
     $c =~ s|\\\\|</td></tr><tr class=\"stylerow\"><td class=\"$stylecell\">|g;
10234 bpr 726
     $b .= $c . (($dectab[2*$cnt+1]) ? "\\(" . $dectab[2*$cnt+1] . "\\)" : '' );
7387 bpr 727
     $cnt ++ ;
743 bpr 728
 };
7387 bpr 729
 $b ;
23 reyssat 730
}
731
 
10824 bpr 732
###demande de convertir d'abord de maniere independante les pdf tiff eps svg en un format d'image png
4852 bpr 733
sub includegraphics{ my ( $b, $opt ) = @_;
7387 bpr 734
   $b=~ s/.(pdf|tiff|eps|svg)/.png/ ;
4858 bpr 735
   $opt =~ s/.*(width|height)\s*=\s*([0-9]*\.?[0-9]*\s*)(\\(line|text)width)/linewidth("$2$3",$1)/eg;
5663 bpr 736
   $opt =~ s/.*(width|height)\s*=\s*([0-9]*\.?[0-9]*\s*)(cm|px)/ style=\"$1:$2$3;\"/;
6358 bpr 737
  "<img src=\"\\filedir\/$b\" $opt alt=\"\" />";
4852 bpr 738
}
7387 bpr 739
 
740
sub minipage { my ( $b ) = @_;
4865 bpr 741
 my @v = extract_bracketed ($b, '[]') ;
7387 bpr 742
 my $option = $v[0] ;
6858 bpr 743
 if($option) {
7387 bpr 744
 $option=~ s/\[\s*b\s*\]/bottom/ ;
4866 bpr 745
 $option=~ s/\[\s*t\s*\]/top/ ;
7387 bpr 746
 $option=~ s/\[\s*c\s*\]/middle/ ;
747
 $option=~ s/\[\s*\]/middle/;
6858 bpr 748
 } else {
749
 $option='middle'} ;
4865 bpr 750
 @v = extract_bracketed ($v[1], '{}') ;
4850 bpr 751
 my $width = $v[0] ;
752
 $width =~ s/\{(.*)\}/$1/;
6858 bpr 753
 $width = linewidth($width);
4865 bpr 754
  "<div style=\"width:$width; display:inline-block;vertical-align:$option;\" class=\"minipage\">
7387 bpr 755
   $v[1]
4850 bpr 756
   </div>";
757
}
7387 bpr 758
sub columns { my ( $b ) = @_;
5289 bpr 759
  "<div class=\"columns\">$b</div>"
5286 bpr 760
}
761
 
7387 bpr 762
sub column { my ( $b ) = @_;
5286 bpr 763
 my @v = extract_bracketed ($b, '[]') ;
6104 bpr 764
 my $option = '';
7387 bpr 765
 $option= $v[0] ;
6104 bpr 766
 if($option) {
7387 bpr 767
  $option=~ s/\[\s*b\s*\]/bottom/ ;
6104 bpr 768
  $option=~ s/\[\s*t\s*\]/top/ ;
7387 bpr 769
  $option=~ s/\[\s*c\s*\]/middle/ ;
770
  $option=~s/\[\s*\]/middle/;
6104 bpr 771
  }
772
 else{ $option='top'} ;
5286 bpr 773
 @v = extract_bracketed ($v[1], '{}') ;
774
 my $width = $v[0] ;
775
 $width =~ s/\{(.*)\}/$1/;
776
 $width = linewidth($width) ;
777
  "<div style=\"width:$width; display:inline-block;vertical-align:$option;\" class=\"column\">
7387 bpr 778
   $v[1]
5286 bpr 779
   </div>";
780
}
781
 
4851 bpr 782
sub lstlisting { my ($b,$id ) = @_ ;
783
  $b =~ s ,\\,\\\\,g ;
784
  "<pre class=\"lstlisting\" id=\"lstlisting$id\">$b</pre>";
785
}
743 bpr 786
 
4858 bpr 787
sub verbatim { my ($b,$id ) = @_ ;
788
  $b =~ s ,\\,\\\\,g ;
789
  "<pre class=\"verbatim\" id=\"verbatim$id\">$b</pre>";
790
}
791
 
23 reyssat 792
sub multline { my ( $b) = @_;
5762 bpr 793
  $b =~ s/\\\\\s*=/\\)<br\/>\\(== /g;
794
  $b =~ s|\\\\|\\)<br\/>\\(|g;
23 reyssat 795
  "<div class=\"math\">\\(" . $b . "\\)</div>\n";
796
}
797
 
798
sub equation { my ( $b) = @_;
10234 bpr 799
  $b = "\\( $b \\)";
11039 bpr 800
  if ($b =~ s/\\label\{([^\}]+)\}//) { $b = "\\label\{$1\}" . $b };
7387 bpr 801
  $b =~ s/\n{2,}/\n/;
23 reyssat 802
  '<div class="math">' . $b . '</div>' ;
803
}
804
 
805
sub align1 { my ( $b) = @_;
11039 bpr 806
  $b = "\\(\\begin\{matrix\} $b \\end\{matrix\} \\)";
807
  if ($b =~ s/\\label\{([^\}])\}//) { $b = "\\label\{$1\}" . $b };
23 reyssat 808
  '<div class="math">' . $b . '</div>' ;
809
}
810
sub align { my ( $b) = @_;
10234 bpr 811
  $b = '<table class="wimscenter wimsnoborder tableau" style="width:100%"><tr><td>\\(' . $b . '\\\\</table>';
11039 bpr 812
  if ($b =~ s/\\label\{([^\}])\}//) { $b = "\\label\{$1\}" . $b };
23 reyssat 813
  $b =~ s|\&|\\)&nbsp;</td><td>&nbsp;\\(|g;
814
  $b =~ s|\\\\\s*</table>|\\)</td></tr></table>|g;
815
  $b =~ s|\\\\|\\)</td></tr><tr><td>\\(|g;
5291 bpr 816
  $b =~ s|\\\(\s+\\\)||g;
817
  $b =~ s|\n\\\)|\\\)|g;
818
  $b =~ s|\\\(\n|\\\(|g;
23 reyssat 819
  '<div class="math">' . $b . '</div>' ;
820
}
821
 
822
sub pmatrix {"\\left ( \\begin{matrix} " . $_[0] . "\\end{matrix} \\right )" ;}
823
sub smallmatrix {"\\left ( \\begin{matrix} " . $_[0] . "\\end{matrix} \\right )" ;}
824
sub eqnarray {" <div class=\"math\">\\(\\begin{matrix} " . $_[0] . "\\end{matrix})</div> " ;}
825
sub center {" <div class=\"center\">" . $_[0] . "</div>"}
826
 
827
sub array {my ( $b ) = @_ ;
828
  my @v = extract_bracketed ($b, '{}');
829
  "\\begin{matrix} " . $v[1] . "\\end{matrix} ";
830
}
831
#TODO pour l'instant
5292 bpr 832
sub cases {"\\left \\lbrace\\begin{matrix} " . $_[0] . "\\end{matrix} \\right ." ; }
23 reyssat 833
 
834
sub gather { my ($b) = @_;
835
  my @decoup = split ('\\\\intertext', $b);
836
  my $cnt = 1;
837
  $b = equation($decoup[0]);
838
  while ($cnt <= $#decoup) {
839
    my @a = extract_bracketed ( $decoup[$cnt], '{}' );
840
    my $c = $a[0];
841
    $c =~ s/\{(.*)\}/$1/;
842
    $b .= $c . equation($a[1]);
843
    $cnt ++;
844
  }
845
  $b;
846
}
847
 
11039 bpr 848
sub displaymath {"<div class=\"math\">\\(\\displaystyle\{ " . $_[0]. "\}\\)</div>"; }
23 reyssat 849
sub math {" \\( " . $_[0]. "\\) "; }
850
 
7395 bpr 851
sub figure { my $caption=''; my $c =$_[0];
852
  $c =~ s /^\[([^\]]+)//; print $c;
11039 bpr 853
  if ( $c =~ s/\\caption\{([^\}]+)\}//) {$caption=$1 };
7387 bpr 854
  "<div class=\"figure\"> " .
855
  (($caption) ? "<div class=\"caption\">". $caption . "</div>":"")
7395 bpr 856
    . $c . "</div>" ;}
23 reyssat 857
 
858
sub thebibliography { my ( $b ) = @_;
11039 bpr 859
  $b =~ s/\\bibitem\{([^\}]+)\}/<\/li>\n<li>\[$1\]\\label\{$1\} /g;
23 reyssat 860
  $b =~ s/\{\d+\}\s*<\/li>//;
7387 bpr 861
  '<h2 class="thebibliography">' . $hash{titb}{ref}
23 reyssat 862
  . "</h2>\n<ul class=\"thebibliography\">$b </li></ul>\n";
863
}
864
sub pspicture { '<p>dessin à faire dans wims</p>' ; }
865
sub picture { '<p>dessin à faire dans wims</p>' ; }
866
 
10824 bpr 867
#decoupe ce qui se trouve a l'interieur de \begin{wims} \end{wims} pour ne pas y toucher.
4851 bpr 868
# même pour verbatim, lstlisting
23 reyssat 869
sub traite_special { my ( $TEXT, $ref_spec, $ref, $environ ) = @_;
870
  $TEXT = recup_embed($TEXT, $ref) ;
11039 bpr 871
  $TEXT =~ s/\\begin\{$environ\}/<$environ>/g;
872
  $TEXT =~ s/\\end\{$environ\}/<\/$environ>/g;
23 reyssat 873
  $TEXT =~ s/\r\n/\n/gs ;
874
  my @decoup = split ("<$environ>", $TEXT);
875
  my $cnt = 1;
876
  if ($#decoup) {
877
    $TEXT = $decoup[0];
878
    while ($cnt <= $#decoup) {
879
      my @a = extract_tagged("<$environ>" . $decoup[$cnt], "<$environ>");
880
      die "Bug dans $environ insertion: $decoup[$cnt]" if (!defined($a[4]));
881
      $TEXT .= $environ . 'insertion' . $cnt . $a[1];
882
      $ref_spec->{$cnt} = $a[4];
883
      $cnt++;
884
    }
885
  }
886
  $TEXT;
887
}
888
 
889
sub latexonly { '' }
890
 
891
sub store_cmd { my ($def, $id, $narg, $val, $ref_command) = @_;
892
  if ($hash_secinv{$id}) {
893
    warn " ATTENTION : commande perso \"$id: argument invalide\n";
894
    return '';
895
  }
896
  my $origin = $ref_command->{origin}{$id};
897
  return '' if ($origin && $origin eq 'defwims' && $def ne 'defwims');
898
  $ref_command->{origin}{$id} = $def;
899
  $ref_command->{cnt_arg}{$id} = $narg;
900
  $ref_command->{definition}{$id} = $val;
901
  dbg("... commande perso \"$id\": argument: \"$narg\" definition: \"$val\"");
902
 '' ;
903
}
7387 bpr 904
 
23 reyssat 905
sub store_environ { my ($def, $cmd, $narg, $titre, $deb, $fin, $ref_env) = @_;
906
  my $origin = $ref_env->{origin}{$cmd};
907
  return '' if ($origin && $origin eq 'environmentwims' && $def ne 'environmentwims');
908
  $ref_env->{deb}{$cmd} = $deb;
909
  $ref_env->{fin}{$cmd} = $fin;
910
  $ref_env->{cnt_arg}{$cmd} = $narg;
7228 bpr 911
## one can have macro in definition of an environment - not general but useful for language
912
  if ($titre=~/\\(\w+)/) {
913
    $titre=$hash_command{definition}{$1} if $hash_command{definition}{$1}
914
  }
23 reyssat 915
  $ref_env->{titre}{$cmd} = $titre;
916
  $ref_env->{origin}{$cmd} = $def;
917
  my $style = $ref_env->{style}{$cmd} ;
7387 bpr 918
  $style = ($style)? $style : $cmd ;
734 bpr 919
  #if (!$ref_env->{deb}{$cmd}) { $ref_env->{deb}{$cmd} = "<div class=\"$style\"> "; }
920
  #if (!$ref_env->{fin}{$cmd}) { $ref_env->{fin}{$cmd} = "</div> "; }
23 reyssat 921
  dbg("... environnement perso \"$cmd\" argument: \"$narg\" titre: \"$titre\" style: \"$style\" debut: \"$deb\"  fin: \"$fin\"");
922
  '';
923
}
924
 
925
sub recup_command {my ($TEXT, $ref_command) = @_;
926
  my $DEF = '(defwims|def|newcommand|renewcommand)';
7387 bpr 927
  #FIXME ? mauvais pour def \def\toto#1#2 ... demander de le refaire avec defwims s'il y a plus de 3 arguments ?
23 reyssat 928
  $TEXT =~ s/\\$DEF\s*\\(\w*)#(\d)\{(.*)\}/store_cmd($1,$2,$3,$4,$ref_command)/eg;
929
  #2 arguments
930
  $TEXT =~ s/\\$DEF\s*\\(\w*)#(\d)#(\d)\{(.*)\}/store_cmd($1,$2,$4,$5,$ref_command)/eg;
931
  $TEXT =~ s/\\$DEF\s*\\(\w*)\s*\{(.*)\}/store_cmd($1,$2,0,$3,$ref_command)/eg;
932
  #3 arguments
933
  $TEXT =~ s/\\$DEF\s*\\(\w*)#(\d)#(\d)#(\d)\{(.*)\}/store_cmd($1,$2,$5,$6,$ref_command)/eg;
10824 bpr 934
  # newcommand avec parametres
23 reyssat 935
  $TEXT =~ s/\\$DEF\s*\{\\(\w*)\}\s*\[(\d)\]\s*\{(.*)\}/store_cmd($1,$2,$3,$4,$ref_command)/eg;
10824 bpr 936
  # newcommand sans parametres
23 reyssat 937
  $TEXT =~ s/\\$DEF\s*\{\\(\w*)\}\s*\{(.*)\}/store_cmd($1,$2,0,$3,$ref_command)/eg;
938
  $TEXT;
939
}
940
 
941
sub recup_config { my ($cmd, $arg, $ref_env) = @_;
942
  my @L = (split (',', $arg));
943
  my $style = $L[0];
944
  my $type = 'style';
10234 bpr 945
  if ($cmd eq 'typefold') { $style = 'fold'; $type = 'type' };
23 reyssat 946
  if ($cmd eq 'typelink') { $style = 'link' ; $type = 'type' };
734 bpr 947
  if ($cmd eq 'tablewims') { $type = 'tabular' ; };
10234 bpr 948
  if ($cmd eq 'listwims') { $type = 'list' };
23 reyssat 949
  for my $rubrique (@L) {
950
    $ref_env->{$type}{$rubrique} = $style;
951
    dbg("... commande $rubrique de $type $style");
7387 bpr 952
    if ($cmd eq 'listwims') { $ref_env->{'style'}{$rubrique . '_item'} = $style . '_item' ;
23 reyssat 953
                              $ref_env->{'titre'}{$rubrique . '_item'} = '' }
954
  }
7387 bpr 955
  push @liste_env_tabular, (keys %{$ref_env->{tabular}}) ;
23 reyssat 956
 '';
957
}
958
sub recup_environ {my ($TEXT, $ref_env) = @_;
959
  my $pat = '\s*\{(.*)\}';
734 bpr 960
  $TEXT =~ s/\\(typefold|typelink|samestyle|listwims|tablewims)\{([^\}]+)\}/recup_config($1,$2, $ref_env)/eg;
23 reyssat 961
  # {nom}[#param]{titre}{debut}{fin}
962
  $TEXT =~ s/\\(environmentwims|[re]?newenvironment)\s*\{(\w*)\}\[(\d)\]$pat$pat$pat/store_environ($1,$2,$3,$4,$5,$6,$ref_env)/eg;
963
  # {nom}{titre}{debut}{fin}
964
  $TEXT =~ s/\\(environmentwims|[re]?newenvironment)\s*\{(\w*)\}$pat$pat/store_environ($1,$2,0,'', $3,$4,$ref_env)/eg;
965
 #\newtheorem{nom}[]?{titre}[]?
966
  $TEXT =~ s /(\\newtheorem\*?)\s*\{(\w*)\}\s*(\[[^\]]*\])?\s*\{([^\}]*)\}\s*(\[[^\]]*\])?\s*/store_environ($1,$2,0,$4,'','',$ref_env)/ge;
967
  $TEXT;
968
}
969
 
970
#on suppose que le texte commence par \command{}{}{}{} avec le bon nombre d'arguments
971
 
972
sub traite_command {my ($TEXT, $command, $ref_command) = @_;
973
  my $cnt_arg = $ref_command->{cnt_arg}{$command};
974
  my $com = $ref_command->{definition}{$command};
975
  if ($cnt_arg) {
976
    $TEXT =~ s/\\$command\s*\{/\{/;
10234 bpr 977
    $TEXT = join ( "", subst($TEXT, $cnt_arg, $com));
23 reyssat 978
  } else {
979
    $TEXT =~ s/\\$command\_/$com . '_'/ge;
980
    $TEXT =~ s/\\$command\b/$com/ge;
981
  }
982
  $TEXT;
983
}
984
#Texte = {}{}{} ou []{}{} qui sont les arguments
985
sub subst { my ($TEXT, $cnt_arg, $com, $environ, $ref_env ) = @_;
986
  my (@a,$u,$v);
987
  my $cnt = 0;
988
  while ($cnt < $cnt_arg) {
989
    @a = extract_tagged($TEXT, '{','}');
990
    ($u,$v) = ($a[1],$a[4]);
991
    if (!$a[0]) {
734 bpr 992
      @a = extract_tagged($TEXT, '\[','\]');
993
      ($u,$v) = ($a[1],$a[4]);
23 reyssat 994
    }
995
    $TEXT = $u;
996
    $cnt ++;
7387 bpr 997
     my $sub="" ;
920 bpr 998
    if ($v) {
999
       $sub = $environ && $ref_env->{titre}{$environ} ? join (' ' , ( $ref_env->{titre}{$environ}, $v)) : $v;}
7387 bpr 1000
    else {$sub=''} ;
10234 bpr 1001
     if (($com) && ("#$cnt")) { $com =~ s/#$cnt/$sub/ge ;};
23 reyssat 1002
  }
1003
  ($com, $TEXT);
1004
}
1005
 
1006
sub Traite_command { my ($TEXT, $command, $ref_command) = @_;
1007
  my $cnt_arg = $ref_command->{cnt_arg}{$command};
1008
  if ($cnt_arg) {
11039 bpr 1009
    my @decoup = split ("\\\\$command\\\{", $TEXT );
23 reyssat 1010
    my $cnt = 1;
1011
    $TEXT = $decoup[0];
1012
    while ($cnt <= $#decoup) {
1013
      $TEXT .= traite_command ('{' . $decoup[$cnt], $command, $ref_command);
1014
      $cnt++;
1015
    }
1016
  } else {
1017
    while( $TEXT =~ /\\$command\b/) {
1018
      $TEXT = traite_command ($TEXT, $command, $ref_command);
1019
    }
1020
  }
1021
  $TEXT;
1022
}
1023
 
1024
my %outagain;
1025
sub out { my ($bloc, $text) = @_;
1026
  warn "Écrase $bloc" if ($outagain{$bloc});
1027
  $outagain{$bloc} = 1;
10234 bpr 1028
  open (OUT, ">$BASE/$bloc") || die "ne peut pas créer $BASE/$bloc";
23 reyssat 1029
  print OUT $text ; close OUT;
1030
}
1031
 
1032
sub out1 { my ($bloc, $text) = @_;
1033
  warn "Écrase $bloc" if ($outagain{$bloc});
178 bpr 1034
  $outagain{$bloc} = 1;
10234 bpr 1035
  open (OUT, ">$doc_DIR$bloc") || die "ne peut pas créer $doc_DIR/$bloc";
23 reyssat 1036
  print OUT $text ; close OUT;
1037
}
1038
 
1039
sub out_def { my ($bloc, $text) = @_;
10234 bpr 1040
  open (OUT, ">$BASE0/$bloc") || die "peut pas créer $BASE0/$bloc";
23 reyssat 1041
  print OUT $text ; close OUT;
1042
}
1043
 
10824 bpr 1044
# PASSE 1: developpe 'input/include'
7387 bpr 1045
sub find_expand { my ($file) = @_;
23 reyssat 1046
  if (!open(IN, $DIR . $file)) { warn "$DIR$file n'existe pas"; return; }
1047
  dbg("... lecture de $file");
1048
  my $text = <IN>; close(IN);
11039 bpr 1049
  $text =~ s/([^%]\s*\\end\{document\})[[:print:][:space:]]+/$1/;
743 bpr 1050
  $text =~ s/([^%])\s*\\endinput[[:print:][:space:]]+/$1/;
1051
  $text =~ s/\%\\(input|include|wimsinclude)([^\n]+)?//g;
11039 bpr 1052
  $text =~ s/\\(input|include|wimsinclude)\s*\{?([a-zA-Z0-9\-_\/]+)\.(sty|tex)\s*\}?/find_expand("$2.$3")/eg;
4851 bpr 1053
  $text =~ s/\\lstinputlisting\s*\{([a-zA-Z0-9\-_\/\.]+)\s*\}/"\\begin\{lstlisting\}\n" . find_expand($1) . "\n\\end\{lstlisting\}"/eg;
7387 bpr 1054
 
23 reyssat 1055
  $text;
1056
}
1057
 
1058
sub open_close { my ($sec, $cnt, $entre) = @_;
1059
  my ($txt) = '';
1060
  my ($ind) = $hash_secinv{$sec};
1061
  #ferme
1062
  for (my $i = $#SECTIONS; $i >= $ind; $i--)
1063
  {
1064
    if ($cnt->[$i]) { $txt .= "</$SECTIONS[$i]>\n"; $cnt->[$i] = 0; }
1065
  }
1066
  #ouvre
1067
  if (!$entre) {
1068
    $txt .= "<$sec>"; $cnt->[$ind] = 1;
1069
    $SEC_MIN_GLOBAL = $ind if ($ind < $SEC_MIN_GLOBAL && $ind);
1070
  }
1071
  $txt;
1072
}
1073
 
7387 bpr 1074
sub cnt_section { my ($sec, $cnt) = @_ ;
23 reyssat 1075
  my ($txt) = '';
1076
  my ($ind) = $hash_secinv{$sec};
1077
  $SEC_MIN_GLOBAL = $ind if ($ind < $SEC_MIN_GLOBAL && $ind);
1078
  "<$sec>"
1079
 }
1080
 
1081
sub store { my ($ref, $cle, $id, $text, $court) = @_ ;
1082
   $ref->{$cle}{$id}=$text ;
1083
   if (defined($court)) { $court =~ s/\[|\]//g ; $ref->{tittoc}{$id} = $court ; } ;
1084
   '';
1085
 }
1086
sub store_option { my ($A) = @_ ; $A = join(' ' , split(',', $A)) ;
10234 bpr 1087
    if ($A =~ s/numero//) { $NUMERO = 1 ;} ;
1088
    if ($A =~ s/index//) { $INDEX = 1 ;}
734 bpr 1089
    if ($A =~ s/tooltip//) { $TOOLTIP = 1 ;}
23 reyssat 1090
    if ($A =~ s/depth\s*=\s*([0-8])//) { $depth = $1 ; }
1091
    $OPTION .= $A ;
1092
   '' ;
1093
 }
1094
 
1095
sub store_include { my ($A) = @_ ; $A = join(' ' , split(',', $A)) ;
7387 bpr 1096
    if ($A =~ s/(\w*)\.(tex|sty)//) {
1097
         if ($MACRO) {$MACRO .= ",$1.$2" } else {$MACRO = "$1.$2" }
23 reyssat 1098
    };
1099
    if ($A =~ s/(\w*\.css)\b//) { if ($STYLE) {$STYLE .= ",$1" } else {$STYLE = $1 } };
11039 bpr 1100
    if ($A =~ s/embed\s*=\s*([^\}]+)//) { $EMBED = $1 ; }
23 reyssat 1101
   '' ;
1102
 }
1103
 
1104
sub add { my ($a,$b)=@_ ;
7387 bpr 1105
    if ($a) {$a .= ",$b" } else {$a = $b }
23 reyssat 1106
 }
1107
 
1108
sub Init { my ($file, $ref_env, $ref_command, $ref, $ref_algo) = @_;
1109
  my ($total, $TEXT) = (0, find_expand($file));
4851 bpr 1110
  my %hash_spec = (wims =>{}, verbatim =>{}, lstlisting => {});
23 reyssat 1111
  my $ref_spec = \%hash_spec;
1112
  $TEXT = traite_special ($TEXT, $ref_spec->{wims}, $ref,'wims');
1113
  $TEXT = traite_special ($TEXT, $ref_spec->{verbatim}, $ref,'verbatim');
4851 bpr 1114
  $TEXT = traite_special ($TEXT, $ref_spec->{lstlisting}, $ref,'lstlisting');
23 reyssat 1115
  $TEXT = traitement_initial ($TEXT);
1116
  $TEXT =~ s/\\wimsoption\s*\{([^\}]+)\}/store_option($1)/eg ;
1117
  $TEXT =~ s/\\makeindex/store_option('index')/eg ;
1118
  $TEXT =~ s/\\wimsinclude\s*\{([^\}]+)\}/store_include($1)/eg ;
1119
  $TEXT =~ s/\\(title|email|author|about)\s*(\[[^\]]+\])?\s*\{([^\}]+)\}/store($ref,$1,'main',$3,$2)/eg ;
7387 bpr 1120
 
23 reyssat 1121
  $TEXT = traite_preambule ($TEXT, $ref_env, $ref_command, $ref);
1122
  for my $command (keys %{$ref_command->{definition}}) {
1123
    $TEXT = Traite_command ($TEXT, $command, $ref_command);
1124
  }
1125
  for my $A (@liste_voca) {
10234 bpr 1126
   $ref_algo->{titre}{$A} = $ref_command->{definition}{"algorithmic\L$A\E"} if ($ref_command->{definition}{"algorithmic\L$A\E"}) ;
23 reyssat 1127
} ;
4851 bpr 1128
  $TEXT =~ s/wimsinsertion(\d*)/$ref_spec->{'wims'}{$1}/g;
4858 bpr 1129
  $TEXT =~ s/verbatiminsertion(\d*)/verbatim($ref_spec->{'verbatim'}{$1},$1)/eg;
4851 bpr 1130
  $TEXT =~ s/lstlistinginsertion(\d*)/lstlisting($ref_spec->{'lstlisting'}{$1},$1)/eg;
23 reyssat 1131
  $TEXT;
1132
}
1133
 
1134
#sub store_makeindex { my ($txt) = @_ ;
1135
#    $txt =~ s/\\printindex/\link{index}{Index}/ ;
1136
#   }
1137
sub traitement_final { my ($TEXT) = @_;
10824 bpr 1138
 #FIXME : je ne peux pas faire ca a cause des exercices de developpement dont l'adresse
23 reyssat 1139
 #contienne un ~. De toute facon
1140
 #ca ne devrait pas exister, mais quand même. ou les wims only
1141
#   $TEXT =~ s/~/&nbsp;/g;
6858 bpr 1142
   $TEXT =~ s:(<br class="spacer" />\s*<br class="spacer" />):<br class="spacer" />:g;
1143
   $TEXT =~ s:<br class="spacer" />\s*(</?div):$1:g;
1144
   $TEXT =~ s:(class="minipage">)\s*<br class="spacer" />:$1:g;
23 reyssat 1145
   $TEXT;
1146
}
1147
 
1148
sub traitemath {my ($txt) = @_;
1149
  my $test = 0;
1150
  while ($txt =~ /\$\$/) {
6169 bpr 1151
    $txt = $` . ($test == 0 ? '<div class="math">\\(\\displaystyle{' : '}\\)</div>') . $';
23 reyssat 1152
    $test = 1-$test;
1153
  }
1154
  $txt;
1155
}
1156
 
1157
sub traitement_initial { my ($TEXT) = @_;
1158
  $TEXT =~ s/\s*$//; # strip trailing whitespace
7387 bpr 1159
  $TEXT =~ s/\r\n/\n/gs ;
23 reyssat 1160
  $TEXT = traitemath($TEXT);
1161
  $TEXT =~ s/{\s*\\(bf|tt|it)\b/\\text$1\{/g;
1162
  $TEXT =~ s/\\begin\b\s*/\\begin/g;
1163
  $TEXT =~ s/\\end\b\s*/\\end/g;
1164
  #$TEXT =~ s/\\text\b/\\hbox/g;
1165
  $TEXT =~ s,\\\[,<p class="math">\\(,g;
1166
  $TEXT =~ s,\\\],\\)</p>,g;
1167
  $TEXT =~ s/\$([^\$]+)\$/\\( $1 \\)/g;
1168
 
11039 bpr 1169
  $TEXT =~ s/\\`\s*\{a\}/à/g;
1170
  $TEXT =~ s/\\\^\s*\{a\}/â/g;
1171
  $TEXT =~ s/\\'\s*\{a\}/á/g;
1172
  $TEXT =~ s/\\'\s*\{e\}/é/g;
1173
  $TEXT =~ s/\\`\s*\{e\}/è/g;
1174
  $TEXT =~ s/\\\^\s*\{e\}/ê/g;
1175
  $TEXT =~ s/\\\^\s*\{i\}/î/g;
1176
  $TEXT =~ s/\\\`\s*\{i\}/ì/g;
1177
  $TEXT =~ s/\\\"\s*\{i\}/ï/g;
1178
  $TEXT =~ s/\\\"\s*\{\\i\}/ï/g;
1179
  $TEXT =~ s/\\\^\s*\{o\}/ô/g;
1180
  $TEXT =~ s/\\\"\s*\{o\}/ö/g;
1181
  $TEXT =~ s/\\\`\s*\{o\}/ò/g;
1182
  $TEXT =~ s/\\\^\s*\{u\}/û/g;
1183
  $TEXT =~ s/\\`\s*\{u\}/ù/g;
23 reyssat 1184
  $TEXT =~ s/\\c\s*\{c\}/ç/g;
1185
 
1186
  $TEXT =~ s/\\`\s*a/à/g;
1187
  $TEXT =~ s/\\\^\s*a/â/g;
1188
  $TEXT =~ s/\\'\s*a/á/g;
1189
  $TEXT =~ s/\\'\s*e/é/g;
1190
  $TEXT =~ s/\\`\s*e/è/g;
1191
  $TEXT =~ s/\\\^\s*e/ê/g;
3846 bpr 1192
  $TEXT =~ s/\\`\s*E/È/g;
1193
  $TEXT =~ s/\\\'\s*E/É/g;
1194
  $TEXT =~ s/\\\^\s*E/Ê/g;
23 reyssat 1195
  $TEXT =~ s/\\\^\s*i/î/g;
1196
  $TEXT =~ s/\\\`\s*i/ì/g;
1197
  $TEXT =~ s/\\\"\s*i/ï/g;
1198
  $TEXT =~ s/\\\^\s*o/ô/g;
1199
  $TEXT =~ s/\\\"\s*o/ö/g;
1200
  $TEXT =~ s/\\\`\s*o/ò/g;
1201
  $TEXT =~ s/\\\^\s*u/û/g;
1202
  $TEXT =~ s/\\`\s*u/ù/g;
1203
  $TEXT =~ s/\\c \s*c/ç/g;
7387 bpr 1204
 
11039 bpr 1205
  $TEXT =~ s/\{\s*\\`\s*a\s*\}/à/g;
1206
  $TEXT =~ s/\{\s*\\\^\s*a\s*\}/â/g;
1207
  $TEXT =~ s/\{\s*\\'\s*a\s*\}/á/g;
1208
  $TEXT =~ s/\{\s*\\'\s*e\s*\}/é/g;
1209
  $TEXT =~ s/\{\s*\\`\s*e\s*\}/è/g;
1210
  $TEXT =~ s/\{\s*\\\^\s*e\s*\}/ê/g;
1211
  $TEXT =~ s/\{\s*\\\^\s*i\s*\}/î/g;
1212
  $TEXT =~ s/\{\s*\\\`\s*i\s*\}/ì/g;
1213
  $TEXT =~ s/\{\s*\\\"\s*i\s*\}/ï/g;
1214
  $TEXT =~ s/\{\s*\\\^\s*o\s*\}/ô/g;
1215
  $TEXT =~ s/\{\s*\\\"\s*o\s*\}/ö/g;
1216
  $TEXT =~ s/\{\s*\\\`\s*o\s*\}/ò/g;
1217
  $TEXT =~ s/\{\s*\\\^\s*u\s*\}/û/g;
1218
  $TEXT =~ s/\{\s*\\`\s*u\s*\}/ù/g;
1219
  $TEXT =~ s/\{\s*\\c \s*c\s*\}/ç/g;
6693 bpr 1220
  $TEXT =~ s/\\maketitle//g;
11039 bpr 1221
  $TEXT =~ s/\{\\textquotesingle\}/'/g;
3846 bpr 1222
  $TEXT =~ s/\\textquotesingle/'/g;
1223
  $TEXT =~ s/\\guillemotleft/<</g;
1224
  $TEXT =~ s/\\guillemotright/>>/g;
4627 bpr 1225
# MODIF YVES NOEL 19/09/2011 (debut)
1226
  $TEXT =~ s/>>/&gt;&gt;/g;
1227
  $TEXT =~ s/~~/&nbsp;&nbsp;/g;
1228
  $TEXT =~ s/\\onslide\+<[0-9]*>//g;
1229
  $TEXT =~ s/\\onslide<[0-9]*->//g;
1230
  $TEXT =~ s/\\onslide<[0-9]*>//g;
1231
  $TEXT =~ s/\\onslide\+<[0-9]*\-[0-9]*>//g;
1232
  $TEXT =~ s/\\onslide<[0-9]*\-[0-9]*->//g;
1233
  $TEXT =~ s/\\onslide<[0-9]*\-[0-9]*>//g;
6003 bpr 1234
  $TEXT =~ s/\[<\+->\]//g;
7387 bpr 1235
 
4627 bpr 1236
# MODIF YVES NOEL 19/09/2011 (fin)
11039 bpr 1237
  $TEXT =~ s/\{\}//g;
1238
  $TEXT =~ s/\\selectlanguage\{french\}\\sffamily//g;
7387 bpr 1239
 
23 reyssat 1240
 #$TEXT =~ s/([^\\])\%+/$1/g;
1241
  $TEXT =~ s/([^\\])\%.*/$1/g;
1242
  $TEXT =~ s/\n\%.*/\n/g;
1243
  $TEXT =~ s/\\\\\[\S*\]/\n\n/g;
1244
  $TEXT =~ s/\\(vspace|hspace|vskip|hskip)\**{\S*}//g;
1245
  $TEXT =~ s/\\parskip=*[a-z0-9 \.]+//g;
1246
  $TEXT =~ s/\\(vskip|hskip)\s*[a-z0-9 \.]+//g;
1247
  $TEXT =~ s/\\smallskip/\n/g;
1248
  $TEXT =~ s/\\(med|big)skip/\n\n/g;
1249
#  $TEXT =~ s/\\makebox\[(\w)cm\]{ }/\&nbsp\&nbsp\&nbsp/g;
1250
  $TEXT =~ s/~(:|;|\?|\!)/&nbsp;$1/g;
1251
 #utiliser verb uniquement dans le cas d'un mot
10234 bpr 1252
#FIXME: $TEXT =~ s/\verb"([^"]+)"/<tt class=verb>$1<\/tt>/g;
11039 bpr 1253
  $TEXT =~ s/\\includegraphics\s*\[(.*)\]\s*\{(.*)\}/includegraphics($2,$1)/eg;
1254
  $TEXT =~ s/\\includegraphics\s*\{([^\}]+)\}/includegraphics($1)/eg;
23 reyssat 1255
  $TEXT =~ s/\\(begin|end){document}/\\document /g;
11039 bpr 1256
  $TEXT =~ s/\\exercise\{module=([^\&]+)\&([^\}]+)\}\{([^\}]+)\}/store_sheet($1,$2,$3,$worksheet)/eg ;
734 bpr 1257
  $TEXT =~ s/\\xspace//g;
7387 bpr 1258
  $TEXT = traite_beamer($TEXT) ;
23 reyssat 1259
  $TEXT;
1260
}
1261
 
10234 bpr 1262
sub traite_beamer { my ($TEXT) = @_;
11039 bpr 1263
   $TEXT =~ s/\\uncover\s*(<([^>]+)>)?\s*\{(.*)\}/\\fold\{.\}\{-->\}\{$3\}/g ;
1264
   $TEXT =~ s/\s*\\frametitle\{([^\}]+)\}/store_frametitle($1)/ge;
6104 bpr 1265
   $TEXT =~ s/\\pause//g;
5362 bpr 1266
   $TEXT ;
1267
}
1268
 
1269
sub store_frametitle{ my ($TEXT)= @_ ;
1270
  "<div class=\"frametitle\">$TEXT</div>"
1271
}
4852 bpr 1272
sub linewidth { my ($line,$w)= @_ ;
4858 bpr 1273
  $line =~ s/1\.[0]\s*\\(line|text)width/100\%/g;
1274
  $line =~ s/0?\.([0-9])\s*\\(line|text)width/$1 0\%/g;
11039 bpr 1275
  $line =~ s/0?\.([0-9]\{2\})[0-9]?\s*\\(line|text)width/$1\%/g;
4850 bpr 1276
  $line =~ s/ //g;
10034 bpr 1277
  $line = "$w=\"$line\"" if ($w);
7387 bpr 1278
  $line ;
4850 bpr 1279
}
10034 bpr 1280
sub store_sheet { my ($ad1,$ad2,$titre,$worksheet) = @_;
1281
   $ad2 =~ s/worksheet=(\d)+//g;
10824 bpr 1282
   $SHEET .= ":$ad1\n$ad2\n10\n1\n$titre\n\n";
10034 bpr 1283
   if ($worksheet) {
1284
     "\\exercise\{module=$ad1\&$ad2\&worksheet=$worksheet\}\{$titre\}"
1285
   }
1286
   else {
1287
      "\\exercise\{module=$ad1\&$ad2\}\{$titre\}"
1288
   };
1289
}
7387 bpr 1290
 
23 reyssat 1291
sub traite_preambule { my ($TEXT, $ref_env, $ref_command, $ref) = @_;
1292
  if ($TEXT=~ s/\\usepackage\[([^]]+)\]\{algorithmic\}//) {
10234 bpr 1293
       $algo_noend = 1 if ($1 =~ /noend/);
7228 bpr 1294
  };
1295
  $TEXT = recup_command($TEXT, $ref_command);
1296
  $TEXT = traite_command($TEXT, $ref_command);
23 reyssat 1297
  $TEXT = recup_environ($TEXT, $ref_env);
7387 bpr 1298
 
23 reyssat 1299
  $TEXT = recup_embed($TEXT, $ref) ;
1300
  for my $cmd ('ref','index') {
7387 bpr 1301
     $ref->{titb}{$cmd} = $ref_command->{definition}{$cmd . "name"}
23 reyssat 1302
  }
1303
  $TEXT;
1304
}
1305
 
1306
sub store_embed { my ($id, $titre, $ref) = @_ ;
1307
     $ref->{titb}{$id} = $titre ; $ref->{text}{$id} = `cat $EMBED/$id` ;
1308
     $ref->{upbl}{$id}='main'; $ref->{type}{$id}='embed';
11039 bpr 1309
     "\\embed\{$id\}\{$titre\}" ;
23 reyssat 1310
}
1311
 
1312
sub recup_embed { my ($TEXT, $ref) = @_ ;
11039 bpr 1313
     $TEXT =~ s /\\embed\s*\{([^\}]+)\}\s*\{(.*)\}/store_embed ($1, $2, $ref)/eg ;
23 reyssat 1314
     $TEXT ;
1315
 }
1316
 
1317
#FIXME on ne peut prendre qu'un seul fichier de style
10824 bpr 1318
#cree le fichier 1/.def
23 reyssat 1319
sub def { my ($ref, @style) = @_;
1320
  my $tit = $ref->{title}{main};
1321
  my $aut = $ref->{author}{main};
1322
  my $mail= $ref->{email}{main};
1323
  my $datm= $ref->{datm}{main};
10234 bpr 1324
  my $header = '<link rel="stylesheet" href="html/themes/_css/l2w.css" type="text/css" />';
23 reyssat 1325
  my $header_tmp ;
1326
  for my $file (@style){
1327
    if (!open(IN, $DIR . $file)) { die "le fichier $DIR$file n'existe pas";}
1328
    open (IN, $DIR . $file);
1329
    ($header_tmp = <IN>) =~ s/\n/\t/g;
1330
    $header .= "\t $header_tmp" ;
1331
  }
1332
  close IN;
6644 bpr 1333
  $header .= "\t<script type=\"text/javascript\">"
11039 bpr 1334
   . "jQuery\(function\(\) \{jQuery\( \"#left_toc\" \).menu\(\);\}\);"
1335
   . "jQuery\(function\(\) \{jQuery\( \"#right_toc\" \).menu\(\);\}\);"
6619 bpr 1336
   . "</script>" if ($TOOLTIP==1);
7387 bpr 1337
 
23 reyssat 1338
"copyright=gnu
1339
docopen=yes
1340
dlang=fr
1341
tit=$tit
1342
author=$aut
1343
email=$mail
1344
header=$header
1345
datm=$datm";
1346
}
10824 bpr 1347
#TODO en fait il faudrait renvoyer dans le cas ou le fichier est de type fold a la page en dessus
1348
# depliee. Je ne suis pas sure de savoir faire ! sinon, on perd la table des matieres.
23 reyssat 1349
 
1350
sub store_ref { my ($link, $titre, $anchor, $ref_bloc) = @_;
1351
  my $txt = '' ;
7387 bpr 1352
  my @list = (split(',', $link)) ;
23 reyssat 1353
  for my $l (@list) {
1354
  dbg("... référence fichier: \"$l\" titre \"$l\"");
1355
  my $page = $ref_bloc->{fichier}{$l} ;
10234 bpr 1356
  warn "label $link n'existe pas" if !($page) ;
11039 bpr 1357
  $txt .= ($#list) ? " \\link\{$page\}\{$l\}\{$anchor\}":
1358
             " \\link\{$page\}\{$titre\}\{$anchor\}";
23 reyssat 1359
 }
1360
 $txt ;
1361
};
1362
 
10824 bpr 1363
#cree la page
23 reyssat 1364
 
10837 bpr 1365
sub toc_HTML {my ($text, $toc_g, $toc_d, $toc_p, $CHEMIN_up, $CHEMIN_down, $index,$type) = @_ ;
7387 bpr 1366
   my $s='' ;
10837 bpr 1367
   $s= "l" if($toc_g || $toc_p) ; $s .= "r" if($toc_d) ;
1368
  if (($toc_g) || ($toc_d) || ($toc_p)) {
5362 bpr 1369
    $CHEMIN_up . '<div class="doc_latex2wims' . $s . '">'
1370
   . '<div class="wimsdoc">'
10608 bpr 1371
   . (($toc_g) ? '<ul id="left_toc" class="left_toc">'. $toc_g . $index . '</ul>' : '')
23 reyssat 1372
   . $text
10608 bpr 1373
   . (($toc_d) ? '<ul id="right_toc" class="right_toc">' . $toc_d . '</ul>' : '')
10869 bpr 1374
   . (($toc_p && !$toc_g) ? '<ul id="left_toc" class="left_toc">' . $toc_p . '</ul>' : '')
7387 bpr 1375
   . $CHEMIN_down .
10608 bpr 1376
   '</div></div>';
5362 bpr 1377
   }
10824 bpr 1378
   else {
10837 bpr 1379
    if (!(defined $type) || $type=~/fold|embed/) {$CHEMIN_up . $text . $CHEMIN_down }
10824 bpr 1380
      else {'<div class="wimsdoc">' . $CHEMIN_up . $text . $CHEMIN_down . '</div>'};
1381
    }
23 reyssat 1382
 }
1383
 
1384
 #################################
1385
 
1386
sub store_algo { my ($txt, $acc, $cmd, $comment, $indent) = @_ ;
1387
  $txt .= " " . $acc ;
10234 bpr 1388
  $txt .= $hash_algo{titre}{$hash_algo{suite}{$cmd}} if ($hash_algo{suite}{$cmd}) ;
23 reyssat 1389
  $indent = $indent + $hash_algo{avant}{$cmd} ;
6472 bpr 1390
  if($hash_algo{titre}{$cmd}) {
10234 bpr 1391
   $txt = "\n" . indent($indent) . $hash_algo{titre}{$cmd} . $txt if ( !($cmd =~ /END/) || $algo_noend == 0);
6472 bpr 1392
  }
1393
  else
1394
  {
10234 bpr 1395
   $txt = "\n" . indent($indent) . $txt if ( !($cmd =~ /END/) || $algo_noend == 0);
6472 bpr 1396
  }
11039 bpr 1397
  $txt .= indent('3') . "\{<i>$comment</i>\}" if ($comment) ;
23 reyssat 1398
  $txt .= "\n" ;
1399
  $txt =~ s/\n+/\n/ ;
1400
  $indent += $hash_algo{apres}{$cmd} ;
1401
  ($txt, $indent) ;
1402
}
1403
 
1404
sub algorithm { '<div class="algorithm">' . algorithmic (@_) . '</div>' } ;
1405
 
1406
sub algorithmic { my ($Text) = @_;
1407
  my $text ='' ; my $indent = 0 ;
1408
  my @T = split('\n', $Text);
1409
  for my $i (1..$#T) {
1410
    my $ligne = $T[$i];
1411
 #   $ligne =~ s/\$([^\$]+)\$/$1/g;
1412
  #  $ligne =~ s/\\\(//g;
1413
 #   $ligne =~ s/\\\)//g;
1414
    $ligne =~ s/\$([^\$]+)\$/\\( $1 \\)/g;
1415
    $ligne =~ s/^\[H\]//;
1416
    next if ($ligne =~ /\\begin\{algorithmic\}\[1\]/);
1417
    $ligne = "\n\n" if ($ligne =~ /\\end\{algorithmic\}/);
1418
    $ligne =~ s/\\caption\s*\{\s*([^\}]*)\}/<h4 class=\"algo_titre\"> $1 <\/h4>/;
1419
    $ligne =~ s/\\cdots/.../g;
1420
    $ligne =~ s/\\geq/>=/g;
1421
    $ligne =~ s/\\leq/<=/g;
1422
    $ligne =~ s/\\bmod/mod/g;
1423
#    $ligne =~ s/\[/<i>/g;
1424
#    $ligne =~ s/\]/<\/i>/g;
1425
    my $cle = 'FOR|WHILE|IF|UNTIL|ELSE|ELSIF|REQUIRE|ENSURE|STATE|ENDFOR|ENDWHILE|ENDIF' ;
1426
    if ($ligne =~ /\s*\\($cle)\s*(\[[^\]]+\]*)?\{([^\n]+)\}\s*([^\n]*)/) {
1427
         ($ligne,$indent) = store_algo($3, $4, $1, $2, $indent) ;
7387 bpr 1428
    }
23 reyssat 1429
    if ($ligne =~ /\s*\\($cle)\s*(\[[^\]]+\]*)?\s*([^\n]*)/) {($ligne,$indent) = store_algo('',$3, $1, $2, $indent);}
10824 bpr 1430
# TODO accepter des commentaires de plusieurs lignes ; presentation
10234 bpr 1431
# des commentaires ?
23 reyssat 1432
    if ($ligne =~ /^\s*\\COMMENT/) { $ligne = "<i>$ligne</i>\n" };
1433
    $text .= "\n" . $ligne;
6472 bpr 1434
    $text =~ s/\n{2,}/\n/g;
1435
    $text =~ s/(<br\s*\/>)+/<br \/>/g;
1436
    $text =~ s/(<br>)+/<br \/>/g;
23 reyssat 1437
  }
6472 bpr 1438
  $text =~ s/\n/<br \/>/g;
23 reyssat 1439
  $text ;
1440
}
1441
 
1442
sub indent { my $espace = "&nbsp;" x  6 ; $espace x $_[0]; }
1443
 
1444
sub Numero { my ($id) = @_;
10234 bpr 1445
  return '' if ($id =~ /F_[^S]\d/) || ($id =~ /L_/); #cela ne provient pas d'une section et co
23 reyssat 1446
  $id =~ s /(F|L)_//g;
1447
  $id =~ s/mainS(\d+)/&Roman($1)/e;
1448
  $id =~ s/S(\d+)S(\d+)S(\d+)/-$1-$2-$3/;
1449
  $id =~ s/S(\d+)S(\d+)/-$1-$2/;
1450
  $id =~ s/S(\d+)/-$1/;
1451
  $id;
1452
}
1453
 
1454
# permet de faire modifier quelque chose dans la table pour un tag
10824 bpr 1455
#TODO j'ai rajoute l'option couleur, du coup je ne sais plus faire fonctionner le shif
23 reyssat 1456
sub selection { my ($text, $couleur, @tag) = @_ ;
1457
  return '' if !defined($text);
1458
  for my $ta (@tag) {
6614 bpr 1459
    $text =~ s/XXXX="$ta">/li class="$couleur">/g;
1460
    $text =~ s/YYYY="$ta">/\/li>/g;
23 reyssat 1461
  };
1462
  $text;
1463
}
1464
 
734 bpr 1465
sub clean { my ($text, $ref) = @_;
10824 bpr 1466
   return '' if !defined($text);
6614 bpr 1467
   $text =~ s/<XXXX="\w*">/<li class="no_selected">/g;
1468
   $text =~ s/<YYYY="\w*">/<\/li>/g;
734 bpr 1469
   $text =~ s/ZZZZZ(\w+)/store_tip($1,$ref)/ge;
23 reyssat 1470
   $text;
1471
}
1472
 
10824 bpr 1473
sub store_tip { my ($tag, $ref)=@_ ;
734 bpr 1474
  my $tip = $ref->{toctip}{$tag} ;
3552 bpr 1475
  my $title=$ref->{tittoc}{$tag} ;
7387 bpr 1476
  #$tip =~ s/'/\\\\'/g if ($tip) ;
1477
  $title =~ s/'/\\\\'/g if ($title) ;
1478
  $ref->{toctip}{$tag} ? "<ul>$tip</ul>" : '' ;
734 bpr 1479
}
1480
 
23 reyssat 1481
sub chemin { my ($tag, $ref) = @_;
1482
  my $tagsup = $tag;
1483
  my $ch = $tag;
1484
  my $txt = ($ref->{tittoc}{$tagsup}) ? $ref->{tittoc}{$tagsup} : $ref->{titb}{$tagsup} ;
1485
  my $niv = 0;
1486
  while ($tagsup !~ /^main\b/) {
1487
    $niv++;
1488
    $tagsup = $ref->{upbl}{$tagsup};
10234 bpr 1489
    $ch = "$tagsup,$ch"; if (!$ref->{tittoc}{$tagsup}) { $ref->{tittoc}{$tagsup}=$tagsup};
11039 bpr 1490
    $txt = "\\link\{$tagsup\}\{$ref->{tittoc}{$tagsup}\} $FLECHE $txt" if ($tagsup) ; #if ($tagsup !~ /^main\b/);
23 reyssat 1491
  }
1492
  $ref->{chemin}{$tag} = $ch;
1493
  $ref->{niveau}{$tag} = $niv;
10824 bpr 1494
  return if (!$txt);
10837 bpr 1495
  '<div class="wims_chemin">' . "$LOAD $linkout $txt" . '</div>';}
23 reyssat 1496
 
1497
sub sortuniq {
1498
  my $prev = "not $_[0]";
1499
  grep { $_ ne $prev && ($prev = $_, 1) } sort @_;
1500
}
1501
 
1502
sub isotime {
178 bpr 1503
    my ($sec,$min,$hour,$mday,$mon,$year) = localtime(time);
23 reyssat 1504
    $year += 1900;
178 bpr 1505
    $mon += 1 ; $mday += 1 ;
23 reyssat 1506
    $mday = sprintf("%02d", $mday);
10234 bpr 1507
    $mon = sprintf("%02d", $mon);
23 reyssat 1508
    "$year-$mon-$mday $hour:$min:$sec";
1509
}
7387 bpr 1510
 
23 reyssat 1511
 sub usage {
1512
  print STDERR << "EOT"
1513
latex2wims [--style=style.css] [--macro=wims.sty] [--dir=dossier1] [--docdir=dossier2] [--embed=dossier3] [--verbose] file
1514
 
7387 bpr 1515
  --style=style.css : style.css fichier de style css à utiliser
23 reyssat 1516
     (peut aussi être mis dans le fichier file : \\wimsinclude{style.css})
10824 bpr 1517
  --macro=wims.sty : wims.sty fichier de style a utiliser
23 reyssat 1518
     (peut aussi être mis dans le fichier file : \\wimsinclude{wims.sty})
10824 bpr 1519
  --dir=dossier1 : dossier1 est le repertoire où se trouvent tous les fichiers dont le fichier file
1520
  --docdir=dossier2 : dossier2 est le repertoire dans lequel sera cree le document
23 reyssat 1521
     (un dossier dans le compte Modtool par exemple)
10824 bpr 1522
  --embed=dossier3 : les fichiers de dossier3 sont appeles dans file
7387 bpr 1523
     par la commande \embed{} (pour expert)
10824 bpr 1524
  --verbose : details
23 reyssat 1525
EOT
1526
;
1527
  exit 1;
1528
}
7387 bpr 1529
 
23 reyssat 1530
##======================================================================##
1531
## Adapted from work by OZAWA Sakuro <ozawa@prince.pe.u-tokyo.ac.jp>
10234 bpr 1532
## Copyright (c) 1995 OZAWA Sakuro. All rights reserved. This
23 reyssat 1533
## program is free software; you can redistribute it and/or modify
1534
## it under the same terms as Perl itself.
1535
##======================================================================##
1536
 
1537
sub Roman { my($arg) = shift;
1538
  my %roman_digit = qw(1 IV 10 XL 100 CD 1000 MMMMMM);
1539
  my @figure = reverse sort keys %roman_digit;
1540
  grep($roman_digit{$_} = [split(//, $roman_digit{$_}, 2)], @figure);
1541
 
1542
  my($x, $roman);
1543
  foreach (@figure) {
1544
    my($digit, $i, $v) = (int($arg / $_), @{$roman_digit{$_}});
1545
    if (1 <= $digit and $digit <= 3) {
1546
      $roman .= $i x $digit;
1547
    } elsif ($digit == 4) {
1548
      $roman .= "$i$v";
1549
    } elsif ($digit == 5) {
1550
      $roman .= $v;
1551
    } elsif (6 <= $digit and $digit <= 8) {
1552
      $roman .= $v . $i x ($digit - 5);
1553
    } elsif ($digit == 9) {
1554
      $roman .= "$i$x";
1555
    }
1556
    $arg -= $digit * $_;
1557
    $x = $i;
1558
  }
1559
  $roman
1560
 }