reporting: @page: allow for multiple titles, title_format, first args can be provided as strings or cellstr, multiple args as cellstr

time-shift
Houtan Bastani 2013-03-19 11:57:20 +01:00
parent ea56c41b68
commit b7969980d0
2 changed files with 30 additions and 19 deletions

View File

@ -31,9 +31,10 @@ function o = page(varargin)
o = struct;
o.paper = '';
o.title = '';
o.title = {};
o.title_format = {};
o.orientation = '';
o.footnote = '';
o.footnote = {};
o.sections = sections();
if nargin == 1
@ -61,7 +62,18 @@ elseif nargin > 1
end
% Check options provided by user
assert(ischar(o.title), '@page.page: title must be a string');
if ischar(o.title)
o.title = {o.title}
end
if ischar(o.title_format)
o.title_format = {o.title_format}
end
assert(iscellstr(o.title), ...
'@page.page: title must be a cell array of strings');
assert(iscellstr(o.title_format), ...
'@page.page: title_format must be a cell array of strings');
assert(length(o.title)==length(o.title_format), ...
'@page.page: title and title_format must be of the same length');
valid_paper = {'a4', 'letter'};
assert(any(strcmp(o.paper, valid_paper)), ...
@ -71,13 +83,11 @@ valid_orientation = {'portrait', 'landscape'};
assert(any(strcmp(o.orientation, valid_orientation)), ...
['@page.page: orientation must be one of ' strjoin(valid_orientation, ' ')]);
msg = ['@page.page: footnote must be a cell array of string(s)'];
if ~isempty(o.footnote)
assert(iscell(o.footnote), msg);
for i=1:length(o.footnote)
assert(ischar(o.footnote{i}), msg);
end
if ischar(o.footnote)
o.footnote = {o.footnote}
end
assert(iscellstr(o.footnote), ...
'@page.page: footnote must be a cell array of string(s)');
% Create page object
o = class(o, 'page');

View File

@ -31,25 +31,26 @@ function o = write(o, fid)
assert(fid ~= -1);
fprintf(fid, '\n%% Page Object\n');
if ~isempty(o.title)
fprintf(fid, '\\centerline{\\large\\textbf{%s}}\n', o.title);
end
if ~isempty(o.footnote)
for i=1:length(o.footnote)
fprintf(fid, '\\blfootnote{\\tiny %d. %s}', i, o.footnote{i});
end
end
if strcmpi(o.orientation, 'landscape')
fprintf(fid, '\\begin{landscape}\n')
end
for i=1:length(o.footnote)
fprintf(fid, '\\blfootnote{\\tiny %d. %s}', i, o.footnote{i});
end
fprintf(fid,'\n');
fprintf(fid, '\\begin{tabular}[t]{@{\\hspace*{-3pt}}c@{}}\n');
for i=1:length(o.title)
fprintf(fid,'\\multicolumn{1}{c}{%s %s}\\\\\n', o.title_format{i}, o.title{i});
end
o.sections.write(fid);
if strcmpi(o.orientation, 'landscape')
fprintf(fid, '\\end{landscape}\n');
end
fprintf(fid, '\\end{tabular}\n');
fprintf(fid, '\\clearpage\n');
fprintf(fid, '%% End Page Object\n\n');
end