How can I make it possible that markdown code used inside Latex Code gets evaluated? (Rmarkdown with PDF (Latex) Output)
Very simple minimal example:
\begin{center}
**should be bold text**
\end{center}
Current output in .tex file after compiling with knitr:
\begin{center}
**should be bold text**
\end{center}
Expected:
\begin{center}
\textbf{should be bold text}
\end{center}
I would be happy to find a way to get this working, because I try to find a way in which I can pass a tibble/dataframe through kable/kableExtra. Table cells can already contain Latex code, but no markdown code, since kable converts everything into a Latex structure.
It seems to me like all Markdown code inside any Latex code block doesn't get evaluated.
I know that I can achieve the same result by just using Latex Code, but I prefer using the Markdown shortcuts wherever possible.
Edit:
@duckmayr kindly offered to review another minimal example to see how it's possible to automatically change Latex code produced by R functions in order to make it work (together with the proposed & accepted answer, thx). So I'm looking for some kind of wrapper that would work regardless what R function I use (here: one basic R example and a simple kable test; could also be Stargazer, or something)
---
title: "Untitled"
output:
pdf_document:
keep_tex: true
df_print: kable
header-includes:
- \let\Begin\begin
- \let\End\end
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, results='hide', message=FALSE, warning=FALSE)
library(kableExtra)
```
```{r test1, results='asis'}
test = function(x=1){
cat('\\begin{center}\n**test**\n\\end{center}')
}
test()
```
```{r test2, results='asis'}
kable(data.frame(x=c("**bold text**")),"latex")
```