From 947ca384406fa5e8ad6a5afecd04a69dc27e0e69 Mon Sep 17 00:00:00 2001 From: Houtan Bastani <houtan@dynare.org> Date: Wed, 15 Jul 2015 08:58:15 +0200 Subject: [PATCH] preprocessor: split creation of latex model files. closes #966 --- DynamicModel.cc | 4 ++-- ModelTree.cc | 34 +++++++++++++++++++++++----------- ModelTree.hh | 4 ++-- StaticModel.cc | 2 +- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/DynamicModel.cc b/DynamicModel.cc index 339cbe97..beca6f1f 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -3907,13 +3907,13 @@ DynamicModel::writeChainRuleDerivative(ostream &output, int eqr, int varr, int l void DynamicModel::writeLatexFile(const string &basename) const { - writeLatexModelFile(basename + "_dynamic.tex", oLatexDynamicModel); + writeLatexModelFile(basename + "_dynamic", oLatexDynamicModel); } void DynamicModel::writeLatexOriginalFile(const string &basename) const { - writeLatexModelFile(basename + "_original.tex", oLatexDynamicModel); + writeLatexModelFile(basename + "_original", oLatexDynamicModel); } void diff --git a/ModelTree.cc b/ModelTree.cc index 688d4f29..14149f59 100644 --- a/ModelTree.cc +++ b/ModelTree.cc @@ -1339,9 +1339,12 @@ ModelTree::Write_Inf_To_Bin_File(const string &basename, } void -ModelTree::writeLatexModelFile(const string &filename, ExprNodeOutputType output_type) const +ModelTree::writeLatexModelFile(const string &basename, ExprNodeOutputType output_type) const { - ofstream output; + ofstream output, content_output; + string filename = basename + ".tex"; + string content_basename = basename + "_content"; + string content_filename = content_basename + ".tex"; output.open(filename.c_str(), ios::out | ios::binary); if (!output.is_open()) { @@ -1349,6 +1352,13 @@ ModelTree::writeLatexModelFile(const string &filename, ExprNodeOutputType output exit(EXIT_FAILURE); } + content_output.open(content_filename.c_str(), ios::out | ios::binary); + if (!content_output.is_open()) + { + cerr << "ERROR: Can't open file " << content_filename << " for writing" << endl; + exit(EXIT_FAILURE); + } + output << "\\documentclass[10pt,a4paper]{article}" << endl << "\\usepackage[landscape]{geometry}" << endl << "\\usepackage{fullpage}" << endl @@ -1364,25 +1374,27 @@ ModelTree::writeLatexModelFile(const string &filename, ExprNodeOutputType output int id = it->first; expr_t value = it->second; - output << "\\begin{dmath*}" << endl - << symbol_table.getName(id) << " = "; + content_output << "\\begin{dmath*}" << endl + << symbol_table.getName(id) << " = "; // Use an empty set for the temporary terms - value->writeOutput(output, output_type); - output << endl << "\\end{dmath*}" << endl; + value->writeOutput(content_output, output_type); + content_output << endl << "\\end{dmath*}" << endl; } for (int eq = 0; eq < (int) equations.size(); eq++) { - output << "\\begin{dmath}" << endl - << "% Equation " << eq+1 << endl; + content_output << "\\begin{dmath}" << endl + << "% Equation " << eq+1 << endl; // Here it is necessary to cast to superclass ExprNode, otherwise the overloaded writeOutput() method is not found - dynamic_cast<ExprNode *>(equations[eq])->writeOutput(output, output_type); - output << endl << "\\end{dmath}" << endl; + dynamic_cast<ExprNode *>(equations[eq])->writeOutput(content_output, output_type); + content_output << endl << "\\end{dmath}" << endl; } - output << "\\end{document}" << endl; + output << "\\include{" << content_basename << "}" << endl + << "\\end{document}" << endl; output.close(); + content_output.close(); } void diff --git a/ModelTree.hh b/ModelTree.hh index 4d161daf..ea799585 100644 --- a/ModelTree.hh +++ b/ModelTree.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 Dynare Team + * Copyright (C) 2003-2015 Dynare Team * * This file is part of Dynare. * @@ -183,7 +183,7 @@ protected: void compileModelEquations(ostream &code_file, unsigned int &instruction_number, const temporary_terms_t &tt, const map_idx_t &map_idx, bool dynamic, bool steady_dynamic) const; //! Writes LaTeX model file - void writeLatexModelFile(const string &filename, ExprNodeOutputType output_type) const; + void writeLatexModelFile(const string &basename, ExprNodeOutputType output_type) const; //! Sparse matrix of double to store the values of the Jacobian /*! First index is equation number, second index is endogenous type specific ID */ diff --git a/StaticModel.cc b/StaticModel.cc index 045e6336..523c0ab9 100644 --- a/StaticModel.cc +++ b/StaticModel.cc @@ -1893,7 +1893,7 @@ StaticModel::writeChainRuleDerivative(ostream &output, int eqr, int varr, int la void StaticModel::writeLatexFile(const string &basename) const { - writeLatexModelFile(basename + "_static.tex", oLatexStaticModel); + writeLatexModelFile(basename + "_static", oLatexStaticModel); } void -- GitLab