0001 function prt_latex(c)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 if ~nargin,
0026 if ~exist('prt_cfg_batch.m','file'), prt; end
0027 c = prt_cfg_batch;
0028 end
0029
0030
0031
0032
0033
0034 for i=1:numel(c.values),
0035 bn = c.values{i}.tag;
0036 fp = fopen(fullfile(prt('dir'),'manual',['batch_',bn,'.tex']),'w');
0037 if fp==-1, sts = false; return; end;
0038 chapter(c.values{i},fp);
0039 end;
0040
0041
0042
0043 fp = fopen(fullfile(prt('dir'),'manual','adv_functions.tex'),'w');
0044 if fp==-1, sts = false; return; end;
0045
0046 l_subdirs = {'machines','utils'};
0047 excl_files = {'Contents.m'};
0048 PRTdir = prt('dir');
0049
0050
0051 fprintf(fp,'\\chapter{%s \\label{Chap:%s}}\n\\minitoc\n\n\\vskip 1.5cm\n\n',...
0052 texify('List of PRoNTo functions'),'sec:functions');
0053 fprintf(fp,'This is the list of PRoNTo functions, including the subdirectories: ');
0054 for ii=1:numel(l_subdirs)
0055 fprintf(fp,'%s',texify(['{\tt ',l_subdirs{ii},'}']));
0056 if ii<numel(l_subdirs)-1
0057 fprintf(fp,', ');
0058 elseif ii==numel(l_subdirs)-1
0059 fprintf(fp,' and ');
0060 else
0061 fprintf(fp,'.\n\n');
0062 end
0063 end
0064
0065
0066 f = spm_select('List',PRTdir,'.*\.m$');
0067 for ii=1:numel(excl_files)
0068 f(strcmp(cellstr(f),excl_files{ii}),:) = [];
0069 end
0070 write_mfiles_help(f,fp);
0071
0072
0073 for ii = 1:numel(l_subdirs)
0074 p = fullfile(PRTdir,l_subdirs{ii});
0075 fprintf(fp,'\n\\%s{%s}\n','section',texify(l_subdirs{ii}));
0076 f = spm_select('List',p,'.*\.m$');
0077 write_mfiles_help(f,fp,l_subdirs(ii));
0078 end
0079
0080 return;
0081
0082
0083 function write_mfiles_help(f,fp,base_dir)
0084
0085 if nargin<3,
0086 base_dir = '';
0087 lev = 1;
0088 else
0089 lev = numel(base_dir)+1;
0090 tmp = base_dir{1};
0091 ltmp = tmp;
0092 for ii=2:numel(base_dir)
0093 ltmp = [tmp,'\textbackslash ',base_dir{ii}];
0094 tmp = fullfile(tmp,base_dir{ii});
0095 end
0096 lbase_dir = ltmp;
0097 base_dir = tmp;
0098 end
0099
0100 sec = {'section','subsection','subsubsection','paragraph','subparagraph', ...
0101 'textbf','textsc','textsl','textit'};
0102
0103 for ii=1:size(f,1)
0104
0105 if isempty(base_dir)
0106 lfunc_name = deblank(f(ii,:));
0107 else
0108 lfunc_name = [lbase_dir,'\textbackslash ',deblank(f(ii,:))];
0109 end
0110 func_name = fullfile(base_dir,deblank(f(ii,:)));
0111 fprintf(fp,'\n\\%s{%s}\n',sec{min(lev,length(sec))},texify(lfunc_name));
0112 fprintf(fp,'%s\n\n',texify('\begin{alltt}'));
0113
0114
0115 htxt = textscan(fopen(func_name),'%s','delimiter','\n','whitespace','');
0116 htxt = htxt{1};
0117 i_beg = find(strncmp('% ',htxt,2)); i_beg = i_beg(1);
0118 i_end = find(strncmp('% Copyright (C)',htxt,15))-2;
0119 htxt = htxt(i_beg:i_end);
0120
0121 for jj=1:numel(htxt)
0122 if strcmp(htxt{jj},'%')
0123 fprintf(fp,'%s\n',' ');
0124 else
0125 fprintf(fp,'%s\n',texify(htxt{jj}(2:end)));
0126 end
0127 end
0128 fprintf(fp,'%s\n\n',texify('\end{alltt}'));
0129 end
0130
0131 return
0132
0133
0134 function sts = chapter(c,fp)
0135 bn = c.tag;
0136 if nargin<2
0137 fp = fopen(fullfile(pwd,'manual',[bn,'.tex']),'w');
0138 if fp==-1, sts = false; return; end;
0139 end
0140
0141 fprintf(fp,'%% $Id: prt_latex.m 518 2012-04-17 10:01:12Z cphillip $ \n\n');
0142 fprintf(fp, ...
0143 '\\chapter{%s \\label{Chap:%s}}\n\n\\vskip 1.5cm\n\n', ...
0144 texify(c.name),c.tag);
0145 write_help(c,fp);
0146
0147 switch class(c),
0148 case {'cfg_branch','cfg_exbranch'},
0149 for i=1:numel(c.val),
0150 section(c.val{i},fp);
0151 end;
0152 case {'cfg_repeat','cfg_choice'},
0153 for i=1:numel(c.values),
0154 section(c.values{i},fp);
0155 end;
0156 end;
0157 fclose(fp);
0158 sts = true;
0159 return;
0160
0161
0162 function section(c,fp,lev)
0163 if nargin<3, lev = 1; end;
0164 sec = {'section','subsection','subsubsection','paragraph','subparagraph', ...
0165 'textbf','textsc','textsl','textit'};
0166
0167 fprintf(fp,'\n\\%s{%s}\n',sec{min(lev,length(sec))},texify(c.name));
0168 write_help(c,fp);
0169 switch class(c),
0170 case {'cfg_branch','cfg_exbranch'},
0171 for i=1:numel(c.val),
0172 section(c.val{i},fp,lev+1);
0173 end;
0174 case {'cfg_repeat','cfg_choice'},
0175 for i=1:numel(c.values),
0176 section(c.values{i},fp,lev+1);
0177 end;
0178 end;
0179
0180 if lev>length(sec),
0181 warning(['Too many nested levels... ',c.name]);
0182 end;
0183 return;
0184
0185
0186 function write_help(hlp,fp)
0187 if isa(hlp, 'cfg_item'),
0188 if ~isempty(hlp.help),
0189 hlp = hlp.help;
0190 else
0191 return;
0192 end;
0193 end;
0194 if iscell(hlp),
0195 for i=1:numel(hlp),
0196 write_help(hlp{i},fp);
0197 end;
0198 return;
0199 end;
0200 str = texify(hlp);
0201 fprintf(fp,'%s\n\n',str);
0202 return;
0203
0204
0205 function str = texify(str0)
0206 st1 = strfind(str0,'/*');
0207 en1 = strfind(str0,'*/');
0208 st = [];
0209 en = [];
0210 for i=1:numel(st1),
0211 en1 = en1(en1>st1(i));
0212 if ~isempty(en1),
0213 st = [st st1(i)];
0214 en = [en en1(1)];
0215 en1 = en1(2:end);
0216 end;
0217 end;
0218
0219 str = [];
0220 pen = 1;
0221 for i=1:numel(st),
0222 str = [str clean_latex(str0(pen:st(i)-1)) str0(st(i)+2:en(i)-1)];
0223 pen = en(i)+2;
0224 end;
0225 str = [str clean_latex(str0(pen:numel(str0)))];
0226 return;
0227
0228
0229 function str = clean_latex(str)
0230 str = strrep(str,'$','\$');
0231 str = strrep(str,'&','\&');
0232 str = strrep(str,'^','\^');
0233 str = strrep(str,'_','\_');
0234 str = strrep(str,'#','\#');
0235
0236 str = strrep(str,'|','$|$');
0237 str = strrep(str,'>','$>$');
0238 str = strrep(str,'<','$<$');
0239 return;
0240
0241
0242 function bibcstr = get_bib(bibdir)
0243 biblist = dir(fullfile(bibdir,'*.bib'));
0244 bibcstr={};
0245 for k = 1:numel(biblist)
0246 [p n e v] = spm_fileparts(biblist(k).name);
0247 bibcstr{k} = fullfile(bibdir,n);
0248 end
0249
0250
0251 function clean_latex_compile
0252 PRTdir = prt('dir');
0253 p = fullfile(PRTdir,'manual');
0254 [f, d] = spm_select('FPlist',p,'.*\.aux$');
0255 f = strvcat(f, spm_select('FPlist',p,'.*\.tex$'));
0256 f = strvcat(f, spm_select('FPlist',p,'^manual\..*$'));
0257 f(strcmp(cellstr(f),fullfile(PRTdir,'manual','prt_manual.tex')),:) = [];
0258 f(strcmp(cellstr(f),fullfile(PRTdir,'manual','prt_manual.pdf')),:) = [];
0259 for i=1:size(d,1)
0260 f = strvcat(f, spm_select('FPlist',deblank(d(i,:)),'.*\.aux$'));
0261 end
0262 f(strcmp(cellstr(f),filesep),:) = [];
0263 disp(f); pause
0264 for i=1:size(f,1)
0265 spm_unlink(deblank(f(i,:)));
0266 end