model_latex: Export DSGE Model Equations to LaTeX

View source: R/model-latex.R

model_latexR Documentation

Export DSGE Model Equations to LaTeX

Description

Renders the equations of a dsge_model or dsgenl_model as LaTeX source, suitable for pasting into a paper or writing straight to a .tex file. Parameter names that match Greek letters are converted automatically (beta becomes \beta), variables receive time subscripts, and leads are wrapped in a conditional expectation operator.

Usage

model_latex(
  model,
  file = NULL,
  env = c("align", "gather", "none"),
  numbered = TRUE,
  greek = TRUE,
  standalone = FALSE,
  labels = FALSE
)

Arguments

model

A dsge_model or dsgenl_model object.

file

Optional path to write the LaTeX source to. If NULL (default) the source is returned invisibly and printed to the console.

env

Character. LaTeX environment to wrap the system in. One of "align" (default), "gather", or "none" (bare equation lines with no wrapper).

numbered

Logical. Use the numbered environment (align) rather than the starred one (align*). Default TRUE.

greek

Logical. Substitute Greek-letter parameter names with their LaTeX commands. Default TRUE.

standalone

Logical. Wrap the output in a minimal complete LaTeX document (with \documentclass and amsmath) so the file compiles on its own. Default FALSE.

labels

Logical. Emit a \label{eq:<lhs>} on each equation so they can be cross-referenced. Only used when numbered = TRUE. Default FALSE.

Details

Rendering conventions

  • Variables carry a time subscript: y renders as y_{t}.

  • Leads render inside a conditional expectation: lead(y) becomes \mathbb{E}_{t} y_{t+1}.

  • Parameter names matching a Greek letter are converted (sigma to \sigma); a trailing _bar becomes an overbar and a trailing _ss a steady-state superscript.

  • Divisions render as \frac, powers as superscripts, and multiplication as juxtaposition.

Value

A character vector of LaTeX source lines, returned invisibly. When file is supplied the same lines are written there.

Examples

nk <- dsge_model(
  obs(pi ~ beta * lead(pi) + kappa * x),
  unobs(x ~ lead(x) - (r - lead(pi) - g)),
  obs(r ~ psi * pi + u),
  state(u ~ rhou * u),
  state(g ~ rhog * g),
  fixed = list(beta = 0.99),
  start = list(kappa = 0.1, psi = 1.5, rhou = 0.7, rhog = 0.9))
tex <- model_latex(nk)
cat(head(tex, 4), sep = "\n")


dsge documentation built on Sept. 25, 2026, 5:08 p.m.