Although Rmarkdown allow to include LaTeX environments and commands, and this should work as expected:
---
output:
pdf_document: default
---
- foo with a \LaTeX\ command.
- baz:
\begin{center}
bar
\end{center}
Sometimes happens that the export to LaTeX is unable to recognize the environment, and it is managed as markdown text.
Solution 1: Mark the LaTeX chunk explicitly as LaTeX or TeX code:
---
output:
pdf_document: default
---
- foo with a \LaTeX\ command.
- baz:
\begin{center}
bar
\end{center}
Note that it should be =latex or =tex with the equal sign before: Otherwise the block just will show the code with syntax highlight.
This solution have the advantage that you can pass any chunk of LaTeX, not just one environment.
Solution 2: Make the LaTeX environment as a Pandoc's Div block:
---
output:
pdf_document: default
---
- foo with a \LaTeX\ command
- baz:
::: {.center data-latex=""}
bar
:::
This have the advantage that the content environment could be markdowm syntax (you can type here *bar* instead of \emph{bar} to have cursives).
Note that you can also just insert only \begin{center} and somewhere later \end{center} with the solution 1, i.e, marking two chunks of LaTeX, to use markdown text inside, but in \begin{center} *foo* \end{center}, as is, there are no markdown text, only a word in LaTeX with two asteriks.
\begin{center}and\end{center}you have are LaTeX commands, and don't have any special meaning in R-markdown. Unless you are running your R-markdown through LaTeX (as opposed to the basicknitin R-studio), what you are getting is what is expected. There are several options for LaTeX within R-studio, the most basic being (I think) TinyTeX. You can also download TeXLive, and use that, but it may be more than you need, if you are only doing a few reports. – enkorvaks Jun 20 '23 at 04:48$$should be avoided and will insert a new block which breaks things here. You should try single$, so$a$instead of$$a$$(two times). I also have the feeling that mixing mardown with TeX-flavoured syntax is not optimal. Try using\mathbf{Y}instead of**Y**(but I don't know if it works in your set up). – Jasper Habicht Jun 20 '23 at 06:28