Home > . > prt_latex_cfg.m

prt_latex_cfg

PURPOSE ^

SYNOPSIS ^

function prt_latex_cfg(c)

DESCRIPTION ^

 Convert a job configuration tree into a series of LaTeX documents.
 Only generate .tex files for each exec_branch of prt_batch. These files
 are then included in a manually written prt_manual.tex file, which also
 includes chapter/sections written manually.

 File derived from that of the SPM8 distribution.
 http://www.fil.ion.ucl.ac.uk/spm
_______________________________________________________________________
 Copyright (C) 2011 Machine Learning & Neuroimaging Laboratory

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function prt_latex_cfg(c)
0002 %
0003 % Convert a job configuration tree into a series of LaTeX documents.
0004 % Only generate .tex files for each exec_branch of prt_batch. These files
0005 % are then included in a manually written prt_manual.tex file, which also
0006 % includes chapter/sections written manually.
0007 %
0008 % File derived from that of the SPM8 distribution.
0009 % http://www.fil.ion.ucl.ac.uk/spm
0010 %_______________________________________________________________________
0011 % Copyright (C) 2011 Machine Learning & Neuroimaging Laboratory
0012 
0013 % John Ashburner & Christophe Phillips
0014 % $Id: prt_latex_cfg.m 173 2011-10-19 17:13:43Z cphillip $
0015 
0016 if ~nargin,
0017     c = prt_cfg_batch;
0018 end
0019 if nargin && ischar(c),
0020     clean_latex_compile;
0021     return;
0022 end
0023 
0024 for i=1:numel(c.values),
0025     chapter(c.values{i});
0026 end;
0027 
0028 return;
0029 
0030 %==========================================================================
0031 function sts = chapter(c)
0032 bn = c.tag;
0033 fp = fopen(fullfile(prt('dir'),'manual',['batch_',bn,'.tex']),'w');
0034 if fp==-1, sts = false; return; end;
0035 
0036 % $Id: prt_latex_cfg.m 173 2011-10-19 17:13:43Z cphillip $
0037 
0038 fprintf(fp,'%% $Id: prt_latex_cfg.m 173 2011-10-19 17:13:43Z cphillip $ \n\n');
0039 fprintf(fp, ...
0040     '\\chapter{%s  \\label{Chap:%s}}\n\\minitoc\n\n\\vskip 1.5cm\n\n', ...
0041     texify(c.name),c.tag);
0042 write_help(c,fp);
0043 
0044 switch class(c),
0045     case {'cfg_branch','cfg_exbranch'},
0046         for i=1:numel(c.val),
0047             section(c.val{i},fp);
0048         end;
0049     case {'cfg_repeat','cfg_choice'},
0050         for i=1:numel(c.values),
0051             section(c.values{i},fp);
0052         end;
0053 end;
0054 fclose(fp);
0055 sts = true;
0056 return;
0057 
0058 %==========================================================================
0059 function section(c,fp,lev)
0060 if nargin<3, lev = 1; end;
0061 sec = {'section','subsection','subsubsection','paragraph','subparagraph', ...
0062             'textbf','textsc','textsl','textit'};
0063 % if lev<=length(sec),
0064     fprintf(fp,'\n\\%s{%s}\n',sec{min(lev,length(sec))},texify(c.name));
0065     write_help(c,fp);
0066     switch class(c),
0067         case {'cfg_branch','cfg_exbranch'},
0068             for i=1:numel(c.val),
0069                 section(c.val{i},fp,lev+1);
0070             end;
0071         case {'cfg_repeat','cfg_choice'},
0072             for i=1:numel(c.values),
0073                 section(c.values{i},fp,lev+1);
0074             end;
0075     end;
0076 % else
0077 if lev>length(sec),
0078     warning(['Too many nested levels... ',c.name]); %#ok<WNTAG>
0079 end;
0080 return;
0081 
0082 %==========================================================================
0083 function write_help(hlp,fp)
0084 if isa(hlp, 'cfg_item'),
0085     if ~isempty(hlp.help),
0086         hlp = hlp.help;
0087     else
0088         return;
0089     end;
0090 end;
0091 if iscell(hlp),
0092     for i=1:numel(hlp),
0093         write_help(hlp{i},fp);
0094     end;
0095     return;
0096 end;
0097 str = texify(hlp);
0098 fprintf(fp,'%s\n\n',str);
0099 return;
0100 
0101 %==========================================================================
0102 function str = texify(str0)
0103 st1  = strfind(str0,'/*');
0104 en1  = strfind(str0,'*/');
0105 st = [];
0106 en = [];
0107 for i=1:numel(st1),
0108     en1  = en1(en1>st1(i));
0109     if ~isempty(en1),
0110         st  = [st st1(i)];
0111         en  = [en en1(1)];
0112         en1 = en1(2:end);
0113     end;
0114 end;
0115 
0116 str = [];
0117 pen = 1;
0118 for i=1:numel(st),
0119     str = [str clean_latex(str0(pen:st(i)-1)) str0(st(i)+2:en(i)-1)];
0120     pen = en(i)+2;
0121 end;
0122 str = [str clean_latex(str0(pen:numel(str0)))];
0123 return;
0124 
0125 %==========================================================================
0126 function str = clean_latex(str)
0127 str  = strrep(str,'$','\$');
0128 str  = strrep(str,'&','\&');
0129 str  = strrep(str,'^','\^');
0130 str  = strrep(str,'_','\_');
0131 str  = strrep(str,'#','\#');
0132 %str  = strrep(str,'\','$\\$');
0133 str  = strrep(str,'|','$|$');
0134 str  = strrep(str,'>','$>$');
0135 str  = strrep(str,'<','$<$');
0136 return;
0137 
0138 %==========================================================================
0139 function bibcstr = get_bib(bibdir)
0140 biblist = dir(fullfile(bibdir,'*.bib'));
0141 bibcstr={};
0142 for k = 1:numel(biblist)
0143     [p n e v] = spm_fileparts(biblist(k).name);
0144     bibcstr{k}  = fullfile(bibdir,n);
0145 end
0146 
0147 %==========================================================================
0148 function clean_latex_compile
0149 PRTdir = prt('dir');
0150 p = fullfile(PRTdir,'manual');
0151 [f, d] = spm_select('FPlist',p,'.*\.aux$');
0152 f = strvcat(f, spm_select('FPlist',p,'.*\.tex$'));
0153 f = strvcat(f, spm_select('FPlist',p,'^manual\..*$'));
0154 f(strcmp(cellstr(f),fullfile(PRTdir,'manual','prt_manual.tex')),:) = [];
0155 f(strcmp(cellstr(f),fullfile(PRTdir,'manual','prt_manual.pdf')),:) = [];
0156 for i=1:size(d,1)
0157     f = strvcat(f, spm_select('FPlist',deblank(d(i,:)),'.*\.aux$'));
0158 end
0159 f(strcmp(cellstr(f),filesep),:) = [];
0160 disp(f); pause
0161 for i=1:size(f,1)
0162     spm_unlink(deblank(f(i,:)));
0163 end

Generated on Thu 20-Oct-2011 11:56:23 by m2html © 2005