parent
0c1569db72
commit
cd483463b5
|
@ -6,6 +6,7 @@
|
|||
*.out
|
||||
*.tex
|
||||
*.csv
|
||||
*.toc
|
||||
*synctex.gz
|
||||
.DS_Store
|
||||
test/tmpRepDir
|
||||
|
|
|
@ -63,6 +63,9 @@ if ~isempty(o.latex)
|
|||
end
|
||||
fprintf(fid, '\\input{%s}', pagename);
|
||||
else
|
||||
if ~isempty(o.title)
|
||||
fprintf(fid, '\\addcontentsline{toc}{subsection}{%s}\n', o.title{1});
|
||||
end
|
||||
fprintf(fid, '\\begin{tabular}[t]{c}\n');
|
||||
for i = 1:length(o.title)
|
||||
if isint(o.titleTruncate)
|
||||
|
|
|
@ -93,23 +93,18 @@ end
|
|||
orig_dir = pwd;
|
||||
cd(o.directory)
|
||||
options = '-synctex=1 -halt-on-error';
|
||||
if opts.showOutput
|
||||
if isoctave
|
||||
system([opts.compiler ' ' options middle o.fileName]);
|
||||
status = 0;
|
||||
else
|
||||
status = system([opts.compiler ' ' options middle o.fileName], '-echo');
|
||||
end
|
||||
else
|
||||
[status, ~] = system([opts.compiler ' -interaction=batchmode ' options middle o.fileName]);
|
||||
[~, rfn] = fileparts(o.fileName);
|
||||
if ~isempty(o.maketoc)
|
||||
% TOC compilation requires two passes
|
||||
compile_tex(o, orig_dir, opts, [options ' -draftmode'], middle);
|
||||
end
|
||||
[~, rfn, ~] = fileparts(o.fileName);
|
||||
|
||||
if status ~= 0
|
||||
cd(orig_dir)
|
||||
error(['@report.compile: There was an error in compiling ' rfn '.pdf.' ...
|
||||
' ' opts.compiler ' returned the error code: ' num2str(status)]);
|
||||
end
|
||||
compile_tex(o, orig_dir, opts, options, middle);
|
||||
|
||||
if o.showOutput || opts.showOutput
|
||||
fprintf('Done.\n\nYour compiled report is located here:\n %s.pdf\n\n\n', [pwd '/' rfn])
|
||||
end
|
||||
|
@ -118,3 +113,22 @@ if opts.showReport && ~isoctave
|
|||
end
|
||||
cd(orig_dir)
|
||||
end
|
||||
|
||||
function compile_tex(o, orig_dir, opts, options, middle)
|
||||
if opts.showOutput
|
||||
if isoctave
|
||||
system([opts.compiler ' ' options middle o.fileName]);
|
||||
status = 0;
|
||||
else
|
||||
status = system([opts.compiler ' ' options middle o.fileName], '-echo');
|
||||
end
|
||||
else
|
||||
status = system([opts.compiler ' -interaction=batchmode ' options middle o.fileName]);
|
||||
end
|
||||
|
||||
if status ~= 0
|
||||
cd(orig_dir)
|
||||
error(['@report.compile: There was an error in compiling ' rfn '.pdf.' ...
|
||||
' ' opts.compiler ' returned the error code: ' num2str(status)]);
|
||||
end
|
||||
end
|
|
@ -33,6 +33,7 @@ classdef report < handle
|
|||
showOutput = true % Print report creation progress to screen. Shows you the page number as it is created and as it is written. This is useful to see where a potential error occurs in report creation. Default: true.
|
||||
header = '' % The valid LATEX code to be included in the report before \begin{document}. Default: empty.
|
||||
reportDirName = 'tmpRepDir' % The name of the folder in which to store the component parts of the report (preamble, document, end). Default: tmpRepDir.
|
||||
maketoc = false % Whether or not to make a table of contents
|
||||
end
|
||||
methods
|
||||
function o = report(varargin)
|
||||
|
@ -99,6 +100,7 @@ classdef report < handle
|
|||
valid_orientation = {'portrait', 'landscape'};
|
||||
assert(any(strcmp(o.orientation, valid_orientation)), ...
|
||||
['@report.report: orientation must be one of ' addCommasToCellStr(valid_orientation)]);
|
||||
assert(islogical(o.maketoc), '@report.report: maketock must be logical');
|
||||
end
|
||||
o = addPage(o, varargin)
|
||||
o = addSection(o, varargin)
|
||||
|
|
|
@ -53,7 +53,7 @@ if fid_preamble == -1
|
|||
end
|
||||
|
||||
fprintf(fid_preamble, '%% Report Object written %s\n', datestr(now));
|
||||
fprintf(fid_preamble, '\\documentclass[11pt]{article}\n');
|
||||
fprintf(fid_preamble, '\\documentclass[11pt,notitlepage]{article}\n');
|
||||
|
||||
fprintf(fid_preamble, '\\usepackage[%spaper,margin=%f%s', o.paper, o.margin, o.marginUnit);
|
||||
if strcmpi(o.orientation, 'landscape')
|
||||
|
@ -83,6 +83,7 @@ if o.showDate
|
|||
fprintf(fid_preamble, '\\renewcommand{\\footrulewidth}{0.5pt}\n');
|
||||
fprintf(fid_preamble, '\\rfoot{\\scriptsize\\reportdate\\today\\ -- \\currenttime}\n');
|
||||
end
|
||||
fprintf(fid_preamble, '\\rhead{}\n\\lhead{}\n');
|
||||
|
||||
% May not need these.....
|
||||
fprintf(fid_preamble, '\\renewcommand{\\textfraction}{0.05}\n');
|
||||
|
@ -94,11 +95,6 @@ fprintf(fid_preamble, '\\newlength\\sectionheight\n');
|
|||
if ~isempty(o.header)
|
||||
fprintf(fid_preamble, '%s\n', o.header);
|
||||
end
|
||||
fprintf(fid_preamble, '\\begin{document}\n');
|
||||
status = fclose(fid_preamble);
|
||||
if status == -1
|
||||
error('@report.write: closing %s\n', preamble_file_name);
|
||||
end
|
||||
|
||||
%% Write body of document
|
||||
[fid_document, msg] = fopen([o.directory '/' document_file_name], 'w');
|
||||
|
@ -107,10 +103,16 @@ if fid_document == -1
|
|||
end
|
||||
|
||||
if ~isempty(o.title)
|
||||
fprintf(fid_document, ['\\begin{titlepage}\n\\centering\n' ...
|
||||
'\\vspace*{0.5cm}\n\\huge\\bfseries\n%s\n' ...
|
||||
'\\vspace*{\\fill}\n\\end{titlepage}\n\\clearpage\n'], ...
|
||||
o.title);
|
||||
fprintf(fid_preamble, '\\newdateformat{reportdatelong}{\\THEDAY\\ \\monthname\\ \\THEYEAR}\n');
|
||||
fprintf(fid_document, '\\title{\\huge\\bfseries %s\\vspace{-1em}}\n\\author{}\n\\date{\\reportdatelong\\today}\n\\maketitle\n', o.title);
|
||||
end
|
||||
|
||||
if o.maketoc
|
||||
fprintf(fid_document, '\\tableofcontents\n');
|
||||
end
|
||||
|
||||
if ~isempty(o.title) || o.maketoc
|
||||
fprintf(fid_document, '\\clearpage\n');
|
||||
end
|
||||
|
||||
if isunix && ~ismac
|
||||
|
@ -137,6 +139,14 @@ for i = 1:length(o.pages)
|
|||
end
|
||||
fprintf(fid_document, '\\input{%s}\n', page_file_name);
|
||||
end
|
||||
|
||||
%% Close preamble, document
|
||||
fprintf(fid_preamble, '\\begin{document}\n');
|
||||
status = fclose(fid_preamble);
|
||||
if status == -1
|
||||
error('@report.write: closing %s\n', preamble_file_name);
|
||||
end
|
||||
|
||||
status = fclose(fid_document);
|
||||
if status == -1
|
||||
error('@report.write: closing %s\n', document_file_name);
|
||||
|
|
|
@ -34,8 +34,8 @@ longNames = {'Coca Cola', 'Kinder Bueno', 'Pizza', ...
|
|||
'Vegetarianism Is Good', 'OS X', 'Dothraki'};
|
||||
|
||||
%% Begin Report
|
||||
rep = report('directory', 'my/report/dir', 'title', 'Report Title');
|
||||
|
||||
rep = report('directory', 'my/report/dir', 'title', 'Report Title', ...
|
||||
'maketoc', true);
|
||||
|
||||
%% Page 1: GDP
|
||||
rep.addPage('title', 'Jan1 vs Jan2', ...
|
||||
|
|
Loading…
Reference in New Issue