From 1c371389df35dc6a40f1d23af9cce812d5b8ba67 Mon Sep 17 00:00:00 2001
From: Houtan Bastani <houtan@dynare.org>
Date: Tue, 19 Feb 2013 15:48:47 +0100
Subject: [PATCH] reporting (WIP)

---
 matlab/reporting/@elements/addGraph.m   |   7 +-
 matlab/reporting/@elements/addTable.m   |   7 +-
 matlab/reporting/@graph/createGraph.m   | 107 ++++++++++++++++++++++++
 matlab/reporting/@graph/display.m       |  43 +++++++++-
 matlab/reporting/@graph/graph.m         |  19 ++++-
 matlab/reporting/@graph/write.m         |  24 +++---
 matlab/reporting/@page/addSection.m     |   7 +-
 matlab/reporting/@page/page.m           |   7 +-
 matlab/reporting/@page/subsref.m        |   7 --
 matlab/reporting/@page/write.m          |  24 +++---
 matlab/reporting/@pages/addPage.m       |  13 +--
 matlab/reporting/@pages/subsref.m       |   7 --
 matlab/reporting/@pages/write.m         |  13 ++-
 matlab/reporting/@report/addPage.m      |  33 ++++----
 matlab/reporting/@report/report.m       |   1 +
 matlab/reporting/@report/subsref.m      |   7 --
 matlab/reporting/@report/write.m        |  16 ++--
 matlab/reporting/@section/addGraph.m    |   7 +-
 matlab/reporting/@section/addTable.m    |   7 +-
 matlab/reporting/@section/display.m     |   6 +-
 matlab/reporting/@section/section.m     |   3 -
 matlab/reporting/@section/subsref.m     |   9 +-
 matlab/reporting/@section/write.m       |  33 ++++++--
 matlab/reporting/@sections/addSection.m |  12 +--
 matlab/reporting/@sections/subsref.m    |   7 --
 matlab/reporting/@sections/write.m      |  13 ++-
 matlab/reporting/@table/write.m         |  17 ++--
 matlab/reporting/addIndentation.m       |  31 -------
 28 files changed, 279 insertions(+), 208 deletions(-)
 create mode 100644 matlab/reporting/@graph/createGraph.m
 delete mode 100644 matlab/reporting/addIndentation.m

diff --git a/matlab/reporting/@elements/addGraph.m b/matlab/reporting/@elements/addGraph.m
index 5149e3f1ec..ace48fc87c 100644
--- a/matlab/reporting/@elements/addGraph.m
+++ b/matlab/reporting/@elements/addGraph.m
@@ -18,10 +18,5 @@ function e = addGraph(e, varargin)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
-assert(nargin >= 1 && nargin <= 3)
-if nargin == 1
-    e.objArray = e.objArray.addObj(graph());
-else
-    e.objArray = e.objArray.addObj(varargin{:});
-end
+e.objArray = e.objArray.addObj(graph(varargin{:}));
 end
\ No newline at end of file
diff --git a/matlab/reporting/@elements/addTable.m b/matlab/reporting/@elements/addTable.m
index 6fe074dee9..afcc8e0523 100644
--- a/matlab/reporting/@elements/addTable.m
+++ b/matlab/reporting/@elements/addTable.m
@@ -18,10 +18,5 @@ function e = addTable(e, varargin)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
-assert(nargin >= 1 && nargin <= 3)
-if nargin == 1
-    e.objArray = e.objArray.addObj(table());
-else
-    e.objArray = e.objArray.addObj(varargin{:});
-end
+e.objArray = e.objArray.addObj(table(varargin{:}));
 end
