Create TOC

closes #12
parent a41c1c02
Pipeline #2489 passed with stage
in 1 minute and 20 seconds
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*.out *.out
*.tex *.tex
*.csv *.csv
*.toc
*synctex.gz *synctex.gz
.DS_Store .DS_Store
test/tmpRepDir test/tmpRepDir
...@@ -63,6 +63,9 @@ if ~isempty(o.latex) ...@@ -63,6 +63,9 @@ if ~isempty(o.latex)
end end
fprintf(fid, '\\input{%s}', pagename); fprintf(fid, '\\input{%s}', pagename);
else else
if ~isempty(o.title)
fprintf(fid, '\\addcontentsline{toc}{subsection}{%s}\n', o.title{1});
end
fprintf(fid, '\\begin{tabular}[t]{c}\n'); fprintf(fid, '\\begin{tabular}[t]{c}\n');
for i = 1:length(o.title) for i = 1:length(o.title)
if isint(o.titleTruncate) if isint(o.titleTruncate)
......
...@@ -93,23 +93,18 @@ end ...@@ -93,23 +93,18 @@ end
orig_dir = pwd; orig_dir = pwd;
cd(o.directory) cd(o.directory)
options = '-synctex=1 -halt-on-error'; options = '-synctex=1 -halt-on-error';
if opts.showOutput [~, rfn] = fileparts(o.fileName);
if isoctave if ~isempty(o.maketoc)
system([opts.compiler ' ' options middle o.fileName]); % TOC compilation requires two passes
status = 0; compile_tex(o, orig_dir, opts, [options ' -draftmode'], middle);
else
status = system([opts.compiler ' ' options middle o.fileName], '-echo');
end
else
[status, ~] = system([opts.compiler ' -interaction=batchmode ' options middle o.fileName]);
end end
[~, rfn, ~] = fileparts(o.fileName);
if status ~= 0 if status ~= 0
cd(orig_dir) cd(orig_dir)
error(['@report.compile: There was an error in compiling ' rfn '.pdf.' ... error(['@report.compile: There was an error in compiling ' rfn '.pdf.' ...
' ' opts.compiler ' returned the error code: ' num2str(status)]); ' ' opts.compiler ' returned the error code: ' num2str(status)]);
end end
compile_tex(o, orig_dir, opts, options, middle);
if o.showOutput || opts.showOutput if o.showOutput || opts.showOutput
fprintf('Done.\n\nYour compiled report is located here:\n %s.pdf\n\n\n', [pwd '/' rfn]) fprintf('Done.\n\nYour compiled report is located here:\n %s.pdf\n\n\n', [pwd '/' rfn])
end end
...@@ -118,3 +113,22 @@ if opts.showReport && ~isoctave ...@@ -118,3 +113,22 @@ if opts.showReport && ~isoctave
end end
cd(orig_dir) cd(orig_dir)
end 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
\ No newline at end of file
...@@ -33,6 +33,7 @@ classdef report < handle ...@@ -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. 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. 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. 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 end
methods methods
function o = report(varargin) function o = report(varargin)
...@@ -99,6 +100,7 @@ classdef report < handle ...@@ -99,6 +100,7 @@ classdef report < handle
valid_orientation = {'portrait', 'landscape'}; valid_orientation = {'portrait', 'landscape'};
assert(any(strcmp(o.orientation, valid_orientation)), ... assert(any(strcmp(o.orientation, valid_orientation)), ...
['@report.report: orientation must be one of ' addCommasToCellStr(valid_orientation)]); ['@report.report: orientation must be one of ' addCommasToCellStr(valid_orientation)]);
assert(islogical(o.maketoc), '@report.report: maketock must be logical');
end end
o = addPage(o, varargin) o = addPage(o, varargin)
o = addSection(o, varargin) o = addSection(o, varargin)
......
...@@ -53,7 +53,7 @@ if fid_preamble == -1 ...@@ -53,7 +53,7 @@ if fid_preamble == -1
end end
fprintf(fid_preamble, '%% Report Object written %s\n', datestr(now)); 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); fprintf(fid_preamble, '\\usepackage[%spaper,margin=%f%s', o.paper, o.margin, o.marginUnit);
if strcmpi(o.orientation, 'landscape') if strcmpi(o.orientation, 'landscape')
...@@ -83,6 +83,7 @@ if o.showDate ...@@ -83,6 +83,7 @@ if o.showDate
fprintf(fid_preamble, '\\renewcommand{\\footrulewidth}{0.5pt}\n'); fprintf(fid_preamble, '\\renewcommand{\\footrulewidth}{0.5pt}\n');
fprintf(fid_preamble, '\\rfoot{\\scriptsize\\reportdate\\today\\ -- \\currenttime}\n'); fprintf(fid_preamble, '\\rfoot{\\scriptsize\\reportdate\\today\\ -- \\currenttime}\n');
end end
fprintf(fid_preamble, '\\rhead{}\n\\lhead{}\n');
% May not need these..... % May not need these.....
fprintf(fid_preamble, '\\renewcommand{\\textfraction}{0.05}\n'); fprintf(fid_preamble, '\\renewcommand{\\textfraction}{0.05}\n');
...@@ -94,11 +95,6 @@ fprintf(fid_preamble, '\\newlength\\sectionheight\n'); ...@@ -94,11 +95,6 @@ fprintf(fid_preamble, '\\newlength\\sectionheight\n');
if ~isempty(o.header) if ~isempty(o.header)
fprintf(fid_preamble, '%s\n', o.header); fprintf(fid_preamble, '%s\n', o.header);
end 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 %% Write body of document
[fid_document, msg] = fopen([o.directory '/' document_file_name], 'w'); [fid_document, msg] = fopen([o.directory '/' document_file_name], 'w');
...@@ -107,10 +103,16 @@ if fid_document == -1 ...@@ -107,10 +103,16 @@ if fid_document == -1
end end
if ~isempty(o.title) if ~isempty(o.title)
fprintf(fid_document, ['\\begin{titlepage}\n\\centering\n' ... fprintf(fid_preamble, '\\newdateformat{reportdatelong}{\\THEDAY\\ \\monthname\\ \\THEYEAR}\n');
'\\vspace*{0.5cm}\n\\huge\\bfseries\n%s\n' ... fprintf(fid_document, '\\title{\\huge\\bfseries %s\\vspace{-1em}}\n\\author{}\n\\date{\\reportdatelong\\today}\n\\maketitle\n', o.title);
'\\vspace*{\\fill}\n\\end{titlepage}\n\\clearpage\n'], ... end
o.title);
if o.maketoc
fprintf(fid_document, '\\tableofcontents\n');
end
if ~isempty(o.title) || o.maketoc
fprintf(fid_document, '\\clearpage\n');
end end
if isunix && ~ismac if isunix && ~ismac
...@@ -137,6 +139,14 @@ for i = 1:length(o.pages) ...@@ -137,6 +139,14 @@ for i = 1:length(o.pages)
end end
fprintf(fid_document, '\\input{%s}\n', page_file_name); fprintf(fid_document, '\\input{%s}\n', page_file_name);
end 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); status = fclose(fid_document);
if status == -1 if status == -1
error('@report.write: closing %s\n', document_file_name); error('@report.write: closing %s\n', document_file_name);
......
...@@ -34,8 +34,8 @@ longNames = {'Coca Cola', 'Kinder Bueno', 'Pizza', ... ...@@ -34,8 +34,8 @@ longNames = {'Coca Cola', 'Kinder Bueno', 'Pizza', ...
'Vegetarianism Is Good', 'OS X', 'Dothraki'}; 'Vegetarianism Is Good', 'OS X', 'Dothraki'};
%% Begin Report %% 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 %% Page 1: GDP
rep.addPage('title', 'Jan1 vs Jan2', ... rep.addPage('title', 'Jan1 vs Jan2', ...
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment