How to put first level sections on different HTML pages? - r

In order to make first level sections instead of only chapters html pages of their own, I tried to alter the split_by in the yaml.
I used this code:
---
title: "new book"
author: "My name"
date: "`r Sys.Date()`"
subtitle: "subtitle"
site: bookdown::bookdown_site
output:
bookdown::gitbook:
split_by: chapter
config:
toc:
collapse: subsection
scroll_highlight: yes
before: null
after: null
toolbar:
position: fixed
edit : null
download: null
search: yes
fontsettings:
theme: white
family: sans
size: 2
sharing:
facebook: yes
twitter: yes
google: no
linkedin: no
weibo: no
instapaper: no
vk: no
all: ['facebook', 'google', 'twitter', 'linkedin', 'weibo', 'instapaper']
#bookdown::pdf_book: default
documentclass: book
---
When I change "chapter" into "section", R throws an error.
How can I make sure there will be seperated pages for chapters as well as first level sections?

There were (in this early stage of the document) some chapters without subsections. split_by: section will cause an error in case of chapters without sections.

Related

How to have Frontpage Image before chapter title and book title?

Is that possible to have FrontPage Image
a) BEFORE first chapter title,
b) BEFORE book title?
Currently the only way to include any frontpage image seems to be AFTER the first-level (non-empty) heading, like below:
---
knit: "bookdown::render_book"
site: bookdown::bookdown_site
documentclass: book
author: "Me Mine"
title: "«My Book»"
---
# Frontpage
```{r, echo=FALSE, out.width="60%", fig.align = "center"}
knitr::include_graphics( "nice-frontpage-image.jpg" )
)
# Introduction
...
It would have been so much better if I can do this (without having to have unneeded #Frontpage chapter):
---
knit: "bookdown::render_book"
site: bookdown::bookdown_site
documentclass: book
author: "Me Mine"
title: "«My Book»"
---
```{r, echo=FALSE, out.width="60%", fig.align = "center"}
knitr::include_graphics( "nice-frontpage-image.jpg" )
)
# Introduction
...
And this (i.e. image goes before the title):
---
knit: "bookdown::render_book"
site: bookdown::bookdown_site
documentclass: book
author: "Me Mine"
title: `r knitr::include_graphics( "nice-frontpage-image.jpg" )`
)"\n «My Book»"
---
# Introduction
...
Is that possible?
PS
I found a related still unaswered question here:
Index.Rmd without first-level heading

Adding navigation to a section in an R markdown file