\ No newline at end of file
diff --git a/matlab/reporting/@graph/createGraph.m b/matlab/reporting/@graph/createGraph.m
new file mode 100644
index 0000000000..b696a305e2
--- /dev/null
+++ b/matlab/reporting/@graph/createGraph.m
@@ -0,0 +1,107 @@
+function o = createGraph(o)
+%function o = createGraph(o)
+% Create the graph
+%
+% INPUTS
+%   none
+%
+% OUTPUTS
+%   none
+%
+% SPECIAL REQUIREMENTS
+%   none
+
+% Copyright (C) 2013 Dynare Team
+%
+% This file is part of Dynare.
+%
+% Dynare is free software: you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation, either version 3 of the License, or
+% (at your option) any later version.
+%
+% Dynare is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+% GNU General Public License for more details.
+%
+% You should have received a copy of the GNU General Public License
+% along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
+
+assert(~isempty(o.data));
+assert(isa(o.data, 'dynSeries')) ;
+
+if ~isempty(o.figname)
+    warning('Will overwrite %s with new graph\n', o.figname);
+end
+
+%o = readConfig(o);
+
+h = figure('visible','off');
+hold on;
+box on;
+%set(0, 'CurrentFigure',h);
+%set(h, 'PaperPositionMode', 'auto');
+%set(h, 'units', 'normalized', 'outerposition', [0 0 1 1]);
+
+if strcmpi(o.seriestoplot, 'all')
+    data = o.data.data;
+else
+    data = o.data{o.seriestoplot{:}}.data;
+end
+
+x=[1:1:o.data.nobs];
+xlabels=getDatesCellStringArray(o.data.time);
+
+plot(x, data);
+
+if ~isempty(o.shade)
+    x1 = strmatch(lower(o.shade{1}), xlabels, 'exact');
+    x2 = strmatch(lower(o.shade{2}), xlabels, 'exact');
+    yrange = get(gca, 'YLim');
+
+    % From ShadePlotForEmpahsis (Matlab Exchange)
+    % use patch bc area doesn't work with matlab2tikz
+    patch([repmat(x1, 1, 2) repmat(x2, 1, 2)], [yrange fliplr(yrange)], ...
+          'b', 'FaceAlpha', .2);
+end
+
+set(gca,'XTick', x);
+set(gca,'XTickLabel', xlabels);
+
+if o.legend
+    if strcmpi(o.seriestoplot, 'all')
+        lh = legend(o.data.name);
+    else
+        lh = legend(o.seriestoplot{:});
+    end
+    set(lh, 'orientation', o.legend_orientation);
+    set(lh, 'Location', o.legend_location);
+    set(lh, 'FontSize', o.legend_font_size);
+    legend('boxoff');
+end
+
+if ~isempty(o.xlabel)
+    xlabel(['$\textbf{\footnotesize ' o.xlabel '}$'],'Interpreter','LaTex');
+end
+
+if ~isempty(o.ylabel)
+    ylabel(['$\textbf{\footnotesize ' o.ylabel '}$'],'Interpreter','LaTex');
+end
+
+if ~isempty(o.title)
+    title(['$\textbf{\large ' o.title '}$'],'Interpreter','LaTex');
+end
+drawnow;
+
+o.figname = ['figure-' num2str(cputime) '.tex'];
+matlab2tikz('filename', o.figname, ...
+            'showInfo', false, ...
+            'showWarnings', false, ...
+            'checkForUpdates', false);
+
+box off;
+hold off;
+close(h);
+clear h;
+end
diff --git a/matlab/reporting/@graph/display.m b/matlab/reporting/@graph/display.m
index f9f9d82fcf..71c2b2ea25 100644
--- a/matlab/reporting/@graph/display.m
+++ b/matlab/reporting/@graph/display.m
@@ -30,9 +30,19 @@ function display(o)
 
 name = 'report.page.section.graph';
 disp(' ');
-disp([name '.caption = ']);
+disp([name '.title = ']);
 disp(' ');
