diff --git a/DynamicModel.cc b/DynamicModel.cc index 339cbe9765a2bfbbc032bbcc0774d59d60827cae..beca6f1f3bbb2754687a30498a0b29ffd148a3cc 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 688d4f292d888d43c533a40456f871dc2f976cc4..14149f59a3a5ef6bebe1354bbf79c51f80200819 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 4d161daf8bf027a91cf6c85ba8fc42c848dcd25b..ea799585c2b2f0b1cddca7fd678a333e3feccdd5 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 045e63364b368a644dadfcb5868e576f3bf337c0..523c0ab93dadeb32037ebad04c84b75bb6cf07b0 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