From 753d8a17f0f84aca5f98fc4cde69a2496e159ac1 Mon Sep 17 00:00:00 2001
From: Houtan Bastani <houtan@dynare.org>
Date: Wed, 5 Apr 2017 10:28:37 +0200
Subject: [PATCH] preprocessor: move equation tags out of dmath mode, include
 all equation tags in one set of brackets, allow equation tags to be
 interpreted as latex, modify manual and test accordingly. #477

---
 doc/dynare.texi              |  3 ++-
 preprocessor/ModelTree.cc    | 34 +++++++++++++++++++++++-----------
 tests/TeX/fs2000_corr_ME.mod |  2 +-
 3 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/doc/dynare.texi b/doc/dynare.texi
index d355a76884..13ac2279a7 100644
--- a/doc/dynare.texi
+++ b/doc/dynare.texi
@@ -2149,7 +2149,8 @@ For the required @LaTeX{} packages, @pxref{write_latex_original_model}.
 @table @code
 
 @item write_equation_tags
-Write the equation tags in the latex output
+Write the equation tags in the @LaTeX{} output. NB: the equation tags will be
+interpreted with @LaTeX{} markups.
 
 @end table
 
diff --git a/preprocessor/ModelTree.cc b/preprocessor/ModelTree.cc
index deec8b7238..ed5ecdbeb8 100644
--- a/preprocessor/ModelTree.cc
+++ b/preprocessor/ModelTree.cc
@@ -1573,19 +1573,31 @@ ModelTree::writeLatexModelFile(const string &basename, ExprNodeOutputType output
 
   for (int eq = 0; eq < (int) equations.size(); eq++)
     {
-      content_output << "\\begin{dmath}" << endl
-                     << "% Equation " << eq+1 << endl;
+      content_output << "% Equation " << eq + 1 << endl;
+      bool wrote_eq_tag = false;
       if (write_equation_tags)
-        for (vector<pair<int,pair<string,string> > >::const_iterator iteqt = equation_tags.begin();
-             iteqt != equation_tags.end(); iteqt++)
-          if (iteqt->first == eq)
-            {
-              content_output << "[\\textrm{" << iteqt->second.first << "}";
-              if (!empty(iteqt->second.second))
-                content_output << " = \\textrm{``" << iteqt->second.second << "''}";
-              content_output << "]";
-            }
+        {
+          for (vector<pair<int,pair<string,string> > >::const_iterator iteqt = equation_tags.begin();
+               iteqt != equation_tags.end(); iteqt++)
+            if (iteqt->first == eq)
+              {
+                if (!wrote_eq_tag)
+                  content_output << "\\noindent[";
+                else
+                  content_output << ", ";
+
+                content_output << iteqt->second.first;
+
+                if (!empty(iteqt->second.second))
+                  content_output << "= `" << iteqt->second.second << "'";
+
+                wrote_eq_tag = true;
+              }
+        }
+      if (wrote_eq_tag)
+        content_output << "]";
 
+      content_output << "\\begin{dmath}" << endl;
       // Here it is necessary to cast to superclass ExprNode, otherwise the overloaded writeOutput() method is not found
       dynamic_cast<ExprNode *>(equations[eq])->writeOutput(content_output, output_type);
       content_output << endl << "\\end{dmath}" << endl;
diff --git a/tests/TeX/fs2000_corr_ME.mod b/tests/TeX/fs2000_corr_ME.mod
index 4e67e98fee..c226ef8358 100644
--- a/tests/TeX/fs2000_corr_ME.mod
+++ b/tests/TeX/fs2000_corr_ME.mod
@@ -71,7 +71,7 @@ del = 0.02;
 options_.TeX=1;
 
 model;
-[name='technology growth']
+[name='technology growth: $\Delta A_{t}$', eq='\#1']
 dA = exp(gam+e_a);
 [name='money supply rule']
 log(m) = (1-rho)*log(mst) + rho*log(m(-1))+e_m;
-- 
GitLab