# LaTeX output of model equations in exp form

**URL:** <https://forum.dynare.org/t/latex-output-of-model-equations-in-exp-form/12535>\
**Category:** General DSGE Modeling\
**Created:** [3 October 2018 22:07 UTC](https://forum.dynare.org/t/latex-output-of-model-equations-in-exp-form/12535 "2018-10-03T22:07:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stzfe](https://forum.dynare.org/user_avatar/forum.dynare.org/stzfe/32/5210_2.png) [@stzfe](https://forum.dynare.org/u/stzfe)\
**Post date:** [3 October 2018 22:07 UTC](https://forum.dynare.org/t/latex-output-of-model-equations-in-exp-form/12535/1 "2018-10-03T22:07:46Z")

</div>

Dear all,

The model I work with now has log-linearized variables ( variables defined in exp(.) format, say if the model equation is x = y+ z, then in the model block it is exp(x) = exp(y)+exp(z) ).

I was wondering if there is a way for Dynare to output the model equations in TeX format substituting the ‘‘exp(‘variable’)’’ form to the original variable. (for example, if I want to output the equation above, I can still get x = y+z, not exp(x) = exp(y)+exp(z) ).

I know manually substitution is one way to go, but just wondering if Dynare has an automated way already.

Thank you.

---

<div class="post-metadata">

**Author:** ![stepan-a](https://forum.dynare.org/user_avatar/forum.dynare.org/stepan-a/32/6652_2.png) [@stepan-a](https://forum.dynare.org/u/stepan-a)\
**Post date:** [4 October 2018 09:14 UTC](https://forum.dynare.org/t/latex-output-of-model-equations-in-exp-form/12535/2 "2018-10-04T09:14:05Z")

</div>

Hi, I do not think that there is an option in Dynare to do the substitution automatically. But you can do it using matlab’s regular expressions. I would do something like:

```auto
write_latex_original_model;

// Loaad content of the TeX file generated by dynare.
texContent = fileread('substitution_original_content.tex');

// Remove exp functions.
expression = 'exp\\left\(\{(?<EXPRESSION>((\w*_\{t\})|(\\\w*_\{t\})|(\w*_\{t-\d\})|(\\\w*_\{t-\d\})|(\w*_\{t\+\d\})|(\\\w*_\{t\+\d\})))\}\\right)';
texContent = regexprep(texContent, expression, '$1');

// Update the original TeX file.
fid = fopen('substitution_original_content.tex','w');
fwrite(fid, texContent);
fclose(fid);

```

after the model declaration in the mod file. Note that it will replace all the terms of the form `exp(X)` by `X`, even if `X` is not an endogenous variable. You may need to adapt the value of `expression` (because I tested this code snippet only on a simple example), just look at the matlab documentation about [regular expressions](https://fr.mathworks.com/help/matlab/matlab_prog/regular-expressions.html).

Best,  
Stéphane.

---

<div class="post-metadata">

**Author:** ![stzfe](https://forum.dynare.org/user_avatar/forum.dynare.org/stzfe/32/5210_2.png) [@stzfe](https://forum.dynare.org/u/stzfe)\
**Post date:** [10 October 2018 19:19 UTC](https://forum.dynare.org/t/latex-output-of-model-equations-in-exp-form/12535/3 "2018-10-10T19:19:43Z")

</div>

Dear Stéphane,

This is absolutely gorgeous. Thanks for the advice!

Regards,  
TS
