preprocessor: add write_equation_tags option to write_latex_original_model and write_latex_static_model. closes #1431
parent
5429821719
commit
1551d33e9e
|
@ -2112,6 +2112,7 @@ equations using the @code{write_latex_static_model} command.
|
|||
@anchor{write_latex_original_model}
|
||||
|
||||
@deffn Command write_latex_original_model ;
|
||||
@deffnx Command write_latex_original_model (@var{OPTIONS}) ;
|
||||
|
||||
@descriptionhead
|
||||
|
||||
|
@ -2135,6 +2136,17 @@ appended to the variable names, as @LaTeX{} subscripts.
|
|||
Compiling the @TeX{} file requires the following @LaTeX{} packages:
|
||||
@code{geometry}, @code{fullpage}, @code{breqn}.
|
||||
|
||||
@optionshead
|
||||
|
||||
@table @code
|
||||
|
||||
@anchor{write_equation_tags}
|
||||
@item write_equation_tags
|
||||
Write the equation tags in the @LaTeX{} output. NB: the equation tags will be
|
||||
interpreted with @LaTeX{} markups.
|
||||
|
||||
@end table
|
||||
|
||||
@end deffn
|
||||
|
||||
@anchor{write_latex_dynamic_model}
|
||||
|
@ -2192,14 +2204,14 @@ For the required @LaTeX{} packages, @pxref{write_latex_original_model}.
|
|||
@table @code
|
||||
|
||||
@item write_equation_tags
|
||||
Write the equation tags in the @LaTeX{} output. NB: the equation tags will be
|
||||
interpreted with @LaTeX{} markups.
|
||||
@xref{write_equation_tags}
|
||||
|
||||
@end table
|
||||
|
||||
@end deffn
|
||||
|
||||
@deffn Command write_latex_static_model ;
|
||||
@deffnx Command write_latex_static_model (@var{OPTIONS}) ;
|
||||
|
||||
@descriptionhead
|
||||
|
||||
|
@ -2227,6 +2239,15 @@ lags) of the dynamic model declared in the @code{model} block.
|
|||
|
||||
For the required @LaTeX{} packages, @pxref{write_latex_original_model}.
|
||||
|
||||
@optionshead
|
||||
|
||||
@table @code
|
||||
|
||||
@item write_equation_tags
|
||||
@xref{write_equation_tags}
|
||||
|
||||
@end table
|
||||
|
||||
@end deffn
|
||||
|
||||
@node Auxiliary variables
|
||||
|
|
|
@ -2343,15 +2343,16 @@ WriteLatexDynamicModelStatement::writeJsonOutput(ostream &output) const
|
|||
output << "{\"statementName\": \"write_latex_dynamic_model\"}";
|
||||
}
|
||||
|
||||
WriteLatexStaticModelStatement::WriteLatexStaticModelStatement(const StaticModel &static_model_arg) :
|
||||
static_model(static_model_arg)
|
||||
WriteLatexStaticModelStatement::WriteLatexStaticModelStatement(const StaticModel &static_model_arg, bool write_equation_tags_arg) :
|
||||
static_model(static_model_arg),
|
||||
write_equation_tags(write_equation_tags_arg)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
WriteLatexStaticModelStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const
|
||||
{
|
||||
static_model.writeLatexFile(basename);
|
||||
static_model.writeLatexFile(basename, write_equation_tags);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -2360,15 +2361,16 @@ WriteLatexStaticModelStatement::writeJsonOutput(ostream &output) const
|
|||
output << "{\"statementName\": \"write_latex_static_model\"}";
|
||||
}
|
||||
|
||||
WriteLatexOriginalModelStatement::WriteLatexOriginalModelStatement(const DynamicModel &original_model_arg) :
|
||||
original_model(original_model_arg)
|
||||
WriteLatexOriginalModelStatement::WriteLatexOriginalModelStatement(const DynamicModel &original_model_arg, bool write_equation_tags_arg) :
|
||||
original_model(original_model_arg),
|
||||
write_equation_tags(write_equation_tags_arg)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
WriteLatexOriginalModelStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const
|
||||
{
|
||||
original_model.writeLatexOriginalFile(basename);
|
||||
original_model.writeLatexOriginalFile(basename, write_equation_tags);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -609,8 +609,9 @@ class WriteLatexStaticModelStatement : public Statement
|
|||
{
|
||||
private:
|
||||
const StaticModel &static_model;
|
||||
const bool write_equation_tags;
|
||||
public:
|
||||
WriteLatexStaticModelStatement(const StaticModel &static_model_arg);
|
||||
WriteLatexStaticModelStatement(const StaticModel &static_model_arg, bool write_equation_tags_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
@ -619,8 +620,9 @@ class WriteLatexOriginalModelStatement : public Statement
|
|||
{
|
||||
private:
|
||||
const DynamicModel &original_model;
|
||||
const bool write_equation_tags;
|
||||
public:
|
||||
WriteLatexOriginalModelStatement(const DynamicModel &original_model_arg);
|
||||
WriteLatexOriginalModelStatement(const DynamicModel &original_model_arg, bool write_equation_tags_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
|
|
@ -3751,7 +3751,8 @@ DynamicModel::cloneDynamic(DynamicModel &dynamic_model) const
|
|||
// Convert static_only equations
|
||||
for (size_t i = 0; i < static_only_equations.size(); i++)
|
||||
dynamic_model.addStaticOnlyEquation(static_only_equations[i]->cloneDynamic(dynamic_model),
|
||||
static_only_equations_lineno[i]);
|
||||
static_only_equations_lineno[i],
|
||||
static_only_equations_equation_tags[i]);
|
||||
|
||||
dynamic_model.setLeadsLagsOrig();
|
||||
}
|
||||
|
@ -3862,12 +3863,14 @@ DynamicModel::toStatic(StaticModel &static_model) const
|
|||
{
|
||||
// Detect if equation is marked [dynamic]
|
||||
bool is_dynamic_only = false;
|
||||
vector<pair<string, string> > eq_tags;
|
||||
for (vector<pair<int, pair<string, string> > >::const_iterator it = equation_tags.begin();
|
||||
it != equation_tags.end(); ++it)
|
||||
if (it->first == i && it->second.first == "dynamic")
|
||||
if (it->first == i)
|
||||
{
|
||||
is_dynamic_only = true;
|
||||
break;
|
||||
eq_tags.push_back(it->second);
|
||||
if (it->second.first == "dynamic")
|
||||
is_dynamic_only = true;
|
||||
}
|
||||
|
||||
try
|
||||
|
@ -3875,11 +3878,11 @@ DynamicModel::toStatic(StaticModel &static_model) const
|
|||
// If yes, replace it by an equation marked [static]
|
||||
if (is_dynamic_only)
|
||||
{
|
||||
static_model.addEquation(static_only_equations[static_only_index]->toStatic(static_model), static_only_equations_lineno[static_only_index]);
|
||||
static_model.addEquation(static_only_equations[static_only_index]->toStatic(static_model), static_only_equations_lineno[static_only_index], static_only_equations_equation_tags[static_only_index]);
|
||||
static_only_index++;
|
||||
}
|
||||
else
|
||||
static_model.addEquation(equations[i]->toStatic(static_model), equations_lineno[i]);
|
||||
static_model.addEquation(equations[i]->toStatic(static_model), equations_lineno[i], eq_tags);
|
||||
}
|
||||
catch (DataTree::DivisionByZeroException)
|
||||
{
|
||||
|
@ -4452,9 +4455,9 @@ DynamicModel::writeLatexFile(const string &basename, const bool write_equation_t
|
|||
}
|
||||
|
||||
void
|
||||
DynamicModel::writeLatexOriginalFile(const string &basename) const
|
||||
DynamicModel::writeLatexOriginalFile(const string &basename, const bool write_equation_tags) const
|
||||
{
|
||||
writeLatexModelFile(basename + "_original", oLatexDynamicModel);
|
||||
writeLatexModelFile(basename + "_original", oLatexDynamicModel, write_equation_tags);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -4767,13 +4770,18 @@ DynamicModel::isModelLocalVariableUsed() const
|
|||
}
|
||||
|
||||
void
|
||||
DynamicModel::addStaticOnlyEquation(expr_t eq, int lineno)
|
||||
DynamicModel::addStaticOnlyEquation(expr_t eq, int lineno, const vector<pair<string, string> > &eq_tags)
|
||||
{
|
||||
BinaryOpNode *beq = dynamic_cast<BinaryOpNode *>(eq);
|
||||
assert(beq != NULL && beq->get_op_code() == oEqual);
|
||||
|
||||
vector<pair<string, string> > soe_eq_tags;
|
||||
for (size_t i = 0; i < eq_tags.size(); i++)
|
||||
soe_eq_tags.push_back(eq_tags[i]);
|
||||
|
||||
static_only_equations.push_back(beq);
|
||||
static_only_equations_lineno.push_back(lineno);
|
||||
static_only_equations_equation_tags.push_back(soe_eq_tags);
|
||||
}
|
||||
|
||||
size_t
|
||||
|
|
|
@ -39,6 +39,9 @@ private:
|
|||
//! Stores line numbers of equations declared as [static]
|
||||
vector<int> static_only_equations_lineno;
|
||||
|
||||
//! Stores the equation tags of equations declared as [static]
|
||||
vector<vector<pair<string, string> > > static_only_equations_equation_tags;
|
||||
|
||||
typedef map<pair<int, int>, int> deriv_id_table_t;
|
||||
//! Maps a pair (symbol_id, lag) to a deriv ID
|
||||
deriv_id_table_t deriv_id_table;
|
||||
|
@ -298,7 +301,7 @@ public:
|
|||
void replaceMyEquations(DynamicModel &dynamic_model) const;
|
||||
|
||||
//! Adds an equation marked as [static]
|
||||
void addStaticOnlyEquation(expr_t eq, int lineno);
|
||||
void addStaticOnlyEquation(expr_t eq, int lineno, const vector<pair<string, string> > &eq_tags);
|
||||
|
||||
//! Returns number of static only equations
|
||||
size_t staticOnlyEquationsNbr() const;
|
||||
|
@ -310,7 +313,7 @@ public:
|
|||
void writeLatexFile(const string &basename, const bool write_equation_tags) const;
|
||||
|
||||
//! Writes LaTeX file with the equations of the dynamic model (for the original model)
|
||||
void writeLatexOriginalFile(const string &basename) const;
|
||||
void writeLatexOriginalFile(const string &basename, const bool write_equation_tags) const;
|
||||
|
||||
virtual int getDerivID(int symb_id, int lag) const throw (UnknownDerivIDException);
|
||||
virtual int getDynJacobianCol(int deriv_id) const throw (UnknownDerivIDException);
|
||||
|
|
|
@ -2118,11 +2118,15 @@ write_latex_dynamic_model : WRITE_LATEX_DYNAMIC_MODEL ';'
|
|||
;
|
||||
|
||||
write_latex_static_model : WRITE_LATEX_STATIC_MODEL ';'
|
||||
{ driver.write_latex_static_model(); }
|
||||
{ driver.write_latex_static_model(false); }
|
||||
| WRITE_LATEX_STATIC_MODEL '(' WRITE_EQUATION_TAGS ')' ';'
|
||||
{ driver.write_latex_static_model(true); }
|
||||
;
|
||||
|
||||
write_latex_original_model : WRITE_LATEX_ORIGINAL_MODEL ';'
|
||||
{ driver.write_latex_original_model(); }
|
||||
{ driver.write_latex_original_model(false); }
|
||||
| WRITE_LATEX_ORIGINAL_MODEL '(' WRITE_EQUATION_TAGS ')' ';'
|
||||
{ driver.write_latex_original_model(true); }
|
||||
;
|
||||
|
||||
shock_decomposition : SHOCK_DECOMPOSITION ';'
|
||||
|
|
|
@ -1690,7 +1690,7 @@ ModelTree::writeLatexModelFile(const string &basename, ExprNodeOutputType output
|
|||
|
||||
content_output << iteqt->second.first;
|
||||
|
||||
if (iteqt->second.second.empty())
|
||||
if (!(iteqt->second.second.empty()))
|
||||
content_output << "= `" << iteqt->second.second << "'";
|
||||
|
||||
wrote_eq_tag = true;
|
||||
|
@ -1723,7 +1723,7 @@ ModelTree::addEquation(expr_t eq, int lineno)
|
|||
}
|
||||
|
||||
void
|
||||
ModelTree::addEquation(expr_t eq, int lineno, vector<pair<string, string> > &eq_tags)
|
||||
ModelTree::addEquation(expr_t eq, int lineno, const vector<pair<string, string> > &eq_tags)
|
||||
{
|
||||
int n = equations.size();
|
||||
for (size_t i = 0; i < eq_tags.size(); i++)
|
||||
|
|
|
@ -200,7 +200,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 &basename, ExprNodeOutputType output_type, const bool write_equation_tags = false) const;
|
||||
void writeLatexModelFile(const string &basename, ExprNodeOutputType output_type, const bool write_equation_tags) const;
|
||||
|
||||
//! Sparse matrix of double to store the values of the Jacobian
|
||||
/*! First index is equation number, second index is endogenous type specific ID */
|
||||
|
@ -318,7 +318,7 @@ public:
|
|||
//! Declare a node as an equation of the model; also give its line number
|
||||
void addEquation(expr_t eq, int lineno);
|
||||
//! Declare a node as an equation of the model, also giving its tags
|
||||
void addEquation(expr_t eq, int lineno, vector<pair<string, string> > &eq_tags);
|
||||
void addEquation(expr_t eq, int lineno, const vector<pair<string, string> > &eq_tags);
|
||||
//! Declare a node as an auxiliary equation of the model, adding it at the end of the list of auxiliary equations
|
||||
void addAuxEquation(expr_t eq);
|
||||
//! Returns the number of equations in the model
|
||||
|
|
|
@ -1968,15 +1968,15 @@ ParsingDriver::write_latex_dynamic_model(bool write_equation_tags)
|
|||
}
|
||||
|
||||
void
|
||||
ParsingDriver::write_latex_static_model()
|
||||
ParsingDriver::write_latex_static_model(bool write_equation_tags)
|
||||
{
|
||||
mod_file->addStatement(new WriteLatexStaticModelStatement(mod_file->static_model));
|
||||
mod_file->addStatement(new WriteLatexStaticModelStatement(mod_file->static_model, write_equation_tags));
|
||||
}
|
||||
|
||||
void
|
||||
ParsingDriver::write_latex_original_model()
|
||||
ParsingDriver::write_latex_original_model(bool write_equation_tags)
|
||||
{
|
||||
mod_file->addStatement(new WriteLatexOriginalModelStatement(mod_file->original_model));
|
||||
mod_file->addStatement(new WriteLatexOriginalModelStatement(mod_file->original_model, write_equation_tags));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -2212,7 +2212,7 @@ ParsingDriver::add_model_equal(expr_t arg1, expr_t arg2)
|
|||
if (!id->isInStaticForm())
|
||||
error("An equation tagged [static] cannot contain leads, lags, expectations or STEADY_STATE operators");
|
||||
|
||||
dynamic_model->addStaticOnlyEquation(id, location.begin.line);
|
||||
dynamic_model->addStaticOnlyEquation(id, location.begin.line, eq_tags);
|
||||
}
|
||||
else
|
||||
model_tree->addEquation(id, location.begin.line, eq_tags);
|
||||
|
|
|
@ -563,9 +563,9 @@ public:
|
|||
//! Adds a write_latex_dynamic_model statement
|
||||
void write_latex_dynamic_model(bool write_equation_tags);
|
||||
//! Adds a write_latex_static_model statement
|
||||
void write_latex_static_model();
|
||||
void write_latex_static_model(bool write_equation_tags);
|
||||
//! Adds a write_latex_original_model statement
|
||||
void write_latex_original_model();
|
||||
void write_latex_original_model(bool write_equation_tags);
|
||||
//! BVAR marginal density
|
||||
void bvar_density(string *maxnlags);
|
||||
//! BVAR forecast
|
||||
|
|
|
@ -2112,9 +2112,9 @@ StaticModel::writeChainRuleDerivative(ostream &output, int eqr, int varr, int la
|
|||
}
|
||||
|
||||
void
|
||||
StaticModel::writeLatexFile(const string &basename) const
|
||||
StaticModel::writeLatexFile(const string &basename, bool write_equation_tags) const
|
||||
{
|
||||
writeLatexModelFile(basename + "_static", oLatexStaticModel);
|
||||
writeLatexModelFile(basename + "_static", oLatexStaticModel, write_equation_tags);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -183,7 +183,7 @@ public:
|
|||
void writeParamsDerivativesFile(const string &basename, bool julia) const;
|
||||
|
||||
//! Writes LaTeX file with the equations of the static model
|
||||
void writeLatexFile(const string &basename) const;
|
||||
void writeLatexFile(const string &basename, const bool write_equation_tags) const;
|
||||
|
||||
//! Writes initializations in oo_.steady_state or steady state file for the auxiliary variables
|
||||
void writeAuxVarInitval(ostream &output, ExprNodeOutputType output_type) const;
|
||||
|
|
Loading…
Reference in New Issue