-disp(['     ''' o.caption '''']);
+disp(['     ''' o.title '''']);
+
+disp(' ');
+disp([name '.xlabel = ']);
+disp(' ');
+disp(['     ''' o.xlabel '''']);
+
+disp(' ');
+disp([name '.ylabel = ']);
+disp(' ');
+disp(['     ''' o.ylabel '''']);
 
 disp(' ');
 disp([name '.footnote = ']);
@@ -40,7 +50,32 @@ disp(' ');
 disp(['     ''' o.footnote '''']);
 
 disp(' ');
-disp([name '.filename = ']);
+disp([name '.figname = ']);
+disp(' ');
+disp(['     ''' o.figname '''']);
+
+disp(' ');
+disp([name '.data = ']);
+disp(' ');
+display(o.data);
+
+disp(' ');
+disp([name '.seriestoplot = ']);
+disp(' ');
+disp(o.seriestoplot);
+
+disp(' ');
+disp([name '.config = ']);
+disp(' ');
+disp(['     ''' o.config '''']);
+
+disp(' ');
+disp([name '.legend = ']);
+disp(' ');
+disp(o.legend);
+
+disp(' ');
+disp([name '.shade = ']);
 disp(' ');
-disp(['     ''' o.filename '''']);
+disp(o.shade);
 end
\ No newline at end of file
diff --git a/matlab/reporting/@graph/graph.m b/matlab/reporting/@graph/graph.m
index 48ed3501a5..2d7d87c2ce 100644
--- a/matlab/reporting/@graph/graph.m
+++ b/matlab/reporting/@graph/graph.m
@@ -30,11 +30,24 @@ function o = graph(varargin)
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
 o = struct;
-o.caption = '';
+
+o.config = '';
+
+o.title = '';
+o.ylabel = '';
+o.xlabel = '';
+o.zlabel = '';
 o.footnote = '';
-o.filename = '';
+
+o.figname = '';
 o.data = '';
-o.config = '';
+o.seriestoplot = 'all';
+o.shade = ''; %{1959q1:1964q4}
+
+o.legend = false;
+o.legend_location = 'SouthEast';
+o.legend_orientation = 'horizontal';
+o.legend_font_size = 8;
 
 if nargin == 1
     assert(isa(varargin{1}, 'graph'),['With one arg to Graph constructor, ' ...
diff --git a/matlab/reporting/@graph/write.m b/matlab/reporting/@graph/write.m
index 4ad52ff8cf..aecf8ab08d 100644
--- a/matlab/reporting/@graph/write.m
+++ b/matlab/reporting/@graph/write.m
@@ -1,12 +1,12 @@
-function write(o, fid, texIndent)
-%function write(o, fid)
-% Write a Page object
+function o = write(o, fid)
+%function o = write(o, fid)
+% Write a Graph object
 %
 % INPUTS
-%   none
+%   fid - int, file id
 %
 % OUTPUTS
-%   none
+%   o   - this
 %
 % SPECIAL REQUIREMENTS
 %   none
@@ -28,13 +28,9 @@ function write(o, fid, texIndent)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
-assert(fid > 0);
-assert(isnumeric(texIndent));
-
-fprintf(fid, '%d\% Page Object\n', texIndent);
-fprintf(fid, '%d\newpage\n', texIndent);
-
-o.sections.write(fid, texIndent+2);
-
-fprintf(fid, '%d\% End Page Object\n', texIndent);
+assert(fid ~= -1);
+if isempty(o.figname)
+    o = createGraph(o);
+end
+fprintf(fid, '\\input{%s}', o.figname);
 end
\ No newline at end of file
diff --git a/matlab/reporting/@page/addSection.m b/matlab/reporting/@page/addSection.m
index c9855ae3a6..b24c16b89e 100644
--- a/matlab/reporting/@page/addSection.m
+++ b/matlab/reporting/@page/addSection.m
@@ -30,10 +30,5 @@ function p = addSection(p, varargin)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
-assert(isa(p, 'page'), 'First argument must be a page object');
-if nargin == 1
-    p.sections = p.sections.addSection();
-elseif nargin == 2 || nargin == 3
-    p.sections = p.sections.addSection(varargin{:});
-end
+p.sections = p.sections.addSection(varargin{:});
 end
diff --git a/matlab/reporting/@page/page.m b/matlab/reporting/@page/page.m
index f0988d5717..f7f1c2c453 100644
--- a/matlab/reporting/@page/page.m
+++ b/matlab/reporting/@page/page.m
@@ -30,12 +30,13 @@ function o = page(varargin)
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
 o = struct;
-o.caption = '';
-o.orientation = 'portrait';
+o.paper = '';
+o.title = '';
+o.orientation = '';
 o.sections = sections();
 
 if nargin == 1
-    assert(isa(varargin{1}, 'page'),['With one arg to Page constructor, ' ...
+    assert(isa(varargin{1}, 'page'), ['With one arg to Page constructor, ' ...
                         'you must pass a page object']);
     o = varargin{1};
     return;
diff --git a/matlab/reporting/@page/subsref.m b/matlab/reporting/@page/subsref.m
index 33524ac793..7b3826bb94 100644
--- a/matlab/reporting/@page/subsref.m
+++ b/matlab/reporting/@page/subsref.m
@@ -23,13 +23,6 @@ switch S(1).type
         switch S(1).subs
             case fieldnames(A)
                 A = A.(S(1).subs);
-            case {'write'}
-                if areParensNext(S)
-                    write(A, S(2).subs{:})
-                    S = shiftS(S);
-                else
-                    assert(false);
-                end
             case methods(A)
                 if areParensNext(S)
                     A = feval(S(1).subs, A, S(2).subs{:});
diff --git a/matlab/reporting/@page/write.m b/matlab/reporting/@page/write.m
index 515a8b8198..4944b3d510 100644
--- a/matlab/reporting/@page/write.m
+++ b/matlab/reporting/@page/write.m
@@ -1,13 +1,12 @@
-function write(o, fid, indent)
-%function write(o, fid, indent)
+function o = write(o, fid)
+%function o = write(o, fid)
 % Write a Page object
 %
 % INPUTS
 %   fid - int, file id
-%   indent - char, number of spaces to indent tex code
 %
 % OUTPUTS
-%   none
+%   o   - this
 %
 % SPECIAL REQUIREMENTS
 %   none
@@ -31,14 +30,19 @@ function write(o, fid, indent)
 
 assert(fid ~= -1);
 
-fprintf(fid, '\n%s%% Page Object\n', indent);
+fprintf(fid, '\n%% Page Object\n');
+if ~isempty(o.title)
+    fprintf(fid, '\\centerline{{\\Large %s}}\n', o.title);
+end
 if strcmpi(o.orientation, 'landscape')
-    fprintf(fid, '%s\\begin{landscape}\n', indent);
+    fprintf(fid, '\\begin{landscape}\n')
 end
-o.sections.write(fid, addIndentation(indent));
+
+o.sections.write(fid);
+
 if strcmpi(o.orientation, 'landscape')
-    fprintf(fid, '%s\\end{landscape}\n', indent);
+    fprintf(fid, '\\end{landscape}\n');
 end
-fprintf(fid, '%s\\clearpage\n', indent);
-fprintf(fid, '%s%% End Page Object\n\n', indent);
+fprintf(fid, '\\clearpage\n');
+fprintf(fid, '%% End Page Object\n\n');
 end
\ No newline at end of file
diff --git a/matlab/reporting/@pages/addPage.m b/matlab/reporting/@pages/addPage.m
index 072f04f575..174d39b23d 100644
--- a/matlab/reporting/@pages/addPage.m
+++ b/matlab/reporting/@pages/addPage.m
@@ -18,10 +18,11 @@ function ps = addPage(ps, varargin)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
-assert(nargin >= 1 && nargin <= 3)
-if nargin == 1
-    ps.objArray = ps.objArray.addObj(page());
-else
-    ps.objArray = ps.objArray.addObj(varargin{:});
-end
+ps.objArray = ps.objArray.addObj(page(varargin{:}));
+%assert(nargin >= 1 && nargin <= 3)
+%if nargin == 1
+%    ps.objArray = ps.objArray.addObj(page());
+%else
+%    ps.objArray = ps.objArray.addObj(varargin{:});
+%end
 end
\ No newline at end of file
diff --git a/matlab/reporting/@pages/subsref.m b/matlab/reporting/@pages/subsref.m
index 1e5db0297e..8d78e5c263 100644
--- a/matlab/reporting/@pages/subsref.m
+++ b/matlab/reporting/@pages/subsref.m
@@ -23,13 +23,6 @@ switch S(1).type
         switch S(1).subs
             case fieldnames(A)
                 A = A.(S(1).subs);
-            case {'write'}
-                if areParensNext(S)
-                    write(A, S(2).subs{:})
-                    S = shiftS(S);
-                else
-                    assert(false);
-                end
             case methods(A)
                 if areParensNext(S)
                     A = feval(S(1).subs, A, S(2).subs{:});
diff --git a/matlab/reporting/@pages/write.m b/matlab/reporting/@pages/write.m
index 8bb89e3682..0c6efe5fb6 100644
--- a/matlab/reporting/@pages/write.m
+++ b/matlab/reporting/@pages/write.m
@@ -1,13 +1,12 @@
-function write(o, fid, indent)
-%function write(o, fid, indent)
+function o = write(o, fid)
+%function o = write(o, fid)
 % Write Pages object
 %
 % INPUTS
 %   fid - int, file id
-%   indent - char, number of spaces to indent tex code
 %
 % OUTPUTS
-%   none
+%   o   - this
 %
 % SPECIAL REQUIREMENTS
 %   none
@@ -30,10 +29,10 @@ function write(o, fid, indent)
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
 assert(fid ~= -1);
-fprintf(fid, '\n%s%% Pages Object\n', indent);
+fprintf(fid, '\n%% Pages Object\n');
 nps = numPages(o);
 for i=1:nps
-    o.objArray(i).write(fid, addIndentation(indent));
+    o.objArray(i).write(fid);
 end
-fprintf(fid, '%s%% End Pages Object\n\n', indent);
+fprintf(fid, '%% End Pages Object\n\n');
 end
\ No newline at end of file
diff --git a/matlab/reporting/@report/addPage.m b/matlab/reporting/@report/addPage.m
index 8299f973d6..f5f2c2468f 100644
--- a/matlab/reporting/@report/addPage.m
+++ b/matlab/reporting/@report/addPage.m
@@ -1,5 +1,5 @@
-function r = addPage(r, varargin)
-%function r = addPage(r, varargin)
+function o = addPage(o, varargin)
+%function o = addPage(o, varargin)
 % Add a page to the Cell Array of pages in the report
 %
 % INPUTS
@@ -30,21 +30,22 @@ function r = addPage(r, varargin)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
-assert(nargin >= 1 && nargin <= 3, ['incorrect number of arguments passed ' ...
-    'to addPage']);
-assert(isa(r, 'report'), 'First argument must be a report object');
-if nargin > 1
-    assert(isa(varargin{1},'page'), ['Optional 2nd arg to addPage must be a ' ...
-        'Page']);
-    if nargin > 2
-        assert(isnumeric(varargin{2}), ['Optional 3rd arg to addPage must be ' ...
-            'an index']);
-    end
-end
+%assert(nargin >= 1 && nargin <= 3, ['incorrect number of arguments passed ' ...
+%    'to addPage']);
+%assert(isa(r, 'report'), 'First argument must be a report object');
+%if nargin > 1
+%    assert(isa(varargin{1},'page'), ['Optional 2nd arg to addPage must be a ' ...
+%        'Page']);
+%    if nargin > 2
+%        assert(isnumeric(varargin{2}), ['Optional 3rd arg to addPage must be ' ...
+%            'an index']);
+%    end
+%end
 
 if nargin == 1
-    r.pages = r.pages.addPage();
-elseif nargin == 2 || nargin == 3
-    r.pages = r.pages.addPage(varargin{:});
+    o.pages = o.pages.addPage('orientation', o.orientation, 'paper', o.paper);
+else
+    o.pages = o.pages.addPage('orientation', o.orientation, 'paper', ...
+                              o.paper, varargin{:});
 end
 end
diff --git a/matlab/reporting/@report/report.m b/matlab/reporting/@report/report.m
index e4e193abd4..a045c5c880 100644
--- a/matlab/reporting/@report/report.m
+++ b/matlab/reporting/@report/report.m
@@ -34,6 +34,7 @@ o = struct;
 o.title = '';
 o.orientation = 'portrait';
 o.paper = 'a4';
+o.margin = '2cm';
 o.pages = pages();
 o.filename = 'report.tex';
 o.config = '';
diff --git a/matlab/reporting/@report/subsref.m b/matlab/reporting/@report/subsref.m
index 25a3001a35..9559393fe6 100644
--- a/matlab/reporting/@report/subsref.m
+++ b/matlab/reporting/@report/subsref.m
@@ -23,13 +23,6 @@ switch S(1).type
         switch S(1).subs
             case fieldnames(A)
                 A = A.(S(1).subs);
-            case {'write'}
-                if areParensNext(S)
-                    write(A, S(2).subs{:})
-                    S = shiftS(S);
-                else
-                    write(A);
-                end
             case methods(A)
                 if areParensNext(S)
                     A = feval(S(1).subs, A, S(2).subs{:});
diff --git a/matlab/reporting/@report/write.m b/matlab/reporting/@report/write.m
index 124edb96c7..6b686c662e 100644
--- a/matlab/reporting/@report/write.m
+++ b/matlab/reporting/@report/write.m
@@ -1,12 +1,12 @@
-function write(o)
-%function write(o)
+function o = write(o)
+%function o = write(o)
 % Write Report object
 %
 % INPUTS
-%   none
+%   o   - Report Object
 %
 % OUTPUTS
-%   none
+%   o   - Report Object
 %
 % SPECIAL REQUIREMENTS
 %   none
@@ -36,16 +36,18 @@ end
 fprintf(fid, '%% Report Object\n');
 fprintf(fid, '\\documentclass[11pt]{article}\n');
 
-fprintf(fid, '\\usepackage[%spaper,margin=2.5cm', o.paper);
+fprintf(fid, '\\usepackage[%spaper,margin=%s', o.paper, o.margin);
 if strcmpi(o.orientation, 'landscape')
     fprintf(fid, ',landscape');
 end
 fprintf(fid, ']{geometry}\n');
 fprintf(fid, '\\usepackage{graphicx}\n');
-fprintf(fid, '\\usepackage{pdflscape}\n')
+fprintf(fid, '\\usepackage{pdflscape}\n');
+fprintf(fid, '\\usepackage{pgf}\n');
+fprintf(fid, '\\usepackage{pgfplots}\n');
 fprintf(fid, '\\begin{document}\n');
 
-o.pages.write(fid, addIndentation(''));
+o.pages.write(fid);
 
 fprintf(fid, '\\end{document}\n');
 fprintf(fid, '%% End Report Object\n');
diff --git a/matlab/reporting/@section/addGraph.m b/matlab/reporting/@section/addGraph.m
index dd41fa4387..28e6e80b9b 100644
--- a/matlab/reporting/@section/addGraph.m
+++ b/matlab/reporting/@section/addGraph.m
@@ -30,10 +30,5 @@ function o = addGraph(o, varargin)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
-assert(isa(o, 'section'), 'First argument must be a section object');
-if nargin == 1
-    o.elements = o.elements.addGraph();
-elseif nargin == 2 || nargin == 3
-    o.elements = o.elements.addGraph(varargin{:});
-end
+o.elements = o.elements.addGraph(varargin{:});
 end
diff --git a/matlab/reporting/@section/addTable.m b/matlab/reporting/@section/addTable.m
index d960182899..7e9390c96c 100644
--- a/matlab/reporting/@section/addTable.m
+++ b/matlab/reporting/@section/addTable.m
@@ -30,10 +30,5 @@ function o = addTable(o, varargin)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
-assert(isa(o, 'section'), 'First argument must be a section object');
-if nargin == 1
-    o.elements = o.elements.addTable();
-elseif nargin == 2 || nargin == 3
-    o.elements = o.elements.addTable(varargin{:});
-end
+o.elements = o.elements.addTable(varargin{:});
 end
diff --git a/matlab/reporting/@section/display.m b/matlab/reporting/@section/display.m
index 4ca24a0184..67d9c5cc22 100644
--- a/matlab/reporting/@section/display.m
+++ b/matlab/reporting/@section/display.m
@@ -34,9 +34,13 @@ disp([name '.align = ']);
 disp(' ');
 disp(['     ''' o.align '''']);
 
+disp(' ');
+disp([name '.cols = ']);
+disp(' ');
+disp(o.cols);
+
 disp(' ');
 disp([name '.elements = ']);
 disp(' ');
 disp(o.elements.getElements());
-
 end
\ No newline at end of file
diff --git a/matlab/reporting/@section/section.m b/matlab/reporting/@section/section.m
index 94d1fc0ad9..e2260f47b2 100644
--- a/matlab/reporting/@section/section.m
+++ b/matlab/reporting/@section/section.m
@@ -23,10 +23,8 @@ function o = section(varargin)
 o = struct;
 o.align = 't';
 o.elements = elements();
-o.rows = 1;
 o.cols = 1;
 
-
 if nargin == 1
     assert(isa(varargin{1}, 'section'),['With one arg to Section constructor, ' ...
                         'you must pass a section object']);
@@ -55,4 +53,3 @@ end
 % Create section object
 o = class(o, 'section');
 end
-
diff --git a/matlab/reporting/@section/subsref.m b/matlab/reporting/@section/subsref.m
index cf3c18010d..eeb041c530 100644
--- a/matlab/reporting/@section/subsref.m
+++ b/matlab/reporting/@section/subsref.m
@@ -23,13 +23,6 @@ switch S(1).type
         switch S(1).subs
             case fieldnames(A)
                 A = A.(S(1).subs);
-            case {'write'}
-                if areParensNext(S)
-                    write(A, S(2).subs{:})
-                    S = shiftS(S);
-                else
-                    assert(false);
-                end
             case methods(A)
                 if areParensNext(S)
                     A = feval(S(1).subs, A, S(2).subs{:});
@@ -41,7 +34,7 @@ switch S(1).type
                 error(['Section Class: unknown field or method: ' S(1).subs]);
         end
     case '()'
-        A = getElements(A, S(1).subs{:});
+        A = A.elements.getElements(S(1).subs{:});
     case '{}'
         error(['Section Class: ' S(1).type ' indexing not supported.']);
     otherwise
diff --git a/matlab/reporting/@section/write.m b/matlab/reporting/@section/write.m
index aa81110ab1..85e451fdf6 100644
--- a/matlab/reporting/@section/write.m
+++ b/matlab/reporting/@section/write.m
@@ -1,13 +1,12 @@
-function write(o, fid, indent)
-%function write(o, fid, indent)
+function o = write(o, fid)
+%function o = write(o, fid)
 % Write Section object
 %
 % INPUTS
 %   fid - int, file id
-%   indent - char, number of spaces to indent tex code
 %
 % OUTPUTS
-%   none
+%   o   - this
 %
 % SPECIAL REQUIREMENTS
 %   none
@@ -31,14 +30,30 @@ function write(o, fid, indent)
 
 assert(fid ~= -1);
 
-fprintf(fid, '\n%s%% Section Object\n', indent);
-fprintf(fid, '%s\\noindent\\begin{minipage}[%s]{0.32\\hsize}\n', indent, o.align);
+fprintf(fid, '%% Section Object\n');
+fprintf(fid, '\\begin{table}[%shtpb]\n', o.align);
+fprintf(fid, '\\resizebox{\\textwidth}{!}{\n');
+fprintf(fid, '\\begin{tabular}{');
+for i=1:o.cols
+    fprintf(fid, 'c');
+end
+fprintf(fid, '}\n');
+
+% Calculate scaling factor
+%sf = round(100/o.cols)/100-.01;
 
 ne = numElements(o);
 for i=1:ne
-    o.elements(i).write(fid, addIndentation(indent));
+    o.elements(i).write(fid);
+    if rem(i, o.cols)
+        fprintf(fid, ' & ');
+    else
+        fprintf(fid, '\\\\\n');
+    end
 end
 
-fprintf(fid, '%s\\end{minipage}\n', indent);
-fprintf(fid, '%s%% End Section Object\n\n', indent);
+fprintf(fid, '\\end{tabular}\n');
+fprintf(fid, '}\n');
+fprintf(fid, '\\end{table}\n');
+fprintf(fid, '%% End Section Object\n\n');
 end
\ No newline at end of file
diff --git a/matlab/reporting/@sections/addSection.m b/matlab/reporting/@sections/addSection.m
index af412a412a..08bf94813f 100644
--- a/matlab/reporting/@sections/addSection.m
+++ b/matlab/reporting/@sections/addSection.m
@@ -18,15 +18,5 @@ function ss = addSection(ss, varargin)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
-assert(nargin >= 1 && nargin <= 3)
-if nargin > 1
-    assert(isa(varargin{1},'section'), ['Optional 2nd arg to addSection ' ...
-                        'must be a Section']);
-end
-
-if nargin == 1
-    ss.objArray = ss.objArray.addObj(section());
-else
-    ss.objArray = ss.objArray.addObj(varargin{:});
-end
+ss.objArray = ss.objArray.addObj(section(varargin{:}));
 end
\ No newline at end of file
diff --git a/matlab/reporting/@sections/subsref.m b/matlab/reporting/@sections/subsref.m
index d777cd0206..89e2948f80 100644
--- a/matlab/reporting/@sections/subsref.m
+++ b/matlab/reporting/@sections/subsref.m
@@ -23,13 +23,6 @@ switch S(1).type
         switch S(1).subs
             case fieldnames(A)
                 A = A.(S(1).subs);
-            case {'write'}
-                if areParensNext(S)
-                    write(A, S(2).subs{:})
-                    S = shiftS(S);
-                else
-                    assert(false);
-                end
             case methods(A)
                 if areParensNext(S)
                     A = feval(S(1).subs, A, S(2).subs{:});
diff --git a/matlab/reporting/@sections/write.m b/matlab/reporting/@sections/write.m
index 3370edd686..937bd3c178 100644
--- a/matlab/reporting/@sections/write.m
+++ b/matlab/reporting/@sections/write.m
@@ -1,13 +1,12 @@
-function write(o, fid, indent)
-%function write(o, fid, indent)
+function o = write(o, fid)
+%function o = write(o, fid)
 % Write Sections object
 %
 % INPUTS
 %   fid - int, file id
-%   indent - char, number of spaces to indent tex code
 %
 % OUTPUTS
-%   none
+%   o   - this
 %
 % SPECIAL REQUIREMENTS
 %   none
@@ -30,10 +29,10 @@ function write(o, fid, indent)
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
 assert(fid ~= -1);
-fprintf(fid, '\n%s%% Sections Object\n', indent);
+fprintf(fid, '\n%% Sections Object\n');
 nps = numSections(o);
 for i=1:nps
-    o.objArray(i).write(fid, indent);
+    o.objArray(i).write(fid);
 end
-fprintf(fid, '%s%% End Sections Object\n\n', indent);
+fprintf(fid, '%% End Sections Object\n\n');
 end
\ No newline at end of file
diff --git a/matlab/reporting/@table/write.m b/matlab/reporting/@table/write.m
index 4ad52ff8cf..129ae38a1a 100644
--- a/matlab/reporting/@table/write.m
+++ b/matlab/reporting/@table/write.m
@@ -1,12 +1,12 @@
-function write(o, fid, texIndent)
-%function write(o, fid)
-% Write a Page object
+function o = write(o, fid)
+%function o = write(o, fid)
+% Write a Table object
 %
 % INPUTS
-%   none
+%   fid - int, file id
 %
 % OUTPUTS
-%   none
+%   o   - this
 %
 % SPECIAL REQUIREMENTS
 %   none
@@ -31,10 +31,7 @@ function write(o, fid, texIndent)
 assert(fid > 0);
 assert(isnumeric(texIndent));
 
-fprintf(fid, '%d\% Page Object\n', texIndent);
-fprintf(fid, '%d\newpage\n', texIndent);
-
-o.sections.write(fid, texIndent+2);
+fprintf(fid, '%% Page Object\n');
 
-fprintf(fid, '%d\% End Page Object\n', texIndent);
+fprintf(fid, '%% End Page Object\n');
 end
\ No newline at end of file
diff --git a/matlab/reporting/addIndentation.m b/matlab/reporting/addIndentation.m
deleted file mode 100644
index 4bbea49b76..0000000000
--- a/matlab/reporting/addIndentation.m
+++ /dev/null
@@ -1,31 +0,0 @@
-function spaces=addIndentation(spaces)
-% Return new level of indentation for latex output
-%
-% INPUTS
-%   spaces - char, current level of indentation
-%
-% OUTPUTS
-%   spaces - char, new level of indentation
-%
-% SPECIAL REQUIREMENTS
-%   none
-
-% Copyright (C) 2013 Dynare Team
-%
-% This file is part of Dynare.
-%
-% Dynare is free software: you can redistribute it and/or modify
-% it under the terms of the GNU General Public License as published by
-% the Free Software Foundation, either version 3 of the License, or
-% (at your option) any later version.
-%
-% Dynare is distributed in the hope that it will be useful,
-% but WITHOUT ANY WARRANTY; without even the implied warranty of
-% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-% GNU General Public License for more details.
-%
-% You should have received a copy of the GNU General Public License
-% along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
-
-spaces = [spaces '    '];
-end
\ No newline at end of file
-- 
GitLab