I have a navbar defined in the _site.yml file:
name: "Rmarkdown with navbar"
output_dir: "."
navbar:
title: "Data Analysis"
type: inverse
right:
- text: "Abstract"
href: https://www.stackoverflow.com
- text: "Data Preparing"
href: https://www.stackoverflow.com
- text: "Related Plots"
href: https://www.stackoverflow.com
- text: "Player Selection"
href: https://www.stackoverflow.com
- text: "Conclusion"
href: https://www.stackoverflow.com
output:
html_document:
theme: spacelab
highlight: textmate
I would like to be able to navigate to each section in my main rmd file, each section is defined as:
<section id="name-of-section">
I tried the following but it doesn't work (in the _site.yml file).
right:
- text: "Abstract"
href: #abstract
I would really appreciate any help. It would be even better if I could add navigation animation when clicking (I know it's achievable using jQuery in websites).
Have you try just adding titles and subtitles to your markdown with '#' and "##' and then search for any section in "online document" (Crtl + Shift + "O")
Or you want a navigation panel on the markdown's output document?
If this is the case, have you try something like this at the beginning of your markdown?
---
title: "El Code-Book de Guibi"
output:
html_document:
toc: yes
toc_depth: 5
toc_float: yes
pdf_document:
toc: yes
toc_depth: '5'
editor_options:
markdown:
wrap: 72
---
In my case, it shows output like this:

xaringan set the document title dynamically

In r-markdown is is an option to move the title: out of the main yaml, as described in the R Markdown Cookbook.
But, in a xaringan slide set the new --- seems to conflict with the idea of new slide.
The below code works, but when move line #2, title: "Presentation Ninja" outside the main yaml, and inset it as title: "The name of the dog is r dog_name!", by removing all my <!-- ... --> code in line #17-19, it does not work as expected. I do no longer get a title page. I guess I need to work around the --- in xaringan?
Any help would be appreciated!
---
title: "Presentation Ninja"
subtitle: "⚔<br/>with xaringan"
author: "Yihui Xie"
output:
xaringan::moon_reader:
lib_dir: libs
---
# xaringan set the document title dynamically
```{r, code=xfun::read_utf8('script_with_many_dog_names.R')}
```
The name of the dog is `r dog_name`!
<!-- --- -->
<!-- title: "The name of the dog is `r dog_name`!" -->
<!-- --- -->
Some bullets
- Foo
- Bar
You could use R Markdown parameters :
Create a template file Template.Rmd
---
title: "The name of the dog is `r params$dog_name`"
subtitle: "⚔<br/>with xaringan"
author: "John Doe"
output:
xaringan::moon_reader:
lib_dir: libs
params:
dog_name: NA
---
# xaringan set the document title dynamically
Some bullets
- Foo
- Bar
Render the template after setting dog_name parameter :
source('script_with_many_dog_names.R')
# As an example, but it could be the result of previous script
params <- list(dog_name = 'Charles')
rmarkdown::render('Template.Rmd', output_file = 'presentation.html',
params = params,
envir = new.env(parent = globalenv())
)
You can add your logic directly to the title, that seems to work fine for me:
---
title: "The number is `r round(100 * runif(1), 2)`"
subtitle: "⚔<br/>with xaringan"
author: "Yihui Xie"
output:
xaringan::moon_reader:
lib_dir: libs
---

Omit index page from the Bookdown TOC

I am using bookdown to write a book with a web-version, using the bs4_book format. I want my index page (the front page) to not appear in the TOC on the left, i.e. I want the blue circled item in this screenshot not to appear in the TOC:
I tried the directions in the documentation:
# Section name {.unlisted .unnumbered}
but it is to no avail. My pandoc version is > 2.7 as indicated:
> rmarkdown::pandoc_version()
[1] ‘2.11.0.4’
These are the contents of _bookdown.yaml
book_filename: "shiny-book"
language:
ui:
chapter_name: "Chapter "
delete_merged_file: true
new_session: no
rmd_files:
[
"index.Rmd",
"test_chapter.md",
]
_output.yml
bookdown::bs4_book:
repo: https://github.com/smsaladi/phd
includes:
in_header: [ga_script.html, no_robots.html]
index.Rmd
---
title: "Investigations on the computer"
author: "Name"
site: bookdown::bookdown_site
---
`r if (knitr::is_latex_output()) '<!--'`
# Preface {.unlisted .unnumbered}
`r if (knitr::is_latex_output()) '-->'`

Setting paper size for PDF output in bookdown with tufte-book

In _output.yml, the following actually sets the paper size correctly:
bookdown::pdf_book:
pandoc_args: [
"-V", "papersize=a4"
]
But when I want to use tufte_book, the papersize argument has no effect, and the output in in letter size no matter what:
bookdown::pdf_book:
base_format: tufte::tufte_book
pandoc_args: [
"-V", "papersize=a4"
]
How do I override the default paper size in tufte_book?
You have to specify this as
bookdown::pdf_book:
base_format: tufte::tufte_book
pandoc_args: [
"-V", "papersize=a4paper"
]
I found this only by looking at the resulting .tex file. The reason is in the used templates. The Tufte templte includes $if(papersize)$$papersize$,$endif$ in the options to the document class, while the default template uses $if(papersize)$$papersize$paper,$endif$ with a literal paper.
BTW, you can also defines this in index.Rmd as
---
[...]
papersize: a4paper
---

Resources