comparison m-toolbox/m/helper/generateModelTechNote.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 function generateModelTechNote(modelname)
2
3 % Header
4 txt = docHeader(modelname);
5
6 % Description and Documentation
7 txt = [txt writeIntroduction(modelname)];
8
9 % Versions
10 txt = [txt writeVersionTable(modelname)];
11
12 % Write each version section
13 txt = [txt writeVersionSections(modelname)];
14
15 % Footer
16 txt = [txt docFooter(modelname)];
17
18 % write file
19 fd = fopen([modelname '.tex'], 'w+');
20 fprintf(fd, strrep(strrep(txt, '\', '\\'), '%', '%%'));
21 fclose(fd);
22
23 % compile
24 % cmd = sprintf('/usr/texbin/pdflatex %s', modelname);
25 % [status, result] = system(cmd)
26
27 edit([modelname '.tex'])
28
29 end
30
31 % Models are documented in html so we need to swap out html tags and
32 % replace them by appropriate LaTeX tags. One replacement per line, please,
33 % and remember to include replacements for closing tags. This is assuming
34 % that all html tags have associated closing tags.
35 function map = tagmap()
36
37 map = {...
38 '<p>', '', ...
39 '</p>', '', ...
40 '<br>', '\newline', ...
41 '<tt>', '$', ...
42 '</tt>', '$', ...
43 };
44
45 end
46
47
48 function txt = docHeader(modelname)
49
50 ename = strrep(modelname, '_', '\_');
51
52
53 txt = sprintf('\\documentclass[11pt]{article}\n');
54 txt = [txt sprintf('\\usepackage{ifpdf}\n')];
55 txt = [txt sprintf('\\ifpdf\n')];
56 txt = [txt sprintf(' \\usepackage[pdftex]{graphicx} %% to include graphics\n')];
57 txt = [txt sprintf(' \\pdfcompresslevel=9 \n')];
58 txt = [txt sprintf(' \\usepackage[pdftex, %% sets up hyperref to use pdftex driver\n')];
59 txt = [txt sprintf(' plainpages=false, %% allows page i and 1 to exist in the same document\n')];
60 txt = [txt sprintf(' breaklinks=true, %% link texts can be broken at the end of line\n')];
61 txt = [txt sprintf(' colorlinks=true,\n')];
62 txt = [txt sprintf(' pdftitle=%s,\n', ename)];
63 txt = [txt sprintf(' pdfauthor=LTPDA\n')];
64 txt = [txt sprintf(' ]{hyperref} \n')];
65 txt = [txt sprintf(' \\usepackage{thumbpdf}\n')];
66 txt = [txt sprintf('\\else \n')];
67 txt = [txt sprintf(' \\usepackage{graphicx} %% to include graphics\n')];
68 txt = [txt sprintf(' \\usepackage{hyperref} %% to simplify the use of \\href\n')];
69 txt = [txt sprintf('\\fi \n')];
70
71 txt = [txt sprintf('\\title{Technical Report of LTPDA built-in model \\texttt{%s}}\n', ename)];
72 txt = [txt sprintf('\\author{LTPDA (%s)}\n', getappdata(0, 'ltpda_version'))];
73
74 txt = [txt sprintf('\\begin{document}\n')];
75 txt = [txt sprintf('\\maketitle\n')];
76
77 end
78
79
80 function txt = docFooter(modelname)
81 txt = sprintf('\\end{document} %% End of %s\n', modelname);
82 end
83
84 function txt = writeVersionSections(modelname)
85
86 versionTable = feval(modelname, 'versionTable');
87 vers = versionTable(1:2:end);
88 fcns = versionTable(2:2:end);
89 Nvers = numel(vers);
90 txt = '';
91 for kk=1:Nvers
92
93 v = vers{kk};
94 vtag = strrep(v, ' ', '');
95 fcn = fcns{kk};
96
97 txt = [txt sprintf('\\clearpage\n\n')];
98 txt = [txt sprintf('\\section{Version `%s''}\n', v)];
99 txt = [txt sprintf('\\label{ref:%s}\n', vtag)];
100
101 txt = [txt sprintf('\n\n')];
102 txt = [txt writeSectionForVersion(modelname, v, fcn)];
103
104 txt = [txt writeSubmodelSectionForVersion(modelname, v)];
105 txt = [txt sprintf('\n\n')];
106
107 end
108
109 txt = [txt sprintf('\n\n')];
110
111
112 end
113
114 function txt = writeSubmodelSectionForVersion(modelname, v)
115
116 ii = feval(modelname, 'info', v);
117
118 ciis = ii.children;
119 txt = '';
120 if numel(ciis) > 0
121
122 label = strrep(sprintf('tab:submodels_%s_%s', modelname, strrep(v, ' ', '')), '_', '');
123 txt = [txt sprintf('\\subsection{Sub-models}\n')];
124 txt = [txt sprintf('Sub-models used in this version are shown in Table \\ref{%s}.\n', label)];
125 txt = [txt sprintf('\\begin{table}[htdp]\n')];
126 txt = [txt sprintf('\\begin{center}\n')];
127 txt = [txt sprintf('\\begin{tabular}{|c|c|p{4cm}|l|} \\hline\n')];
128
129 txt = [txt sprintf('Sub-model & Description \\\\ \\hline\\hline \n')];
130 for kk=1:numel(ciis)
131 cii = ciis(kk);
132 name = strrep(cii.mname, '_', '\_');
133 txt = [txt sprintf('%s & %s \\\\ \\hline\n', name, cii.description)];
134
135 end
136
137 % table footer
138 txt = [txt sprintf('\\end{tabular}\n')];
139 txt = [txt sprintf('\\end{center}\n')];
140 txt = [txt sprintf('\\caption{Sub-models}\n')];
141 txt = [txt sprintf('\\label{%s}\n', label)];
142 txt = [txt sprintf('\\end{table}\n')];
143
144
145 end
146 end
147
148 function txt = writeSectionForVersion(modelname, v, fcn)
149
150 txt = '';
151
152 % Description
153 desc = fcn('description');
154 desc = replaceTags(desc);
155 txt = [txt sprintf('\\subsection{Description}\n')];
156 txt = [txt sprintf('%s\n', desc)];
157 txt = [txt sprintf('\n\n')];
158
159 % Plist for version
160 txt = [txt sprintf('\\subsection{Parameter List}\n')];
161 label = strrep(sprintf('tab:plist_%s_%s', modelname, strrep(v, ' ', '')), '_', '');
162 txt = [txt sprintf('Parameters used in this version are shown in Table \\ref{%s}.\n', label)];
163 pl = feval(modelname, 'plist');
164
165 txt = [txt plistTable(pl, label)];
166
167 txt = [txt sprintf('\n\n')];
168
169 end
170
171 function txt = plistTable(pl, label)
172
173 txt = '';
174 txt = [txt sprintf('\\begin{table}[htdp]\n')];
175 txt = [txt sprintf('\\begin{center}\n')];
176 txt = [txt sprintf('\\begin{tabular}{|c|p{4cm}|p{4cm}|p{4cm}|} \\hline\n')];
177
178 txt = [txt sprintf('Key & Default Value & Options & Description \\\\ \\hline\\hline \n')];
179 for kk=1:pl.nparams
180
181 txt = [txt sprintf('%s & ', pl.params(kk).key)];
182 ptxt = display(pl.params(kk));
183 txt = [txt sprintf('%s & ', strtrim(strrep(ptxt{3}, 'val:', '')))];
184 if numel(pl.params(kk).getOptions) > 1
185 opts = pl.params(kk).getOptions;
186 optlist = sprintf('\\begin{itemize} ');
187 for oo=1:numel(opts)
188 optlist = [optlist sprintf('\\item %s ', utils.helper.val2str(opts{oo}))];
189 end
190 optlist = [optlist sprintf('\\end{itemize}')];
191 txt = [txt sprintf('%s & ', optlist)];
192 else
193 txt = [txt sprintf('\\textit{none} & ')];
194 end
195 desc = char(strrep(pl.params(kk).desc, '\n', '\\newline\\newline'));
196 if isempty(desc)
197 desc = '\textit{no description}';
198 end
199 txt = [txt sprintf('%s ', desc)];
200 txt = [txt sprintf(' \\\\ \\hline \n')];
201
202
203 end
204
205 % table footer
206 txt = [txt sprintf('\\end{tabular}\n')];
207 txt = [txt sprintf('\\end{center}\n')];
208 txt = [txt sprintf('\\caption{Parameter list}\n')];
209 txt = [txt sprintf('\\label{%s}\n', label)];
210 txt = [txt sprintf('\\end{table}\n')];
211
212
213 end
214
215 function txt = writeVersionTable(modelname)
216
217 ename = strrep(modelname, '_', '\_');
218
219 % table header
220 txt = '';
221 txt = [txt sprintf('\\subsection{Versions}\n')];
222 txt = [txt sprintf('\\begin{table}[htdp]\n')];
223 txt = [txt sprintf('\\begin{center}\n')];
224 txt = [txt sprintf('\\begin{tabular}{|c|c|} \\hline\n')];
225
226 versionTable = feval(modelname, 'versionTable');
227 vers = versionTable(1:2:end);
228 fcns = versionTable(2:2:end);
229 Nvers = numel(vers);
230 txt = [txt sprintf('Version & Description \\\\ \\hline\\hline \n')];
231 for kk=1:Nvers
232
233 v = vers{kk};
234 vtag = strrep(v, ' ', '');
235 fcn = fcns{kk};
236
237 txt = [txt sprintf('\\hyperref[ref:%s]{%s} & %s \\\\ \\hline \n', vtag, v, fcn('description'))];
238
239 end
240
241 % table footer
242 txt = [txt sprintf('\\end{tabular}\n')];
243 txt = [txt sprintf('\\end{center}\n')];
244 txt = [txt sprintf('\\caption{Versions for model %s}\n', ename)];
245 txt = [txt sprintf('\\label{versions:\texttt{%s}}\n', modelname)];
246 txt = [txt sprintf('\\end{table}\n')];
247
248 end
249
250 function txt = writeIntroduction(modelname)
251
252 % section
253 txt = sprintf('\\section{Overview}\n');
254
255 % description
256 desc = feval(modelname, 'description');
257 desc = replaceTags(desc);
258 txt = [txt sprintf('\\subsection{Description}\n\n')];
259 txt = [txt sprintf('%s\n\n\n', desc)];
260
261 % Documentation
262 doc = feval(modelname, 'doc');
263 doc = replaceTags(doc);
264 txt = [txt sprintf('\\subsection{Details}\n\n')];
265 txt = [txt sprintf('%s\n\n\n', doc)];
266
267
268 end
269
270 function txt = replaceTags(txt)
271
272 tm = tagmap();
273 tags = tm(1:2:end);
274 reps = tm(2:2:end);
275
276 for kk=1:numel(tags)
277 txt = strrep(txt, tags{kk}, reps{kk});
278 end
279
280 end
281
282
283
284
285
286