xml2tex - Xml file to tex file convertor
xml2tex(namef,flag,typdoc)
- namef : string. name of the XML source file to be converted
- flag : string. set the type of man page
- 'block' : for interfacing function of scicos block
- 'pal' : for a palette (.cosf file)
- 'diagr' : for a scicos diagram (.cos file)
- 'scilib' : for a library of scilab macros
- 'sci' : for a scilab macro.
- 'rout' : for computational routine
- 'sim' : for scilab simulation script (_sim.sce file)
- 'sce' : for scilab script (.sce file)
- typdoc : string. a flag to set the type of the documentation to produce
- 'html' : for html format
- 'guide' : for paper format
//xml2tex
//fonction qui convertit un ficher d'aide scilab xml qui
//se trouve dans man/xml (xml_path) en un ensemble de fichier latex :
//fichier namef_call_seq.tex :
//fichier namef_long.tex : fichier tex correspondant à la description longue
//fichier namef_param.tex : fichier tex correspondant aux paramètres
//fichier namef_ex.tex
//fichier namef_see_also.tex : fichier tex correspondant aux pages "voir aussi"
//fichier namef_authors.tex : fichier correspondant aux auteurs du fichier xml
//fichier _bib.tex :
//fichier _used_func.tex :
//
//Entrée namef : nom du fichier xml à convertir sans extension
// (ex:'CAN_f')
// flag : 'block' pour une fonction d'interface scicos
// 'pal' pour un fichier palette scicos (cosf)
// 'diagr' pour un diagramme de simulation scicos
// 'scilib' pour une librairie de fonctions scilab
// 'sci' pour une fonction scilab
// 'rout' pour une routine bas-niveau
// 'sim' pour un script de simulation scilab
// typdoc : 'html' (default)
// 'guide' pour du papier
//Sortie néant
function xml2tex(namef,flag,typdoc)
if rsh<3 then
typdoc='html'
end
//choix de l'extension du répertoire
select flag
case 'block'
ext=''
case 'pal'
ext='_cosf'
case 'diagr'
ext='_cos'
case 'scilib'
ext='_scilib'
case 'sci'
ext='_sci'
case 'rout'
ext='_rout'
case 'sim'
ext=''
case 'sce'
ext='_sce'
end
//Pour chaque nom
for ij=1:size(namef,1)
name=namef(ij)+ext
//test présence fichier source .xml
if fileinfo(xml_path+lang+'/'+namef(ij)+'.xml')<>[] then
//crée un repertoire si non existant
if fileinfo(name+'/')==[] then unix_g("mkdir "+name+"/"), end;
printf("Generate %s.tex from %s.xml... ",namef(ij),namef(ij));
//Ecrit fichier _call_seq.tex
txt=return_xml_call_seq(xml_path+lang+'/'+namef(ij)+'.xml');
if txt<>[] then
tt=['\begin{verbatim}';txt];
tt=[tt;'\end{verbatim}'];
mputl(tt,'./'+name+'/'+namef(ij)+'_call_seq.tex');
end
//Ecrit fichier _param.tex
//txt=return_xml_param2(xml_path+namef(ij)+'.xml');
txt_list=return_xml_param3(xml_path+lang+'/'+namef(ij)+'.xml');
if txt_list<>[] then
//trouve la profondeur d'indentation max.
nb_indent=size(txt_list);
//trouve le nombre de paramètres
nb_param=0;
for i=1:size(txt_list)
nb_param=nb_param+size(txt_list(i)(2),1);
end
//pause
//initialise une nouvelle liste
n=list();
for i=1:nb_param
n(i)=list();
n(i)(1)=0;
n(i)(2)="";
n(i)(3)="";
end
//met la liste dans l'ordre des paragraphes
for i=1:size(txt_list)
for j=1:size(txt_list(i)(1),1)
n(txt_list(i)(1)(j,1))(1)=i;
n(txt_list(i)(1)(j,1))(2)=txt_list(i)(2)(j,1);
n(txt_list(i)(1)(j,1))(3)=txt_list(i)(2)(j,2);
end
end
//crée la liste des param au format tex
tt_param=[];
pre_i=0; //indentation précédente
for i=1:size(n)
dif_i=n(i)(1)-pre_i;
if dif_i<>0 then
if dif_i>0 then
for j=1:dif_i
tt_param=[tt_param;' \begin{itemize}'];
end
elseif dif_i<0 then
for j=-1:-1:dif_i
tt_param=[tt_param;' \end{itemize}'];
end
end
end
pre_i=n(i)(1);
titlep=retrieve_char(n(i)(2));
descp=retrieve_char(n(i)(3));
if flag=='block' then
tt_param=[tt_param;
' \item{\textbf{'+latexsubst(titlep)+' :}}\linebreak';
latexsubst(descp);];
else
tt_param=[tt_param;
' \item{\textbf{'+latexsubst(titlep)+' :}} '+latexsubst(descp);];
end
end
dif_i=-pre_i;
if dif_i<0 then
for j=-1:-1:dif_i
tt_param=[tt_param;' \end{itemize}'];
end
end
if typdoc=='guide' then
tt_param=strsubst(tt_param,'\linebreak','\\');
end
mputl(tt_param,'./'+name+'/'+namef(ij)+'_param.tex');
end
//Ecrit fichier _long.tex
list_txt=return_xml_desc3(xml_path+lang+'/'+namef(ij)+'.xml');
if list_txt<>list(list()) then
n=1; //profondeur d'indentation
tt=[];
for i=1:size(list_txt)
if list_txt(i)(1)>n then
for j=1:list_txt(i)(1)-n
tt=[tt;'\begin{quotation}'}
end
n=list_txt(i)(1);
end
if i>1 & list_txt(i)(1)<n then
for j=1:n-list_txt(i)(1)
tt=[tt;'\end{quotation}'}
end
n=list_txt(i)(1);
end
if list_txt(i)(2)<>"" then
tt=[tt;'\textbf{'+latexsubst(list_txt(i)(2))+' }'+...
latexsubst(list_txt(i)(3));'']
else
tt=[tt;latexsubst(list_txt(i)(3));'']
end
end
if n>1 then
for j=1:(n-1)
tt=[tt;'\end{quotation}'}
end
end
mputl(tt,'./'+name+'/'+namef(ij)+'_long.tex');
end
//Ecrit fichier _ex.tex
txt=return_xml_ex(xml_path+lang+'/'+namef(ij)+'.xml');
if txt<>[]&txt<>"" then
if flag=='sci'|flag=='rout' then
tt=['\begin{verbatim}';txt];
tt=[tt;'\end{verbatim}'];
elseif flag=='block' then
tt=latexsubst(txt);
end
mputl(tt,'./'+name+'/'+namef(ij)+'_ex.tex');
end
//Ecrit fichier _see_also.tex
txt=return_xml_see_also(xml_path+lang+'/'+namef(ij)+'.xml');
if txt<>[]&txt<>"" then
emptyf=%t;
for i=1:size(txt,'r')
if txt(i,1)<>"" then
emptyf=%f
break
end
end
if ~emptyf then
tt=['\begin{itemize}'];
for i=1:size(txt,'r')
txt1=latexsubst(txt(i,1));
txt2=[];
txt2=return_xml_sdesc(xml_path+lang+'/'+txt(i,1)+'.xml');
txt3=return_xml_type(xml_path+lang+'/'+txt(i,1)+'.xml');
txt3=change_lang_title(lang,txt3);
txt2=latexsubst(txt2)
if typdoc=='html' then
tt=[tt;'\item{\htmladdnormallink{'+latexsubst(txt(i,1))+...
' - '+txt2+' ('+txt3+')}{'+txt(i,1)+'.htm}}'];
else
tt=[tt;'\item{'+txt1+' - '+txt2+' ('+txt3+')}']; //on pout rajouter un \ref{} ici!
end
end
tt=[tt;'\end{itemize}'];
mputl(tt,'./'+name+'/'+namef(ij)+'_see_also.tex');
end
end
//Ecrit fichier _bib.tex
txt=return_xml_biblio(xml_path+lang+'/'+namef(ij)+'.xml');
if txt<>[]&txt<>"" then
txt=latexsubst(txt)
tt=['\begin{thebibliography}{}';txt;'\end{thebibliography}']
mputl(tt,'./'+name+'/'+namef(ij)+'_bib.tex');
end
//Ecrit fichier _authors.tex
txt=return_xml_authors2(xml_path+lang+'/'+namef(ij)+'.xml')
if txt<>[]&txt<>"" then
txt=latexsubst(txt)
mputl(txt,'./'+name+'/'+namef(ij)+'_authors.tex');
end
//Ecrit fichier _used_func.tex
txt=return_xml_used_func(xml_path+lang+'/'+namef(ij)+'.xml')
if txt<>[]&txt<>"" then
txt=latexsubst(txt)
mputl(txt,'./'+name+'/'+namef(ij)+'_used_func.tex');
end
printf("Done\n");
end
end
endfunction
IRCOM Group
Alan Layec