Adding line number when using rticles::elsevier_article - r

I am using rticles::elsevier_article to write a manuscript. I am not able to add the linenumber properly. What I did:
header-includes:
- \usepackage{lineno}
- \linenumbers
output:
bookdown::pdf_book:
base_format: rticles::elsevier_article
But, in this case when having equations the line numbers are not added, and neither the sections where the equations are embedded. Any suggestion?

Seems like your YAML is malformatted. Better to do it like this:
bookdown::pdf_book:
base_format: rticles::elsevier_article
includes:
in_header: "preamble.tex"
Then add additional LaTeX header lines to preamble.tex:
\usepackage{booktabs}
\usepackage{lineno}
\linenumbers
Example
index.Rmd
---
title: "A Minimal Book Example"
author: "You"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
output:
bookdown::pdf_book:
base_format: rticles::elsevier_article
includes:
in_header: "preamble.tex"
abstract: "This is your awesome abstract"
---
# Introduction
```{r, results='asis'}
cat(
stringi::stri_rand_lipsum(1)
)
```
(The code chunk requires the stringi package to be installed.)

Related

RMarkdown / Knitr: Hide code for Word document, but code folding in HTML document

For a project, I would like the knitr-output when choosing for a HTML to enable code folding, but to hide all code when knitting a word document.
My current RMarkdown YAML:
---
title: "Title"
author: "me"
output:
bookdown::html_document2:
code_folding: hide
number_sections: false
word_document:
reference_docx: reference.docx
# Option to hide code in word document?
pdf_document:
latex_engine: xelatex
bibliography: references.bib
link-citations: yes
editor_options:
markdown:
wrap: 72
linestretch: 2
lang: en
---
Is there an option for the word_document YAML-tag to make this possible? Or another workaround or package? If you set echo=FALSE or include=FALSE in the R chuncks, then this also omits the code in the HTML document. Looked around in RMarkdown documentation and different forums, but can't find a way to achieve this.
One option would be to use knitr::is_html_output to check whether you are rendering to HTML or not. This could then be used to conditionally set echo=FALSE for non-HTML output:
---
title: "Title"
author: "me"
output:
word_document:
# Option to hide code in word document?
#reference_docx: reference.docx
bookdown::html_document2:
code_folding: hide
number_sections: false
pdf_document:
latex_engine: xelatex
---
```{r include=FALSE}
if (!knitr::is_html_output()) knitr::opts_chunk$set(echo=FALSE)
```
```{r}
library(ggplot2)
ggplot(mtcars, aes(hp, mpg)) +
geom_point()
```
Word Output
HTML Output

Bookdown: Produce only PDF, no HTML

I have a large bookdown project. My YAML header below.
My only desired output is a PDF. However, bookdown by default produces a HTML as well. This makes compilation take more time, and also uses more caching space on my disk. Any chance I can disable producing HTML output? I have tried to play around with the site parameter in the YAML heading, but no luck.
title: "Title"
subtitle: "Subtitle"
author:
- "Name"
- "Institution"
date: "September 2020"
output:
bookdown::pdf_book:
toc: false
includes:
in_header: preamble.tex
keep_tex: yes
latex_engine: xelatex
citation_package: natbib
fontsize: 12pt
linestretch: 1.5
site: bookdown::bookdown_site
documentclass: book
bibliography: [references.bib]
biblio-style: "apalike"
geometry: "left=2.5cm, right=2.5cm, top=2.5cm, bottom=2.5cm"
bookdown doesn't really have a "default" output format. If it produces HTML, the output format must have been provided somewhere. Check if you have a _output.yml under the root directory of your book project. If you do, you may delete it. Then bookdown will use the output field that you specified in the YAML frontmatter of your Rmd document.

Rmarkdown and Latex format citations with round paranthesis

