Bookmarks not working with RMarkdown (pdf) and titlesec - formatting

I was looking for a way to change heading format in RMarkdown (pdf) and found this code which works just fine.
---
output: pdf_document
header-includes:
- \usepackage[tiny]{titlesec}
\titleformat*{\section}{\center\bfseries}{}
---
However, the heading are not correct in the bookmarks of the document, i.e., all sections ends up a level lower than the previous (regardless of their actual level).
Here is an example.
---
output: pdf_document
header-includes:
- \usepackage[tiny]{titlesec}
\titleformat*{\section}{\center\bfseries}{}
---
# Level 1
# Level 1
## Level 2
### Level 3
# Level 1
## Level 2
And this is the resulting bookmarks.
Thank you,

Related

Remove chapter headings in Rmarkdown for PDF reports

I am aware that there are already an infinite number of entries here about the YAML header in rmarkdown. However, I have not yet been able to find an answer to the following question:
I need:
a PDF
a title page
the table of contents starting on the second page
a page numbering starting at the table of contents
numbered sections
no automatic chapter numbering
I would like to do this without LateX code, bookdown or the import of any text files.
Except for the last point, this seems to work with documentclass: report. Unfortunately I can't get rid of the chapters. Is there no pure rmarkdown YAML header solution for this?
---
title: The Force
subtitle: May it be with you
author: "Obi-Wan Kenobi"
date: "`r Sys.Date()`"
output:
pdf_document:
toc: yes
toc_depth: 3
number_sections: true
documentclass: report
---
# Introduction
## Sub
### SubSub
# Methods
## Sub
### SubSub
We can use this answer from Tex-StackExchange to do this.
---
title: The Force
subtitle: May it be with you
author: "Obi-Wan Kenobi"
date: "`r Sys.Date()`"
output:
pdf_document:
toc: yes
toc_depth: 3
number_sections: true
documentclass: report
header-includes:
- \usepackage{titlesec}
- \titleformat{\chapter}{\normalfont\LARGE\bfseries}{\thechapter}{1em}{}
- \titlespacing*{\chapter}{0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
---
# Introduction
## Sub
### SubSub
# Methods
## Sub
### SubSub
If your only reason to use the report class is the page break before the table of contents, you could easily add it to the default class article:
---
title: The Force
subtitle: May it be with you
author: "Obi-Wan Kenobi"
date: "`r Sys.Date()`"
output:
pdf_document:
keep_tex: true
toc: yes
toc_depth: 3
number_sections: true
header-includes:
- \pretocmd{\tableofcontents}{\clearpage}{}{}
- \apptocmd{\tableofcontents}{\clearpage}{}{}
---
# Introduction
## Sub
### SubSub
# Methods
## Sub
### SubSub

Regulate how many PDF pages is to be displayed per page in when knitting to PDF in Rmarkdown?

I have a rmarkdown document where I import a few PDFs, and I would like to display four PDF-import-pages per page in my knitted PDF.
---
title: "combinePages"
author: "xxx"
date: '2022-xx-xx'
output:
pdf_document:
toc: true
header-includes:
- \usepackage{pdfpages}
---
\includepdf[pages={-}]{pdfs/Lecture1.pdf}
\includepdf[pages={-}]{pdfs/Lecture2.pdf}
Can this be done in rmarkdown?
According to the manual of pdfpages,
nup => Puts multiple logical pages onto each sheet of paper. The syntax of this option is: nup=⟨xnup⟩x⟨ynup⟩. Where ⟨xnup⟩ and ⟨ynup⟩ specify the umber of logical pages in horizontal and vertical direction, which are arranged on each sheet of paper. (Default: nup=1x1)
So, four pdf pages from an imported pdf file can be knitted per page using nup=2x2 in the option of \includepdf.
---
title: "combinePages"
author: "xxx"
date: '2022-xx-xx'
output:
pdf_document:
toc: true
header-includes:
- \usepackage{pdfpages}
---
## Multiple Page
\includepdf[pages={1-}, nup=2x2]{lorem_ipsum.pdf}
\includepdf[pages={1-}, nup=2x2]{lorem_ipsum.pdf}
So A page of the rendered document looks like this,
Explore the manual for more options.

YAML issue when knitting to pdf

I have a paper written in rnotebook, which I want to knit to pdf.
this is the beginning of it, including the YAML:
---
title: "Are shifts between points of view challenging for readers? An examination of readers' eye movements in response to Woolf's *To the Lighthouse* and *Mrs Dalloway*"
author: "Giulia Grisot, Kathy Conklin, Violeta Sotirova - The University of Nottingham"
date: '`r format(Sys.time(), "%d %B %Y")`'
output:
html_notebook:
fig_caption: yes
force_captions: yes
#highlight: pygments
number_sections: false
theme: readable
# csl: sage-harvard.csl
csl: apa.csl
bibliography: library.bib
link-citations: yes
nocite: |
#Grisot2018
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)
```
```{r, include=F}
library(tidyverse)
library(ggpubr)
```
# Abstract
The emergence of empirical approaches within stylistics has increased interest in how literary texts are processed by readers. Techniques of speech and thought representation represent an area ripe for empirical investigation in this respect, especially when these cause interpretative ambiguities.
I have installed tinytex, and I have got miktex installed and pandoc.
I have tried to just use the "knit to pdf" command in RStudio but it gives me this error and i don't know what to do
Error in yaml::yaml.load(..., eval.expr = TRUE) :
Scanner error: while scanning for the next token at line 4, column 31 found character that cannot start any token at line 4, column 31
Calls: <Anonymous> ... parse_yaml_front_matter -> yaml_load -> <Anonymous>
Execution halted
I think this is down to the formatting in your yaml. When I knitted your code R Studio did some re-formatting of the title, but in the process replaced the ' with " in your date, causing the error. I don't have your .bib file so I can't test your exact code, but the following worked for me:
---
title: Are shifts between points of view challenging for readers? An examination of
readers' eye movements in response to Woolf's *To the Lighthouse* and *Mrs Dalloway*
author: "Giulia Grisot, Kathy Conklin, Violeta Sotirova - The University of Nottingham"
date: '`r format(Sys.time(), "%d %B %Y")`'
output:
pdf_document: default
html_notebook:
fig_caption: yes
force_captions: yes
number_sections: no
theme: readable
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)
```
```{r, include=F}
library(tidyverse)
#library(ggpubr)
```
# Abstract

