Can't pass arguments to pandoc through rmarkdown - r

I am trying to pass pandoc arguments through rmarkdown YAML as it is linked here: http://rmarkdown.rstudio.com/html_document_format.html#advanced-customization
and the option I am trying to add is code line numbering:
--indented-code-classes=CLASSES
Specify classes to use for indented code blocks–for example, perl,numberLines or haskell. Multiple classes may be separated by spaces or commas.
My .Rmd file is below but after the rendering the output do no look like to be numbered. Does anyone know how to pass this argument correctly? I've tried many various possibilities but none of them worked.
---
title: "Untitled"
author: "Marcin Kosinski"
date: "28.12.2015"
output:
html_document:
theme: united
highlight: espresso
md_extensions: +fenced_code_attributes+fenced_code_blocks
pandoc_args: [
"--indented-code-classes","numberLines"
]
---
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r, results='hide'}
summary(cars)
iris
summary(iris)
```

Related

RMarkdown Add fold marks to PDF-document

I want to use RMarkdown to create a PDF document with folding marks on the left side.
I have already found a working example for LaTex:
https://tex.stackexchange.com/questions/332368/scrlttr2-wider-folding-marks
Unfortunately, I have not yet found a way to implement this example in my RMarkdown file.
In my opinion this example suggests to change the documentclass-option to scrlttr2.
However, after much research, I have not found a comparable example for RMarkdown.
Can someone help me?
(I would also be happy if you could find another way and create fold marks in RMarkdown.)
Here is my example-code:
---
title: "Untitled"
output: pdf_document
date: "2023-01-17"
header-includes:
\usepackage{fancyhdr}
\usepackage{xcolor}
---
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
You could use the same approach as in https://tex.stackexchange.com/a/95230/36296
---
title: "Untitled"
output: pdf_document
date: "2023-01-17"
header-includes:
- \usepackage{fancyhdr}
- \usepackage{xcolor}
- \usepackage{tikz}
- \usetikzlibrary{calc}
- \AddToHook{shipout/background}{\begin{tikzpicture}[overlay,remember picture]\draw ($(current page.north west)!0.3535!(current page.south west)$)--++(0.5cm,0cm);\draw ($(current page.north west)!0.50!(current page.south west)$)--++(0.8cm,0cm);\draw ($(current page.north west)!0.7071!(current page.south west)$)--++(0.5cm,0cm);\end{tikzpicture}}
---
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

Calibri font for a particular set of line in Rmarkdown

Here's a reproducible example of PDF Rmarkdown:
---
title: "Untitled"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r cars}
summary(cars)
```
I need "This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com."
to be in Calibri font than the default one.
If you are okay with setting the latex engine to xelatex, you can use \fontspec{Calibri} to set the font to Calibri and then \normalfont to return to the default font.
---
title: "Untitled"
output:
pdf_document:
latex_engine: xelatex
---
## R Markdown
\fontspec{Calibri}
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
\normalfont
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

Is there a way to add line breaks ONLY when exporting to PDF in R Markdown?

I think the question is quite self-explanatory but for avoidance of doubt I'll explain with more detail below:
I have an R Markdown document that works well if converted to HTML or uploaded to GitHub. When converting to PDF (using Latex), the results are not so pretty. I find that the biggest problem in a Latex PDF document are line breaks. I can fix the line breaks issue on the PDF document by adding "\ " characters, but that throws my HTML document out of whack too.
Is there a way to manually add line breaks (or "space before/after paragraphs") for the PDF output only?
Thank you!
You can redefine the relevant spacings in the YAML header. \parskip controls the paragraph spacing. Code blocks are shaded using a snugshade environment from the framed package. We can also redefine the shaded environment for code blocks to have some vertical space at the start. Here's a reproducible example. Note: I also added the keep_tex parameter so you can see exactly what the generated tex file looks like, in case this is useful:
title: "test"
author: "A.N. Other"
header-includes:
- \setlength{\parskip}{\baselineskip}
- \renewenvironment{Shaded}{\vspace{\parskip}\begin{snugshade}}{\end{snugshade}}
output:
pdf_document:
keep_tex: true
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r cars}
summary(cars)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
Once you output to HTML, you can just print the HTML webpage as PDF. that might be an easy way keep the original format

Rmarkdown: knit PDF to look exactly like HTML

When declaring output format in YAML section of my Rmarkdown document, is there a way to make sure it knits to PDF, but looks like a knitted HTML?
Nothing about knitted PDF looks the same: the font is some flavor of serif (assume I can change that), blockquotes and code chunks look different.
I like knitted HTML and the look, but is there a way to generate a PDF looking exactly the same?
As an example, just a simple default sample code:
---
title: "Untitled"
output:
html_document: default
pdf_document: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
> This is a quote
This is a link: <http://rmarkdown.rstudio.com>
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r cars}
summary(cars)
```
Here are 2 samples how 2 outputs look out of the box

How to indent new paragraphs?

How can I change the rmarkdown settings in a way that a new paragraph starts with an indented first line (as the default in LateX) rather than with blank space and no indentation.
That is what I normally get:
---
output: pdf_document
---
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:**
That is what I want:
In the header of your Rmd document, you can add LaTeX includes. To indent the paragraph, just change parindent, e.g.
output: pdf_document
header-includes:
- \setlength{\parindent}{4em}
- \setlength{\parskip}{0em}
Alternatively, you could store the latex commands in a separate file:
includes:
in_header: header.tex
See the advanced customization section.

Resources