write.m 2.65 KB
Newer Older
1
2
function write(o, fid, pg, rep_dir)
%function write(o, fid, pg, rep_dir)
Houtan Bastani's avatar
Houtan Bastani committed
3
4
5
% Write a Page object
%
% INPUTS
Houtan Bastani's avatar
Houtan Bastani committed
6
7
%   o              [page]     page object
%   fid            [integer]  file id
8
%   pg             [integer]  this page number
9
%   rep_dir        [string]   directory containing report.tex
Houtan Bastani's avatar
Houtan Bastani committed
10
11
%
% OUTPUTS
Houtan Bastani's avatar
Houtan Bastani committed
12
%   o              [page]     page object
Houtan Bastani's avatar
Houtan Bastani committed
13
14
15
%
% SPECIAL REQUIREMENTS
%   none
Houtan Bastani's avatar
Houtan Bastani committed
16

17
% Copyright (C) 2013-2019 Dynare Team
Houtan Bastani's avatar
Houtan Bastani committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
%
% 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/>.

34
fprintf(fid, '\n%% Page Number %d written %s\n', pg, datestr(now));
35
36
37
if ~isempty(o.setPageNumber)
    fprintf(fid, '\\setcounter{page}{%d}\n', o.setPageNumber);
end
38
39
40
if o.removeHeaderAndFooter
    fprintf(fid, '\\thispagestyle{empty}\n');
end
41
if strcmpi(o.orientation, 'landscape')
42
    fprintf(fid, '\\begin{landscape}\n');
Houtan Bastani's avatar
Houtan Bastani committed
43
end
Houtan Bastani's avatar
Houtan Bastani committed
44

45
46
for i=1:length(o.footnote)
    fprintf(fid, '\\blfootnote{\\tiny %d. %s}', i, o.footnote{i});
Houtan Bastani's avatar
Houtan Bastani committed
47
end
48
fprintf(fid, '\n');
Houtan Bastani's avatar
Houtan Bastani committed
49

50
if ~isempty(o.latex)
Houtan Bastani's avatar
Houtan Bastani committed
51
    dir = [rep_dir '/' o.pageDirName];
52
53
    if exist(dir, 'dir') ~= 7
        mkdir(dir);
54
    end
Houtan Bastani's avatar
Houtan Bastani committed
55
    pagename = [dir '/page_' num2str(pg) '.tex'];
56
57
58
59
60
61
62
63
64
    [fidp, msg] = fopen(pagename, 'w');
    if fidp == -1
        error(['@page.write: ' msg]);
    end
    fprintf(fidp, '%s', o.latex);
    if fclose(fidp) == -1
        error('@page.write: closing %s\n', pagename);
    end
    fprintf(fid, '\\input{%s}', pagename);
65
else
Houtan Bastani's avatar
Houtan Bastani committed
66
67
68
    if ~isempty(o.title)
        fprintf(fid, '\\addcontentsline{toc}{subsection}{%s}\n', o.title{1});
    end
69
    fprintf(fid, '\\begin{tabular}[t]{c}\n');
70
    for i = 1:length(o.title)
71
72
73
74
        if isint(o.titleTruncate)
            if length(o.title{i}) > o.titleTruncate
                o.title{i} = o.title{i}(1:o.titleTruncate);
            end
75
        end
76
        fprintf(fid, '\\multicolumn{1}{c}{%s %s}\\\\\n', o.titleFormat{i}, o.title{i});
77
    end
Stéphane Adjemian's avatar
Stéphane Adjemian committed
78

79
    for i = 1:length(o.sections)
80
        o.sections{i}.write(fid, pg, i, rep_dir);
81
82
    end
    fprintf(fid, '\\end{tabular}\n');
83
end
Houtan Bastani's avatar
Houtan Bastani committed
84

Houtan Bastani's avatar
Houtan Bastani committed
85
if strcmpi(o.orientation, 'landscape')
Houtan Bastani's avatar
Houtan Bastani committed
86
    fprintf(fid, '\\end{landscape}\n');
Houtan Bastani's avatar
Houtan Bastani committed
87
end
Houtan Bastani's avatar
Houtan Bastani committed
88
89
fprintf(fid, '\\clearpage\n');
fprintf(fid, '%% End Page Object\n\n');
90
end