0001 function pdfhtlatex_yp(root_path,filelist,verbose)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 flag = 0;
0022
0023 if nargin == 0,
0024 root_path = '';
0025 filelist = {};
0026 end
0027 if nargin == 1,
0028 filelist = {};
0029 end
0030
0031 [s_htlatex,~] = unix('which htlatex');
0032 [s_pdflatex,~] = unix('which pdflatex');
0033 [s_imagemagick,~] = unix('which convert');
0034
0035 if s_htlatex || s_imagemagick,
0036 info_dke_yp(1,'The package tex4ht is not available: latex to html conversion is not possible.');
0037 end
0038 if s_pdflatex,
0039 info_dke_yp(1,'The package pdflatex is not available: lateX to pdf conversion is not possible.');
0040 end
0041
0042 if s_htlatex && s_pdflatex && s_imagemagick,
0043 return
0044 end
0045
0046 dirinit = pwd;
0047
0048 if isempty(root_path),
0049 root_path = [pwd,filesep];
0050 end
0051
0052 if ~strcmp(root_path(end),filesep),
0053 root_path = [root_path,filesep];
0054 end
0055
0056 cd(root_path);
0057
0058 if isempty(filelist),
0059 filelisttex = dir('*.tex');
0060 for ii = 1:length(filelisttex),
0061 filelist{ii} = fullfile(root_path,filelisttex(ii).name);
0062 end
0063 if isempty(filelist),
0064 info_dke_yp(1,'A list of Tex files must be given as input of pdfhtlatex_yp.m or the local directory must contain one or more LaTeX files !');
0065 return
0066 end
0067 end
0068
0069 docpath = root_path;
0070 if nargin > 1,
0071 latexdochtmlpath = fullfile(docpath,'Help','LaTeX');
0072 end
0073
0074 if nargin > 1,
0075 if ~exist(latexdochtmlpath),
0076 mkdir(docpath,fullfile('Help','LaTeX'));
0077 else
0078 rmdir(latexdochtmlpath,'s');
0079 mkdir(docpath,fullfile('Help','LaTeX'));
0080 end
0081 else
0082 latexdochtmlpath = docpath;
0083 end
0084
0085 for i = 1:length(filelist),
0086 try
0087 [pathstr, name, ext] = fileparts(filelist{i});
0088 if ~strcmp(pathstr(end),filesep),
0089 pathstr = [pathstr,filesep];
0090 end
0091 texfile = [name,ext];
0092 source_dir = pathstr;
0093 destination_dir = fullfile(latexdochtmlpath,strrep(pathstr,root_path,''));
0094
0095 if nargin > 1,
0096 if ~exist(destination_dir),
0097 mkdir(destination_dir);
0098 else
0099 rmdir(destination_dir,'s');
0100 mkdir(destination_dir);
0101 end
0102 end
0103
0104 if ~strcmp(pathstr,root_path),
0105 [status,message,messageid] = copyfile(source_dir,destination_dir,'f');
0106 else
0107 status = 1;
0108 end
0109
0110 if ~status,
0111 info_dke_yp(1,['The copy from ',source_dir,' to ',destination_dir, ' failed.']);
0112 return
0113 end
0114
0115 cd(destination_dir);
0116
0117
0118
0119 delete_cvsdir_yp(destination_dir);
0120
0121 try
0122 if ~unix('which htlatex') && ~unix('which convert')
0123 if isempty(verbose)
0124 [status_ht, result] = unix(['htlatex ',texfile,' ''html,index=2,3,next''']);
0125 else
0126 [status_ht, result] = unix(['htlatex ',texfile,' ''html,index=2,3,next'''],'-echo');
0127 end
0128 else
0129 status_ht = 1;
0130 end
0131 catch
0132 status_ht = 1;
0133 end
0134
0135 try
0136 if ~unix('which pdflatex')
0137 if isempty(verbose)
0138 [status_pdf, result] = unix(['pdflatex ',texfile],'-echo');
0139 [status_pdf, result] = unix(['pdflatex ',texfile],'-echo');
0140 else
0141 [status_pdf, result] = unix(['pdflatex ',texfile]);
0142 [status_pdf, result] = unix(['pdflatex ',texfile]);
0143 end
0144 else
0145 status_pdf = 1;
0146 end
0147 catch
0148 status_pdf = 1;
0149 end
0150
0151 if status_ht == 0,
0152 info_dke_yp(1,['Successfull LaTeX to HTML conversion of the file ',texfile]);
0153 else
0154 info_dke_yp(1,['Unsuccessfull LaTeX to HTML conversion of the file ',texfile]);
0155 disp(result);
0156 end
0157
0158 if status_pdf == 0,
0159 info_dke_yp(1,['Successfull LaTeX to PDF conversion of the file ',texfile]);
0160 else
0161 info_dke_yp(1,['Unsuccessfull LaTeX to PDF conversion of the file ',texfile]);
0162 disp(result);
0163 end
0164
0165 cd(root_path);
0166 catch
0167 cd(root_path);
0168 rmdir(destination_dir,'s');
0169 info_dke_yp(1,['An error occured during LaTeX translation of the file ',texfile]);
0170 end
0171 end
0172
0173 cd(dirinit);
0174
0175 end
0176
0177 function [search_path] = delete_cvsdir_yp(root_path,search_path)
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193 if nargin == 0,
0194 error('The root_path of the folder to be scanned must be given as input delete_cvsdir_yp.m !');
0195 end
0196 if nargin == 1,
0197 search_path = {};
0198 end
0199
0200 dirinit = pwd;
0201
0202 if ~strcmp(root_path(end),filesep),
0203 root_path = [root_path,filesep];
0204 end
0205
0206 cd(root_path);
0207 dirlist = dir;
0208 nsearch_path0 = length(search_path);
0209 nsearch_path = nsearch_path0;
0210
0211 for ii = 1:length(dirlist),
0212 if dirlist(ii).isdir == 1 & ~strcmp(dirlist(ii).name(1),'.') & ~strcmp(dirlist(ii).name,'CVS'),
0213 search_path = [search_path,[root_path,dirlist(ii).name]];
0214 nsearch_path = nsearch_path + 1;
0215 end
0216 end
0217
0218 if exist('CVS','dir') == 7,
0219 rmdir('CVS','s');
0220 end
0221
0222 for ii = nsearch_path0+1:nsearch_path,
0223 [search_path] = delete_cvsdir_yp(search_path{ii},search_path);
0224 end
0225
0226 cd(dirinit);
0227 end
0228