Using biblatex in R markdown without auto-creating "Reference" section

My header looks as follows and works perfectly as intended:
---
header-includes:
- \usepackage{float}
- \usepackage{wrapfig}
- \usepackage{graphicx}
- \usepackage[fontsize=12pt]{scrextend}
- \usepackage{fontspec}
- \renewcommand*{\bibfont}{\footnotesize}
- \usepackage[dvipsnames]{xcolor}
output:
pdf_document:
latex_engine: xelatex
fig_caption: true
citation_package: biblatex
bibliography: SPP.bib
mainfont: ArialMT
geometry: margin=0.75in
---
However, the reference section already gets populated by the section name "References". Is there a way to stop that automated insertion? Thanks.
The "References" section is automatically included if you define a bibliography. Here an excerpt from the template:
$if(biblatex)$
\printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$
$endif$
Do you only want to change "References" into something else. Then it would be sufficient to add biblio-title: ... to you YAML header. If you want to suppress it completely, you have remove the quoted part in a copy of the template and use this copy instead. You can find the location where the template is stored via:
system.file("rmd", "latex", package = "rmarkdown")
#> [1] "/usr/lib/R/site-library/rmarkdown/rmd/latex"
Typically there are several files there:
list.files(system.file("rmd", "latex", package = "rmarkdown"))
#> [1] "default-1.14.tex" "default-1.15.2.tex" "default-1.17.0.2.tex"
#> [4] "default.tex"
The one with the highest version number (here default-1.17.0.2.tex) is used.

PDF Output with Knitr for Latex Equations

I am having trouble getting multi-line latex equations to successfully compile when using knitr in R Markdown. When I output as an HTML file it works but when I attempt to output as a PDF I get errors and it will not compile.
The following sample code illustrates the problem. Just change output:html_document to output: pdf_document. You'll see that in HTML output both Test 1 and Test 2 work. But in PDF output only Test 1 successfully compiles.
---
title: "Test"
date: "1/16/2018"
output: html_document
---
## R Markdown
Testing to see if a multi-line latex equation works.
#### Test 1:
$$ f(x) = x^5 + x^3 + x $$
$$ g(x) = y^{x+1} $$
#### Test 2:
\begin{align}
f(x) &= x^5 + x^3 + x \\
g(x) &= y^{x+1}
\end{align}
I am running Mac OS X - High Sierra and R Studio - Version 1.1.383
The following is the error I got:
Rule 'pdflatex': File changes, etc:
Non-existent destination files:
'Untitled.pdf'
------------
Run number 1 of rule 'pdflatex'
------------
------------
Running 'pdflatex -halt-on-error -interaction=batchmode -recorder "Untitled.tex"'
------------
This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
=== TeX engine is 'pdfTeX'
Latexmk: Errors, so I did not complete making targets
Collected error summary (may duplicate other messages):
pdflatex: Command for 'pdflatex' gave return code 1
Refer to 'Untitled.log' for details
Latexmk: Use the -f option to force complete processing,
unless error was exceeding maximum runs of latex/pdflatex.
! Paragraph ended before \align was complete.
<to be read again>
\par
l.112
Error: Failed to compile Untitled.tex. See Untitled.log for more info.
Execution halted