I feel like this is a straight forward thing, but everything I find doesn't quite get me what I want. I'm using rmarkdown and knitting to a latex .pdf. I'd like to have my in-text citations have round () parenthesis instead of the block ones. The yaml below uses a references.bib file to correctly import the references. Is there anything I can do to easily change my parenthesis to round?
---
title: "Title"
author: "Author"
date: "16/03/2020"
output:
pdf_document:
fig_caption: yes
citation_package: natbib
bibliography: references.bib
editor_options:
chunk_output_type: console
---
I've used an approach here, but it returns an error:
Error in yaml::yaml.load(..., eval.expr = TRUE) :
Parser error: while parsing a block mapping at line 6, column 5 did not
find expected key at line 7, column 30`
---
title: "Title"
author: "Author"
date: "16/03/2020"
output:
pdf_document:
fig_caption: yes
bibliography: references.bib
editor_options:
chunk_output_type: console
\usepackage[round]{natbib}
---
Any ideas? Thanks for your suggestions / ideas...
The problem with your attempt to include \usepackage[round]{natbib} in the rmarkdown header is that rmarkdown seems not clever enough to parse commands with optional arguments. One can trick it by hiding the command in a .tex file
---
title: "Title"
author: "Author"
date: "16/03/2020"
output:
pdf_document:
fig_caption: yes
includes:
in_header: preamble.tex
bibliography: references.bib
---
test [#knuth]
with preamble.tex
\usepackage[round]{natbib}
https://rstudio.cloud/project/1061588
Using the header-includes: option should fix the issue.
---
title: "Title"
author: "Author"
date: "16/03/2020"
output:
pdf_document:
fig_caption: yes
citation_package: natbib
bibliography: references.bib
editor_options:
chunk_output_type: console
header-includes:
- \usepackage[round]{natbib}
---

R bookdown: How to change the title of the table of content for rendering a PDF book

I am using bookdown to render a PDF book using the documentclass "scrreprt" from koma script. This works so far, however the book is in German
and the table of contents has a title "Contents" instead of a german "Inhaltsverzeichnis".
The "header" of my index.rmd:
---
title: "Mein Buchtitel"
author: "Jens Laufer"
date: "`r Sys.Date()`"
documentclass: scrreprt
---
The output of table of contents looks like this:
I tried also to add a preamble.tex in index.Rmd:
---
title: "Mein Buchtitel"
author: "Jens Laufer"
date: "`r Sys.Date()`"
documentclass: scrreprt
output:
bookdown::pdf_book:
includes:
in_header: preamble.tex
---
preamble.tex
\renewcommand{\contentsname}{Inhaltsverzeichnis}
However this doesn't help.
Any ideas? Thanks!
You can set the variable toc-title in the YAML metadata, e.g.,
toc-title: "Table of Contents"
See the Pandoc Manual for more info: https://pandoc.org/MANUAL.html
I could fix the problem by changing the preamble.tex to this:
\usepackage[ngerman]{babel}
\selectlanguage{ngerman}

How to output a pdf book from Rnotebook?

I'm not getting a pdf output from my rnotebook.
My header in my "index.Rmd" is:
---
title: "some title"
author: "me"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
documentclass: book
bibliography: [book.bib, packages.bib]
biblio-style: apalike
link-citations: yes
description: "Notes on a Leasing Company busines risk and opportunities."
---
I'm rendering the book in the console with the following code:
bookdown::render_book("index.rmd", output_format = "bookdown::pdf_book")
Output is:
Error: Functions that produce HTML output found in document targeting latex output.
Please change the output type of this document to HTML. Alternatively, you can allow
HTML output in non-HTML formats by adding this option to the YAML front-matter of
your rmarkdown file:
always_allow_html: yes
Note however that the HTML output will not be visible in non-HTML formats.
How do I go about changing the output type?
My file "_output.yml" file is:
toc:
before: |
<li>A Minimal Book Example</li>
after: |
<li>Published with bookdown</li>
download: ["pdf", "epub"]
bookdown::pdf_book:
includes:
in_header: preamble.tex
latex_engine: xelatex
citation_package: natbib
keep_tex: yes
bookdown::epub_book: default

Resources