Add the Matlab-Scilab dictionnary
[scilab.git] / scilab_doc / Dictionnaire-Matlab-Scilab / makedoc.sce
1 mode(-1);
2 // Copyright INRIA
3
4 // Contents of this file
5 // - function []=xml2htmlpdf(XMLFILE,dic)
6 // - function [MATNAME,DESCR,SCINAME,NOTE,MATEX,SCIEX]=get_func_info(data,index)
7 // - function []=write_html_data(matname,descr,sciname,note,matex,sciex,funnb,dic)
8 // - function []=write_latex_data(matname,descr,sciname,note,matex,sciex,funnb,dic)
9 // - function [matname,descr,sciname,note,matex,sciex]=datatohtml(matname,descr,sciname,note,matex,sciex)
10 // - function [matname,descr,sciname,note,matex,sciex]=datatolatex(matname,descr,sciname,note,matex,sciex)
11 // - function []=create_html_index(indexfile,names,dic)
12 // - function [out]=special_name(in)
13 // - function [entry]=index_entry(in)
14 // - Some batch instructions
15
16 //****************************************************************************************
17 // function []=xml2htmlpdf(XMLFILE,dic)
18 // Copyright INRIA
19 // XMLFILE : XML file containing data to convert
20 // dic : dictionary we want to build (M2SCI or SCI2M)
21 //****************************************************************************************
22 function []=xml2htmlpdf(XMLFILE,dic)
23 LATEXFILE=dic+".tex"
24 HTMLFILE="./html/"+dic+".htm"
25 HTMLINDEXFILE="./html/"+dic+"_index.htm"
26
27 // Verify that XML file is well formed
28 //ierr=execstr("unix_s(""xmllint --noout --valid "+XMLFILE+""")","errcatch")
29 //if ierr<>0 then
30   //mprintf("File : "+XMLFILE+" does not follow DTD");
31   //return
32 //end
33
34 // Read data in XML file
35 [xmlfile,ierr]=mopen(XMLFILE,"r")
36 if ierr<>0 then
37   mprintf("Could not open file : "+XMLFILE);
38   return
39 end
40 xmldata=mgetl(xmlfile);
41 mclose(xmlfile);
42
43 // Create function table
44 funtable=[] // line matname sciname
45 k=1
46 while k<size(xmldata,1)
47   while strindex(xmldata(k),"<MATSCIFUN>")==[] & k<size(xmldata,1)
48     k=k+1
49   end
50   tmp=string(k)
51   while strindex(xmldata(k),"<MATNAME>")==[] & k<size(xmldata,1)
52     k=k+1
53   end
54   tmp=[tmp,stripblanks(strsubst(strsubst(xmldata(k),"<MATNAME>",""),"</MATNAME>",""))]
55   while strindex(xmldata(k),"<SCINAME>")==[] & k<size(xmldata,1)
56     k=k+1
57   end
58   tmp=[tmp,stripblanks(strsubst(strsubst(xmldata(k),"<SCINAME>",""),"</SCINAME>",""))]
59   if k<size(xmldata,1) then
60     funtable=[funtable;tmp]
61   end
62 end
63
64 // Parameter initialization according to dic 
65 if dic=="M2SCI" then
66   title="Matlab-Scilab equivalent functions"
67   leftimage="<B>Matlab</B>"
68   rightimage="<IMG SRC=scilab.gif>"
69   lefthead="Matlab function"
70   righthead="Scilab function"
71   
72   // Del No equivalent funnames
73   k=1
74   while k<=size(funtable,1)
75     if funtable(k,2)=="No equivalent" then
76       functable(k,:)=[]
77     else
78       funtable(k,4)=special_name(funtable(k,2)) // Name in index
79       funtable(k,5)=index_entry(funtable(k,2)) // Entry in index
80       k=k+1
81     end
82   end
83
84   [tmp,indexes]=sort(convstr(funtable(:,2)))
85   
86   funlines=[];funnames=[];indexnames=[];indexentries=[]
87   oplines=[];opnames=[];
88   varlines=[];varnames=[];
89   for k=1:size(indexes,1)
90     if length(funtable(indexes(k),5))==1 then
91       funlines=[funlines;funtable(indexes(k),1)] // Line in XML file
92       funnames=[funnames;funtable(indexes(k),2)] // Name of function
93       indexnames=[indexnames;funtable(indexes(k),4)]  // Name in index
94       indexentries=[indexentries;funtable(indexes(k),5)]  // Entry in index
95     elseif funtable(indexes(k),5)=="Operators" then
96       oplines=[oplines;funtable(indexes(k),1)];
97       opnames=[opnames;funtable(indexes(k),2)];
98     elseif funtable(indexes(k),5)=="Variables" then
99       varlines=[varlines;funtable(indexes(k),1)];
100       varnames=[varnames;funtable(indexes(k),2)];
101     else
102       error("Wrong index entry : "+funtable(indexes(k),5));
103     end
104   end
105   
106   // Add operators
107   for k=1:size(opnames,1) 
108     funlines=[funlines;oplines(k)]
109     funnames=[funnames;opnames(k)]
110     indexnames=[indexnames;special_name(opnames(k))]
111     indexentries=[indexentries;"Operators"]
112   end
113   
114   // Add Variables
115   for k=1:size(varnames,1) 
116     funlines=[funlines;varlines(k)]
117     funnames=[funnames;varnames(k)]
118     indexnames=[indexnames;special_name(varnames(k))]
119     indexentries=[indexentries;"Variables"]
120   end
121 else
122   title="Scilab-Matlab equivalent functions"
123   leftimage="<IMG SRC=scilab.gif>"
124   rightimage="<B>Matlab</B>"
125   lefthead="Scilab function"
126   righthead="Matlab function"
127   
128   // Del No equivalent funnames
129   k=1
130   while k<=size(funtable,1)
131     write(%io(2),funtable(k,3))
132     if funtable(k,3)=="No equivalent" then
133       funtable(k,:)=[]
134     elseif part(stripblanks(funtable(k,3)),1)=="1" then
135       funtable(k,:)=[]
136     else
137       funtable(k,4)=special_name(funtable(k,3)) // Name in index
138       funtable(k,5)=index_entry(funtable(k,3)) // Entry in index
139       k=k+1
140     end
141   end
142
143   [tmp,indexes]=sort(convstr(funtable(:,3)))
144   
145   funlines=[];funnames=[];indexnames=[];indexentries=[]
146   oplines=[];opnames=[];
147   varlines=[];varnames=[];
148   for k=1:size(indexes,1)
149     if length(funtable(indexes(k),5))==1 then
150       funlines=[funlines;funtable(indexes(k),1)] // Line in XML file
151       funnames=[funnames;funtable(indexes(k),3)] // Name of function
152       indexnames=[indexnames;funtable(indexes(k),4)]  // Name in index
153       indexentries=[indexentries;funtable(indexes(k),5)]  // Entry in index
154     elseif funtable(indexes(k),5)=="Operators" then
155       oplines=[oplines;funtable(indexes(k),1)];
156       opnames=[opnames;funtable(indexes(k),3)];
157     elseif funtable(indexes(k),5)=="Variables" then
158       varlines=[varlines;funtable(indexes(k),1)];
159       varnames=[varnames;funtable(indexes(k),3)];
160     else
161       error("Wrong index entry : "+funtable(indexes(k),5));
162     end
163   end
164   
165   // Add operators
166   for k=1:size(opnames,1) 
167     funlines=[funlines;oplines(k)]
168     funnames=[funnames;opnames(k)]
169     indexnames=[indexnames;special_name(opnames(k))]
170     indexentries=[indexentries;"Operators"]
171   end
172   
173   // Add Variables
174   for k=1:size(varnames,1) 
175     funlines=[funlines;varlines(k)]
176     funnames=[funnames;varnames(k)]
177     indexnames=[indexnames;special_name(varnames(k))]
178     indexentries=[indexentries;"Variables"]
179   end
180 end
181
182 if dic=="M2SCI" then
183   ref="Matlab"
184   eq="Scilab"
185 else
186   eq="Matlab"
187   ref="Scilab"
188 end
189
190 LATEX_FORWORD=[
191     "This document contains a list of some "+ref+" basis functions and compare them ";
192     "with the "+eq+" equivalent functions if there are. It gives the main differences ";
193     "and gives examples of particular cases.\newline";
194     "\newline"
195     "However not all "+ref+" and "+eq+" functions are described here.\newline";
196     "\newline"
197     "Equivalents for operators and variables can be found at the end of this document.\newline"
198     "\newline"
199     "Caution:\newline"
200     "This document is not dedicated to explain how functions work. ";
201     "Users can used online manuals of "+ref+" and "+eq+" for it.\newline"
202     "\newline"
203     ]
204 HTML_FOREWORD=[
205     LATEX_FORWORD;
206     "How to use this HTML guide:\newline";
207     "To have more details about functions and examples, clic on the ""triangles"" just ";
208     "at the left of "+ref+" function name.\newline";
209     "To have a more detailed index, clic on the letters and keywords.\newline"
210     ]
211
212 // Write HTML file beginning
213 HTML_FILE_BEG=[
214     "<!-- FILE GENERATED BY SCILAB - PLEASE DO NOT EDIT -->"
215     "<HTML>"
216     "<HEAD>"
217     "  <TITLE>"+title+"</title>"
218     "  <META HTTP-EQUIV=""Content-Type"" CONTENT=""text/html; charset=iso-8859-1"">"
219     "  <SCRIPT SRC=""matsci.js""></SCRIPT>"
220     "</HEAD>"
221     "<BODY BACKGROUND=""back.jpg"">"
222     "<P ALIGN=""center"">"
223     "<FONT FACE=""arial"">"
224     ]
225 [htmlfile,ierr]=mopen(HTMLFILE,"w")
226 if ierr<>0 then
227   mprintf("Could not open file : "+HTMLFILE);
228   return
229 end
230 mputl([HTML_FILE_BEG;
231     "<A NAME=""Foreword""></A>"
232     "<TABLE WIDTH=""80%"">";   
233     "  <TR WIDTH=""100%"">"
234     "    <TD COLSPAN=""4"" ALIGN=""center"">"
235     "      <FONT SIZE=""+2"" COLOR=""red"">Foreword</FONT>"
236     "      <HR WIDTH=""100%"">"
237     "    </TD>"
238     "  </TR>"
239     "  <TR WIDTH=""100%"">"
240     "    <TD COLSPAN=""4"">"
241     strsubst(HTML_FOREWORD,"\newline","<BR>")
242     "    </TD>"
243     "  </TR>"
244     "</TABLE>"
245     ],htmlfile)
246 mclose(htmlfile)
247
248 // Write LATEX file beginning
249 LATEX_FILE_BEG=[
250     "% FILE GENERATED BY SCILAB - PLEASE DO NOT EDIT %"
251     "\documentclass[12pt]{report}"
252     "\usepackage[a4paper,text={170mm,250mm},pdftex,twoside]{geometry}"
253     "\usepackage{fancyheadings}"
254     "\lhead{"+lefthead+"}"
255     "\rhead{"+righthead+"}"
256     "\cfoot{DRAFT - Page {\thepage}}"
257     "\addtolength{\parskip}{5mm}"
258     "\usepackage{makeidx}"
259     "\makeindex"
260     "\usepackage{amssymb}"
261     "\usepackage{hyperref}"
262     "\begin{document}"
263     "\pagestyle{empty}"
264     "\begin{center}"
265     "\vspace*{9cm}"
266     "\begin{minipage}[c]{\linewidth}"
267     "\begin{center}"
268     "\textbf{\Large{"+dic+":\\"+title+"\\}}"
269     "Version 1.0"
270     "\end{center}"
271     "\begin{center}"
272     "Scilab Project\\"
273     "INRIA Rocquencourt - BP 105\\"
274     "78153 Le Chesnay Cedex -  France\\"
275     "Email: \texttt{scilab@inria.fr}\\"
276     "2004"
277     "\end{center}"
278     "\end{minipage}"
279     "\end{center}"
280     "\cleardoublepage"
281     "\newpage"
282     "\pdfbookmark[0]{Foreword}{Forword}"
283     "\begin{center}"
284     "\textbf{Forword}"
285     "\end{center}"
286     LATEX_FORWORD
287     "\cleardoublepage"
288     "\printindex"
289     "\cleardoublepage"
290     "\pagestyle{fancy}"
291     ]
292 [latexfile,ierr]=mopen(LATEXFILE,"w")
293 if ierr<>0 then
294   mprintf("Could not open file : "+LATEXFILE);
295   return
296 end
297 mputl(LATEX_FILE_BEG,latexfile)
298 mclose(latexfile)
299
300 // Write all function informations
301 indentry_sav=""
302 for l=1:size(funnames,1)
303   
304   // Get infos from xml data
305   [matname,descr,sciname,note,matex,sciex]=get_func_info(xmldata,evstr(funlines(l)))
306   
307   // Add indexes to files (HTML and TEX)
308   indentry=indexentries(l)
309   if indentry<>indentry_sav then
310
311     // Index HTML file (A, B, ...)
312     HTML_DATA=[
313         "<A NAME="""+indentry+"""></A>";
314         "<TABLE WIDTH=""80%"">";
315         "  <TR WIDTH=""100%"">"
316         "    <TD COLSPAN=""4"">"
317         "    <HR WIDTH=""100%"">"
318         "    </TD>"
319         "  </TR>"
320         "  <TR WIDTH=""100%"">";
321         "    <TD HEIGHT=""20"" WIDTH=""100%"" COLSPAN=""4"">";
322         "    </TD>";
323         "  </TR>";
324         "  <TR WIDTH=""100%"">";
325         "    <TD WIDTH=""5%"" ALIGN=""center""></TD>";
326         "    <TD WIDTH=""10%"" ALIGN=""center"">"+leftimage+"</TD>";
327         "    <TD WIDTH=""70%"" ALIGN=""center""><FONT SIZE=""+2"" COLOR=""red"">"+indentry+"</FONT></TD>";
328         "    <TD WIDTH=""10%"" ALIGN=""center"">"+rightimage+"</TD>";
329         "  </TR>";
330         "</TABLE>"]
331     
332     [htmlfile,ierr]=mopen(HTMLFILE,"a+")
333     if ierr<>0 then
334       mprintf("Could not open file : "+HTMLFILE);
335       return
336     end
337     mputl(HTML_DATA,htmlfile)
338     mclose(htmlfile)
339     
340     // Index LATEX file (A, B, ...)
341     LATEX_DATA=[
342         "\newpage"
343         "\pdfbookmark[0]{"+indentry+"}{"+indentry+"}"
344         "\begin{center}\textbf{"+indentry+"}\end{center}"
345         ]
346     [latexfile,ierr]=mopen(LATEXFILE,"a+")
347     if ierr<>0 then
348       mprintf("Could not open file : "+LATEXFILE);
349       return
350     end
351     mputl(LATEX_DATA,latexfile)
352     mclose(latexfile)
353     
354     indentry_sav=indentry
355   end
356   
357   // Write data according to data read
358   write_html_data(matname,descr,sciname,note,matex,sciex,l,dic);
359   write_latex_data(matname,descr,sciname,note,matex,sciex,l,dic,indexnames(l),indexentries(l));
360 end
361
362 // Write HTML file end
363 HTML_FILE_END=[
364     "</P>"
365     "</FONT>"
366     "</BODY>"
367     "</HTML>"
368     ]
369 [htmlfile,ierr]=mopen(HTMLFILE,"a+")
370 if ierr<>0 then
371   mprintf("Could not open file : "+HTMLFILE);
372   return
373 end
374 mputl(["<HR WIDTH=""80%"">";HTML_FILE_END],htmlfile)
375 mclose(htmlfile)
376
377 // Write LATEX file end
378 LATEX_FILE_END=[
379     "\end{document}"
380     ]
381 [latexfile,ierr]=mopen(LATEXFILE,"a+")
382 if ierr<>0 then
383   mprintf("Could not open file : "+LATEXFILE);
384   return
385 end
386 mputl(LATEX_FILE_END,latexfile)
387 mclose(latexfile)
388
389 // Create HTML index file (done automatically for TEX)
390 create_html_index(HTMLINDEXFILE,funnames,dic,indexentries)
391 endfunction
392
393
394 //****************************************************************************************
395 //function [MATNAME,DESCR,SCINAME,NOTE,MATEX,SCIEX]=get_func_info(data,index)
396 // Copyright INRIA
397 // data : XML data
398 // index : position of function in data
399 //****************************************************************************************
400 function [MATNAME,DESCR,SCINAME,NOTE,MATEX,SCIEX]=get_func_info(data,index)
401 index=index+1
402 MATNAME=stripblanks(strsubst(strsubst(data(index),"<MATNAME>",""),"</MATNAME>",""))
403 index=index+1
404 SCINAME=stripblanks(strsubst(strsubst(data(index),"<SCINAME>",""),"</SCINAME>",""))
405 index=index+1
406 DESCR=stripblanks(strsubst(strsubst(data(index),"<DESCR>",""),"</DESCR>",""))
407 index=index+1
408 disp(data(index-3))
409 if strindex(data(index),"</MATSCIFUN>")==[] then
410   index=index+1
411   NOTE=""
412   while strindex(data(index),"</NOTE>")==[]
413     NOTE=NOTE+stripblanks(data(index))
414     index=index+1
415   end
416   index=index+1
417   if strindex(data(index),"</MATSCIFUN>")==[] then
418     
419     if strindex(data(index),"<MATEX>")<>[] then 
420       index=index+1
421       MATEX=[]
422       while strindex(data(index),"</MATEX>")==[] then
423         MATEX=[MATEX;stripblanks(data(index))]
424         index=index+1
425       end
426       index=index+1
427     end
428     
429     if strindex(data(index),"<SCIEX>")<>[] then 
430       index=index+1
431       SCIEX=[]
432       while strindex(data(index),"</SCIEX>")==[] then
433         SCIEX=[SCIEX;stripblanks(data(index))]
434         index=index+1
435       end
436     end      
437   else
438     MATEX=""
439     SCIEX=""
440   end
441 else
442   NOTE=""
443   MATEX=""
444   SCIEX=""
445 end
446 endfunction
447
448 //****************************************************************************************
449 //function []=write_html_data(matname,descr,sciname,note,matex,sciex,funnb,dic)
450 // Copyright INRIA
451 //****************************************************************************************
452 function []=write_html_data(matname,descr,sciname,note,matex,sciex,funnb,dic)
453 [matname,descr,sciname,note,matex,sciex]=datatohtml(matname,descr,sciname,note,matex,sciex)
454
455 if dic=="M2SCI" then
456   leftname=matname
457   rightname=sciname
458   leftex=matex
459   rightex=sciex
460 else
461   leftname=sciname
462   rightname=matname
463   leftex=sciex
464   rightex=matex
465 end  
466
467 [htmlfile,ierr]=mopen(HTMLFILE,"a+")
468 if ierr<>0 then
469   mprintf("Could not open file : "+HTMLFILE);
470   return
471 end
472
473 // Prepare data to write in HTML file
474 ind_name=strsubst(special_name(leftname)," ","-")
475 ind_name=strsubst(ind_name,"&#8596;","")
476
477 HTML_DATA = [
478     "<!---------- "+special_name(leftname)+" ---------->"
479     "<A NAME="""+ind_name+"""></A>";
480     "<TABLE CELLPADING=""0"" CELLSPACING=""0"" WIDTH=""80%"">";
481     "  <TR>"
482     "    <TD>"
483     "    <HR WIDTH=""100%"">"
484     "    </TD>"
485     "  </TR>"
486     "  <TR WIDTH=""100%""> "
487     "    <TD>"
488     "      <TABLE WIDTH=""100%"" CELLSPACING=""0"">"
489     "        <TR>"
490     "          <TD WIDTH=""5%"" ALIGN=""right"" VALIGN=""top"">"
491     ]
492 if or(leftex<>"") | or(rightex<>"") | or(note<>"") then
493   HTML_DATA=[
494       HTML_DATA;
495       "            <A HREF=""javascript:swap_couche(''"+string(funnb)+"'');"">"
496       "              <IMG NAME=""arrow"+string(funnb)+""" SRC=""rightarrow.gif?1"" BORDER=""0"">"
497       "            </A>"
498       ]
499 end
500 HTML_DATA=[
501     HTML_DATA;
502     "          </TD>"
503     "          <TD WIDTH=""10%"" ALIGN=""center""><B>"+leftname+"</B></TD>"
504     "          <TD WIDTH=""75%"" ALIGN=""center""><I>"+descr+"</I></TD>"
505     "          <TD WIDTH=""10%"" ALIGN=""center""><B>"+rightname+"</B></TD>"
506     "        </TR>"
507     "      </TABLE>"
508     "    </TD>"
509     "  </TR>"]
510 if or(leftex<>"") | or(rightex<>"") | or(note<>"") then
511   HTML_DATA=[
512       HTML_DATA;
513       "  <SCRIPT LANGUAGE=''JavaScript''>"
514       "    <!-- "
515       "      vis[''"+string(funnb)+"''] = ''hide'';"
516       "    //-->"
517       "  </SCRIPT>"
518       "  <TR WIDTH=""100%"">"
519       "    <TD>"
520       "      <DIV ID=''Layer"+string(funnb)+"'' STYLE=''display: none;''>"
521       "        <TABLE WIDTH=""100%"" CELLSPACING=""0"" BORDER=""1"" BORDERCOLOR=""silver"">"
522       ]
523   if or(note<>"") then
524     HTML_DATA=[
525         HTML_DATA
526         "          <TR>"
527         "            <TD COLSPAN=""2"">"+note+"</TD>"
528         "          </TR>"
529         ]
530   end
531   if or(rightex<>"") | or(leftex<>"") then
532     if leftex=="" then leftex="None";end
533     if rightex=="" then rightex="None";end
534     HTML_DATA=[
535         HTML_DATA
536         "          <TR>"
537         "            <TD VALIGN=""top"" WIDTH=""50%""><TT>"+leftex+"</TT></td>"
538         "            <TD VALIGN=""top"" WIDTH=""50%""><TT>"+rightex+"</TT></td>"
539         "          </TR>"
540         ]
541     
542   end
543   HTML_DATA=[
544       HTML_DATA
545       "        </TABLE>"
546       "        <BR>"
547       "      </DIV>"
548       "    </TD>"
549       "  </TR>"
550       ]
551 end
552
553 HTML_DATA=[
554     HTML_DATA
555     "</TABLE>"
556     ]
557
558 mputl(HTML_DATA,htmlfile)
559 mclose(htmlfile)
560 endfunction
561
562 //****************************************************************************************
563 // function [matname,descr,sciname,note,matex,sciex]=datatohtml(matname,descr,sciname,note,matex,sciex)
564 // Copyright INRIA
565 // Convert XML data to HTML
566 //****************************************************************************************
567 function [matname,descr,sciname,note,matex,sciex]=datatohtml(matname,descr,sciname,note,matex,sciex)
568
569 // Syntax modification
570 matname=strsubst(matname,"<MATH>","")
571 matname=strsubst(matname,"</MATH>","")
572 matname=strsubst(matname,"|-|","&#8596;")
573
574 sciname=strsubst(sciname,"<MATH>","")
575 sciname=strsubst(sciname,"</MATH>","")
576 sciname=strsubst(sciname,"|-|","&#8596;")
577
578 note=strsubst(note,"<P>","")
579 note=strsubst(note,"</P>","<BR>")
580 note=strsubst(note,"<B>","<B>")
581 note=strsubst(note,"<MATH>","")
582 note=strsubst(note,"</MATH>","")
583 note=strsubst(note,"|-|","&#8596;")
584
585 note=strsubst(note,"</NOTE_ITEM>","")
586 kitem=strindex(note,"<NOTE_ITEM")
587 kitem=[kitem,length(note)+1]
588 klabel=strindex(note,"LABEL")
589 kend=strindex(note,""">")
590 if kitem<>[] then
591   tmp=part(note,1:kitem(1)-1)
592   for m=1:size(kitem,"*")-1
593     label=strsubst(part(note,klabel(m)+7:kend(m)-1),"|-|","&#8596;")
594     tmp=tmp+"&#9657; "+label+":<BR>"+part(note,kend(m)+2:kitem(m+1)-1)+"<BR>"
595   end
596   note=stripblanks(tmp)
597 end
598
599 // Remove useless newline
600 if max(strindex(note,"<BR>"))==length(note)-3 then
601   note=part(note,1:(length(note)-4))
602 end
603
604 if matex<>"" then
605   tmp="<TT>"
606   for m=1:size(matex,1)
607     matex(m)=strsubst(matex(m),"<MATH>","")
608     matex(m)=strsubst(matex(m),"</MATH>","")
609     tmp=tmp+matex(m)+"<BR>"
610   end
611   tmp=tmp+"</TT>"
612   matex=tmp
613 end
614
615 if sciex<>"" then
616   tmp="<TT>"
617   for m=1:size(sciex,1)
618     tmp=tmp+sciex(m)+"<BR>"
619   end
620   tmp=tmp+"</TT>"
621   sciex=tmp
622 end
623
624 rhs=argn(2)
625 if rhs<3 then
626   note=""
627 end
628 if rhs<4 then
629   matex=""
630 end
631 if rhs<5 then
632   sciex=""
633 end
634
635 endfunction
636
637 //****************************************************************************************
638 //function []=write_latex_data(matname,descr,sciname,note,matex,sciex,funnb,dic)
639 // Copyright INRIA
640 //****************************************************************************************
641 function []=write_latex_data(matname,descr,sciname,note,matex,sciex,funnb,dic,index_name,index_entry)
642 [matname,descr,sciname,note,matex,sciex]=datatolatex(matname,descr,sciname,note,matex,sciex)
643
644 if dic=="M2SCI" then
645   leftname=matname
646   rightname=sciname
647   leftex=matex
648   rightex=sciex
649 else
650   leftname=sciname
651   rightname=matname
652   leftex=sciex
653   rightex=matex
654 end  
655
656 [latexfile,ierr]=mopen(LATEXFILE,"a+")
657 if ierr<>0 then
658   mprintf("Could not open file : "+LATEXFILE);
659   return
660 end
661
662 // Prepare data to write in LATEX file
663 ind_name=strsubst(special_name(leftname)," ","-")
664 ind_name=strsubst(ind_name,"$\Leftrightarrow$","")
665
666 LATEX_DATA = [
667     "%---------- "+ind_name+" ----------"
668     "\pdfbookmark[1]{"+leftname+"}{"+index_name+"}"
669     ]
670
671 if index_entry=="Operators" then
672   LATEX_DATA = [
673       LATEX_DATA;
674       "\index{"+index_entry+"!"+index_name+"\textsf{("+leftname+")}}"
675       ]
676 elseif  index_entry=="Variables" & index_name=="Last index" then
677   LATEX_DATA = [
678       LATEX_DATA;
679       "\index{"+index_entry+"!"+index_name+"\textsf{(end)}}"
680       ]
681 else
682   LATEX_DATA = [
683       LATEX_DATA;
684       "\index{"+index_entry+"!"+index_name+"}"
685       ]
686 end
687
688 LATEX_DATA = [
689     LATEX_DATA;
690     "\begin{center}"
691     "\begin{tabular}{|p{4.5cm}|p{3.25cm}p{3.25cm}|p{4.5cm}|}"
692     "\hline\multicolumn{1}{|p{4.5cm}}{\centering\textbf{"+leftname+"}} & "
693     "\multicolumn{2}{|p{6.5cm}|}{\centering\textit{"+descr+"}} & "
694     "\multicolumn{1}{p{4.5cm}|}{\centering\textbf{"+rightname+"}} \\ \hline"
695     ]
696 if note<>"" then
697   LATEX_DATA=[
698       LATEX_DATA
699       "\multicolumn{4}{|p{16.5cm}|}{"+note+"} \\ \hline"
700       ]
701 end
702
703 if or(rightex<>"") | or(leftex<>"") then
704   if leftex=="" then leftex="None";end
705   if rightex=="" then rightex="None";end
706   LATEX_DATA=[
707       LATEX_DATA
708       "\multicolumn{2}{|p{7.75cm}|}{"+leftex+"} & "
709       "\multicolumn{2}{p{7.75cm}|}{"+rightex+"} \\ \hline"
710       ]
711 end
712
713 LATEX_DATA=[
714     LATEX_DATA
715     "\end{tabular}"
716     "\end{center}"
717     ]
718
719 mputl(LATEX_DATA,latexfile)
720 mclose(latexfile)
721 endfunction
722
723 //****************************************************************************************
724 // function [matname,descr,sciname,note,matex,sciex]=datatolatex(matname,descr,sciname,note,matex,sciex)
725 // Copyright INRIA
726 // Convert XML data to LATEX
727 //****************************************************************************************
728 function [matname,descr,sciname,note,matex,sciex]=datatolatex(matname,descr,sciname,note,matex,sciex)
729
730 matname=strsubst(matname,"\","\textbackslash");
731 matname=strsubst(matname,"<MATH>^</MATH>","\textasciicircum")
732 matname=strsubst(matname,"%","\%")
733 matname=strsubst(matname,"$","\$")
734 matname=strsubst(matname,"&amp;","\&")
735 matname=strsubst(matname,"&lt;","<")
736 matname=strsubst(matname,"&gt;",">")
737 matname=strsubst(matname,"<MATH>","$")
738 matname=strsubst(matname,"</MATH>","$")
739 matname=strsubst(matname,"|-|","$\Leftrightarrow$")
740 matname=strsubst(matname,"_","\_")
741
742 sciname=strsubst(sciname,"\","\textbackslash");
743 sciname=strsubst(sciname,"<MATH>^</MATH>","\textasciicircum")
744 sciname=strsubst(sciname,"%","\%")
745 sciname=strsubst(sciname,"$","\$")
746 sciname=strsubst(sciname,"&amp;","\&")
747 sciname=strsubst(sciname,"&lt;","<")
748 sciname=strsubst(sciname,"&gt;",">")
749 sciname=strsubst(sciname,"<MATH>","$")
750 sciname=strsubst(sciname,"</MATH>","$")
751 sciname=strsubst(sciname,"|-|","$\Leftrightarrow$")
752 sciname=strsubst(sciname,"_","\_")
753
754 note=strsubst(note,"\","\textbackslash")
755 note=strsubst(note,"$","\$")
756 note=strsubst(note,"<P>","")
757 note=strsubst(note,"</P>","\newline ")
758 note=strsubst(note,"<B>","\textbf{")
759 note=strsubst(note,"</B>","}")
760 note=strsubst(note,"<MATH>^</MATH>","\textasciicircum")
761 note=strsubst(note,"<MATH>","$")
762 note=strsubst(note,"</MATH>","$")
763 note=strsubst(note,"</NOTE_ITEM>","")
764 note=strsubst(note,"&lt;","<")
765 note=strsubst(note,"&gt;",">")
766 note=strsubst(note,"%","\%")
767 note=strsubst(note,"|-|","$\Leftrightarrow$")
768
769 kitem=strindex(note,"<NOTE_ITEM")
770 kitem=[kitem,length(note)+1]
771 klabel=strindex(note,"LABEL")
772 kend=strindex(note,""">")
773 if kitem<>[] then
774   tmp=part(note,1:kitem(1)-1)
775   for m=1:size(kitem,"*")-1
776     label=strsubst(part(note,klabel(m)+7:kend(m)-1),"|-|","$\Leftrightarrow$")
777     tmp=tmp+"$\triangleright$ "+label+":\newline "+part(note,kend(m)+2:kitem(m+1)-1)+"\newline "
778   end
779   note=tmp
780   note=stripblanks(strsubst(note,"_","\_"))
781 end
782
783 // Remove useless newline
784 if max(strindex(note,"\newline"))==length(note)-7 then
785   note=part(note,1:(length(note)-8))
786 end
787
788 if or(matex<>"") then
789   tmp="\texttt{"
790   for m=1:size(matex,1)
791     matex(m)=strsubst(matex(m),"&amp;","\&")
792     matex(m)=strsubst(matex(m),"&lt;","<")
793     matex(m)=strsubst(matex(m),"&gt;",">")
794     matex(m)=strsubst(matex(m),"^","\textasciicircum")
795     matex(m)=strsubst(matex(m),"_","\_")
796     matex(m)=strsubst(matex(m),"$","\$")
797     matex(m)=strsubst(matex(m),"<MATH>","$")
798     matex(m)=strsubst(matex(m),"</MATH>","$")
799     tmp=tmp+matex(m)
800     if m<>size(matex,1) then
801       tmp=tmp+"\newline "
802     end
803   end
804   tmp=tmp+"}"
805   matex=tmp
806 end
807
808 if or(sciex<>"") then
809   tmp="\texttt{"
810   for m=1:size(sciex,1)
811     sciex(m)=strsubst(sciex(m),"&amp;","\&")
812     sciex(m)=strsubst(sciex(m),"&lt;","<")
813     sciex(m)=strsubst(sciex(m),"&gt;",">")
814     sciex(m)=strsubst(sciex(m),"^","\textasciicircum")
815     sciex(m)=strsubst(sciex(m),"_","\_")
816     sciex(m)=strsubst(sciex(m),"%","\%")
817     sciex(m)=strsubst(sciex(m),"$","\$")
818     sciex(m)=strsubst(sciex(m),"<MATH>","$")
819     sciex(m)=strsubst(sciex(m),"</MATH>","$")
820     tmp=tmp+sciex(m)
821     if m<>size(sciex,1) then
822       tmp=tmp+"\newline "
823     end
824   end
825   tmp=tmp+"}"
826   sciex=tmp
827 end
828
829 rhs=argn(2)
830 if rhs<3 then
831   note=""
832 end
833 if rhs<4 then
834   matex=""
835 end
836 if rhs<5 then
837   sciex=""
838 end
839
840 endfunction
841
842 //****************************************************************************************
843 // function []=create_html_index(indexfile,names,dic)
844 // Copyright INRIA
845 // - indexfile: name of file to create
846 // - names: function names
847 // - dic: dic to create
848 //****************************************************************************************
849 function []=create_html_index(indexfile,names,dic,indentries)
850
851 htmlfile=mopen(indexfile,"w")
852
853 mputl(HTML_FILE_BEG,htmlfile)
854
855 firstlettersav=""
856 for kname=1:size(names,"*")
857   
858   firstletter=indentries(kname)
859   if length(firstletter)==1 then
860     couche=string(ascii(firstletter))
861   elseif firstletter=="Operators" then
862     couche=string(1000)
863   else
864     couche=string(1001)
865   end
866   if firstletter<>firstlettersav then
867     firstlettersav=firstletter
868     if kname<>1 then
869       HTML_DATA=[
870           "      </DIV>"
871           "    </TD>"
872           "  </TR>"
873           "</TABLE>"
874           ]
875     else
876       if dic=="M2SCI" then
877         HTML_DATA="<A HREF=""SCI2M_doc.htm"" TARGET=""_top"">Go to SCI2M</A><BR>"
878       else
879         HTML_DATA="<A HREF=""M2SCI_doc.htm"" TARGET=""_top"">Go to M2SCI</A><BR>"
880       end
881       HTML_DATA=[
882           HTML_DATA
883           "<BR><A HREF="""+dic+".htm#Foreword"" TARGET=""dic"">Foreword</A><BR><BR>"
884           ]
885     end
886     HTML_DATA = [
887         HTML_DATA;
888         "<TABLE WIDTH=""70"">"
889         "  <TR>"
890         "    <TD>"
891         "      <A HREF=""javascript:void(0)"" onClick=""javascript:swap_couche(''"+couche+"''); parent.dic.document.location.href = ''"+dic+".htm#"+firstletter+"''"">"+firstletter+"</A><BR>"
892         "    </TD>"
893         "  </TR>"
894         "  <SCRIPT language=''JavaScript''>"
895         "    <!--       "
896         "      vis[''"+couche+"''] = ''hide'';"
897         "    //-->"
898         "  </SCRIPT>"
899         "  <TR>"
900         "    <TD>"
901         "      <DIV ID=''Layer"+couche+"'' STYLE=''display: none;''>"
902         ]
903   mputl(HTML_DATA,htmlfile)
904   end
905
906   ind_name=strsubst(special_name(names(kname))," ","-")
907   ind_name=strsubst(ind_name,"|-|","")
908
909   HTML_DATA=[
910       "<A HREF="""+dic+".htm#"+ind_name+""" TARGET=""dic"">"+strsubst(names(kname)," |-| ","--")+"</A><BR>"]
911   mputl(HTML_DATA,htmlfile)
912   
913 end
914 HTML_DATA=[
915     "      </DIV>"
916     "    </TD>"
917     "  </TR>"
918     "</TABLE>"
919     HTML_FILE_END]
920
921 mputl(HTML_DATA,htmlfile)
922 mclose(htmlfile);
923 endfunction
924
925 //****************************************************************************************
926 // function [out]=special_name(in)
927 // Copyright INRIA
928 // Deals with operator names
929 //****************************************************************************************
930 function [out]=special_name(in)
931 if in=="+" then
932   out="plus"
933 elseif in=="-" then
934   out="minus"
935 elseif in==".*." then
936   out="kronecker product"
937 elseif in=="./." then
938   out="kronecker right division"
939 elseif in==".\." then
940   out="kronecker letf division"
941 elseif in=="/" then
942   out="right division"
943 elseif in=="./" then
944   out="elementwise right division"
945 elseif in==".\" | in==".\textbackslash" then
946   out="elementwise left division"
947 elseif in=="<MATH>^</MATH>" | in=="^" | in=="\textasciicircum" then
948   out="exponent"
949 elseif in==".<MATH>^</MATH>" | in==".^" | in==".\textasciicircum" then
950   out="elementwise exponent"
951 elseif in=="*" then
952   out="multiplication"
953 elseif in==".*" then
954   out="elementwise multiplication"
955 elseif in=="<MATH>&gt;</MATH>" | in=="$>$" | in=="&gt;" then
956   out="greater than"
957 elseif in=="<MATH>&lt;</MATH>" | in=="$<$" | in=="&lt;"then
958   out="smaller than"
959 elseif in=="<MATH>&gt;</MATH>=" | in=="$>$=" | in=="&gt;=" then
960   out="greater or equal to"
961 elseif in=="<MATH>&lt;</MATH>=" | in=="$<$=" | in=="&lt;=" then
962   out="smaller or equal to"
963 elseif in=="==" then
964   out="equal to"
965 elseif in=="~=" then
966   out="not equal to"
967 elseif in=="''" then
968   out="transpose"
969 elseif in==".''" then
970   out="elementwise transpose"
971 elseif in=="&amp;" | in=="\&" then
972   out="logical AND"
973 elseif in=="<MATH>|</MATH>" | in=="|" | in=="$|$" then
974   out="logical OR"
975 elseif in=="\" | in=="\textbackslash" then
976   out="left division"
977 elseif in==":" then
978   out="colon"
979 elseif in=="~" then
980   out="negation"
981 elseif in=="\$" | in=="$" | in=="end (index)" then
982   out="Last index"
983 elseif in=="~MSDOS" then
984   out="isunix"
985 else
986   out=strsubst(in,"\_","");
987   out=strsubst(out,"_","");
988   out=strsubst(out,"%","");
989   out=strsubst(out,"$","");
990 end
991 endfunction
992
993 //****************************************************************************************
994 // function [entry]=index_entry(in)
995 // Copyright INRIA
996 // Finds index entries
997 //****************************************************************************************
998 function [entry]=index_entry(in)
999 if dic=="M2SCI" & or(in==["i","j","eps","ans","pi","end (index)"]) then
1000   entry="Variables"
1001 elseif part(in,1)=="%" | part(in,2)=="%" | in=="$" | in=="\$" | ~isempty(strindex(in,"MSDOS")) then
1002   entry="Variables"
1003 elseif special_name(in)<>in & isempty(strindex(in,"_")) then
1004   entry="Operators"
1005 else
1006   entry=convstr(part(in,1),"u")
1007 end
1008 endfunction
1009
1010 //****************************************************************************************
1011 // Batch instructions
1012 //****************************************************************************************
1013 disp("M2SCI");
1014 xml2htmlpdf("matscifuns.xml","M2SCI")
1015 disp("SCI2M");
1016 xml2htmlpdf("matscifuns.xml","SCI2M")
1017 disp("Doc done !")