pdfhtlatex_yp

PURPOSE ^

LUKE - LaTeX to PDF and HTML LUKE help builder

SYNOPSIS ^

function pdfhtlatex_yp(root_path,filelist,verbose)

DESCRIPTION ^

LUKE - LaTeX to PDF and HTML LUKE help builder

 Create dynamically all the help for C3PO/LUKE in html format from Latex files
 (needs standard TeX package with TeX4ht. TeXLive 2007 or above package is strongly recommanded)

 INPUT:

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function pdfhtlatex_yp(root_path,filelist,verbose)
0002 %LUKE - LaTeX to PDF and HTML LUKE help builder
0003 %
0004 % Create dynamically all the help for C3PO/LUKE in html format from Latex files
0005 % (needs standard TeX package with TeX4ht. TeXLive 2007 or above package is strongly recommanded)
0006 %
0007 % INPUT:
0008 %
0009 
0010 %   - root_path: path where the help directory should be placed (string)
0011 %       (default: local directory)
0012 %   - filelist: full path to LaTeX files (cells of string)
0013 %       (default: local directory)
0014 %   - verbose: display Latex compilation echos if not empty
0015 %       (default: empty)
0016 %
0017 % OUTPUT: none
0018 %
0019 % by Y. PEYSSON (CEA/DSM/IRFM, yves.peysson@cea.fr) and J. DECKER (CEA/DSM/IRFM, joan.decker@cea.fr)
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');%htlatex (TeXLive distribution)
0032     [s_pdflatex,~] = unix('which pdflatex');%pdflatex (TeXLive distribution)
0033     [s_imagemagick,~] = unix('which convert');%imagemagick
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;%initial directory name
0047     %
0048     if isempty(root_path),
0049         root_path = [pwd,filesep];%Working in the local directories where pdfhtlatex_yp is launched
0050     end
0051     %
0052     if ~strcmp(root_path(end),filesep),
0053         root_path = [root_path,filesep];%root_path must be ended by a filesep
0054     end
0055     %
0056     cd(root_path);
0057     %
0058     if isempty(filelist),
0059         filelisttex = dir('*.tex');%scan the local directory to find a LaTeX file
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];%root_path must be ended by a 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             % Delete recursively possible CVS directories
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');%run twice for the references
0140                     else
0141                         [status_pdf, result] = unix(['pdflatex  ',texfile]);
0142                         [status_pdf, result] = unix(['pdflatex  ',texfile]);%run twice for the references
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);%back to the LUKE root directory
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);%back to the initial directory
0174     %
0175 end
0176 
0177 function [search_path] = delete_cvsdir_yp(root_path,search_path)
0178 %LUKE - Recursive directory scan
0179 %
0180 % Recursive delete of all CVS directories from root directory
0181 %
0182 % INPUT:
0183 %
0184 %   - root_path: absolute directory path name to be scanned (string)
0185 %   - search_path: list of subdirectories (cell of strings)
0186 %
0187 % OUTPUT:
0188 %
0189 %   - search_path: structure of subdirectories scanned (not equal to input when recursive option is 'on') (structure)
0190 %
0191 % by Y. PEYSSON (CEA/DSM/IRFM, yves.peysson@cea.fr) and J. DECKER (CEA/DSM/IRFM, joan.decker@cea.fr)
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;%record the active directory name
0201     %
0202     if ~strcmp(root_path(end),filesep),
0203         root_path = [root_path,filesep];%root_path must be ended by a filesep
0204     end
0205     %
0206     cd(root_path);%move to the root folder to be scanned
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;%a valid new directory has been found
0215         end
0216     end 
0217     %
0218     if exist('CVS','dir') == 7,%a CVS directory exists in the rootdir
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);%recursive scan
0224     end
0225     %
0226     cd(dirinit);%back to the initial active directory
0227 end
0228

Community support and wiki are available on Redmine. Last update: 18-Apr-2019.