---
classoption: landscape
sansfont: Calibri Light
author: "Talitha Speranza"
output:
  rmarkdown::pdf_document:
    includes:  
      in_header: fix_figs.tex
params: 
  text: !r NA
  author: !r NA
  email: !r NA
  url: !r NA
  logo: !r NA
---

\fontfamily{lmss}\selectfont

```{r echo = FALSE, results = "hide"}
knitr::opts_chunk$set(warning=FALSE, message=FALSE)

text = params$text
author = params$author
email = params$email
logo = params$logo
url = params$url
```

```{r echo = FALSE}
library(BETS)
```

\def\haslogo{`r as.integer(!is.na(logo))`}
\def\haswebsite{`r as.integer(!is.na(url))`} 
\def\hastext{`r as.integer(!is.na(text))`} 

\fancypagestyle{plain}{
  \fancyhf{}%
  \setlength{\headheight}{45pt} 
  \fancyhead[L]{
    \includegraphics[width=\linewidth,height=40pt]{logo_situation} }
  \ifnum\hastext = 1
  \fancyhead[R]{
    {\fontfamily{lmss}\selectfont
    {\footnotesize Analysis by} \\
    \ifnum\haslogo = 1
      \includegraphics[width=\linewidth,height=35pt]{`r logo`} \\
    \else
      `r author` \\
    \fi
    \ifnum\haswebsite = 1
      {\small \url{`r url`}}
    \fi
    }
  }
  \fi
  \fancyfoot[L]{
     {\fontfamily{lmss}\selectfont
     {\small Charts generated by the \textbf{BETS R Package} on `r Sys.Date()` $\diamond$ \textbf{\url{https://github.com/pedrocostaferreira/BETS}}}}
  }
  \fancyfoot[R]{
    \thepage\  / \pageref{LastPage} }
}
\pagestyle{plain}


```{r echo = FALSE, results = "hide"}
dir.create("graphs")
chart(ts = "ipca_with_core", file = "ipca.pdf", open = FALSE)
```


```{r echo = FALSE, results = "hide"}
chart(ts = "ulc", file = "ulc.pdf", open = FALSE)
```

\begin{figure}[h]
\begin{subfigure}{.49\textwidth}
  \centering
  \includegraphics[width=1\linewidth]{graphs/ipca}
  \label{ipca}
\end{subfigure}
~
\begin{subfigure}{.49\textwidth}
  \centering
  \includegraphics[width=1\linewidth]{graphs/ulc}
  \label{cut}
\end{subfigure}
\end{figure}


```{r, echo = FALSE, results='asis'}
if(!is.na(text)){
  text <- paste(readLines(text), collapse=" ")
  text = gsub(pattern = "\\\\n", replacement = "  \n", x = text)
  text <- strsplit(text, "##")[[1]]
  cat(text[1])
}
```

\ifnum\hastext = 1
  \newpage
  \pagestyle{plain}
\fi

```{r echo = FALSE, results = "hide"}
chart(ts = "eap", file = "eap.pdf", open = FALSE)
```

```{r echo = FALSE, results = "hide"}
chart(ts = "unemp", file = "unemp.pdf", open = FALSE)
```

\begin{figure}[h]
\begin{subfigure}{.49\textwidth}
  \centering
  \includegraphics[width=1\linewidth]{graphs/eap}
  \label{ipca}
\end{subfigure}
~
\begin{subfigure}{.49\textwidth}
  \centering
  \includegraphics[width=1\linewidth]{graphs/unemp}
  \label{cut}
\end{subfigure}
\end{figure}


```{r, echo = FALSE, results='asis'}
if(!is.na(text)){
  cat(text[2])
}
```

\newpage
\pagestyle{plain}

```{r echo = FALSE, results = "hide"}
chart(ts = "vargdp", file = "vargdp.pdf", open = FALSE)
```

```{r echo = FALSE, results = "hide"}
chart(ts = "indprod", file = "indprod.pdf", open = FALSE)
```

\begin{figure}[h]
\begin{subfigure}{.49\textwidth}
  \centering
  \includegraphics[width=1\linewidth]{graphs/vargdp}
  \label{ipca}
\end{subfigure}
~
\begin{subfigure}{.49\textwidth}
  \centering
  \includegraphics[width=1\linewidth]{graphs/indprod}
  \label{cut}
\end{subfigure}
\end{figure}

```{r, echo = FALSE, results='asis'}
if(!is.na(text)){
  cat(text[3])
}
```

\ifnum\hastext = 1
  \newpage
  \pagestyle{plain}
\fi

```{r echo = FALSE, results = "hide"}
chart(ts = "selic", file = "selic.pdf", open = FALSE)
```

```{r echo = FALSE, results = "hide"}
chart(ts = "cdb", file = "cdb.pdf", open = FALSE)
```

\begin{figure}[h]
\begin{subfigure}{.49\textwidth}
  \centering
  \includegraphics[width=1\linewidth]{graphs/selic}
  \label{ipca}
\end{subfigure}
~
\begin{subfigure}{.49\textwidth}
  \centering
  \includegraphics[width=1\linewidth]{graphs/cdb}
  \label{cut}
\end{subfigure}
\end{figure}

```{r, echo = FALSE, results='asis'}
if(!is.na(text)){
  cat(text[4])
}
```


