I am rendering a book in .pdf with bookdown and I want to include several chapters.
_bookdown.yml looks like this:
book_filename: "my-Thesis"
before_chapter_script: "Script1.R" #Script1.R cleans memory (see Script1.R file)
rmd_files: ["index.Rmd", "01-intro.Rmd","02-C-quantity.Rmd","03-C-quality.Rmd","04-fine-roots.Rmd","05-aboveg-biom.Rmd","07-appendix.Rmd","08-definitions.Rmd","09-references.Rmd"]
delete_merged_file: true
_output.yml looks like this:
bookdown::gitbook:
lib_dir: assets
split_by: "rmd"
#config:
#toolbar:
#position: static
bookdown::pdf_book:
includes:
in_header: preamble.tex
keep_tex: yes
latex_engine: xelatex
#citation_package: #harvard #biblatex
I would like to add an Appendix 07-Appendix.Rmd at the end of the book which covers the whole book and shows up as a chapter, not as a subchapter of the "Above-ground..." chapter as shown in the following snapshot. This is also true for the Definitions and Referenceschapters.
Any help is welcome many thanks.
Start a new markdown page with the first line:
Appendix{-}
The {-} removes numbering. I find the rmd_files listing unnecessary. Attaching an image of a page and the resulting contents listing.
Related
I am rather experienced with R but new to markdown and especially bookdown. I wonder how to render a single chapter and merge it with the existing book without re-building the whole book. The reason why I am asking is that I am creating a book that contains parameterised chapters and each chapter runs very long (1-2 hours). All in all, it will be hundreds of chapters with the same analysis, but different input data and would time-wise add up. I am aware of the knit-and-merge approach, in fact, that's the reason why I chose bookdown, but somehow it is not working as expected.
I am honestly also a little bit confused by the different rendering possibilities. There is the built-book button, the knit button, serve_book(), render_book(), preview_chapter(), ... I figured that one should avoid using the knit button in bookdown and that serve_book() will automatically compile changes. My approach so far is entering serve_book() into console, where it renders the whole book, then I create a new chapter, hit save and it runs the chunks of only that chapter (exactly what I want!) and the single HTML file of the new chapter appears. However, it doesn't show them when I look at the book via the index.html file.
I am only interested in an HTML book and do not need any other output formats.
In order to recreate the problem, I am just using the bookdown example and adding chapters to it.
_bookdown.yaml
book_filename: "book_name"
new_session: yes #true
before_chapter_script: _common.R
delete_merged_file: true
language:
ui:
chapter_name: "Chapter "
_output.html
bookdown::bs4_book:
css: style.css
theme:
primary: "#10395B"
#repo: https://github.com/rstudio/bookdown-demo
bookdown::pdf_book:
includes:
in_header: preamble.tex
latex_engine: xelatex
citation_package: natbib
keep_tex: yes
bookdown::epub_book: default
_index.yaml
---
title: |
![](./Logo_PureGene.png){width=200px}|
|-|
||
author: "Name"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
#output: bookdown::bs4_book
documentclass: book
bibliography: [book.bib, packages.bib]
# url: your book url like https://bookdown.org/yihui/bookdown
# cover-image: path to the social sharing image like images/cover.jpg
description: |
This is a minimal example of using the bookdown package to write a book.
The HTML output format for this example is bookdown::bs4_book,
set in the _output.yml file.
biblio-style: apalike
csl: chicago-fullnote-bibliography.csl
---
# About {-}
I would appreciate any help!
Thanks in advance :)
I wonder if it is possible to put an appendix after references when using biblatex. These question and answer or this answer showed how to do so without citation_package: biblatex but do not work anymore when I add this in YAML. Using child document to print appendix after references does not work either.
Is it possible to use both biblatex and this solution?
Here's a reproducible example (Not working. Remove citation_package: biblatex for a functional example):
---
title:
author:
date:
abstract:
output:
pdf_document:
number_sections: true
citation_package: biblatex
bibliography: references.bib
biblio-style: bwl-FU
---
# Part 1
#greenwood_financial_1989
# My references
<div id="refs"></div>
# Appendix
bla bla
with references.bib:
#article{greenwood_financial_1989,
title = {Financial Development, Growth and the Distribution of Income},
url = {https://www.nber.org/papers/w3189},
number = {3189},
journaltitle = {NBER Working Paper Series},
date = {1989},
author = {Greenwood, Jeremy and Jovanovic, Boyan}
}
Edit: As suggested, I compared the latex document produced by the .Rmd file (by adding keep_tex: true in YAML) when I use citation_package: biblatex and when I don't.
I renamed the section "References" as "My references" in the .Rmd file to be able to distinguish the two sections in the latex document.
It appears that:
using citation_package: biblatex automatically adds \printbibliography at the end of the latex document, hence the "References" section with the actual references at the end of the PDF output. Besides, the section "My references" only contains \hypertarget{refs}{}.
when I remove citation_package: biblatex, the \printbibliography line disappears from the latex document, and the "My references" section contains \leavevmode\hypertarget{}{} with the id of the reference and its full description (that I do not paste here because it would only make this less readable).
Therefore, I guess this problem appears during the conversion from the .Rmd file to .tex format.
Is it possible to include a before_body only to some of the chapters in bookdown?
I tried to write a yaml header for the chapters in which I want to insert the before_body block but nothing showed up
---
bookdown::gitbook:
includes:
before_body: includes/myblock.html
---
I am writing a report with R Markdown in which I include references. The problem is that R markdown automatically includes references at the end of the report (without calling them with \printbibliography for example) and the section title is "References". I am writing in French so I would like the title to be "Références", but more generally is there any way to modify the title of that section?
Below is reproducible example:
---
title:
author:
date:
abstract:
output:
pdf_document:
template: NULL
number_sections: true
citation_package: biblatex
bibliography: references.bib
biblio-style: bwl-FU
---
# Partie 1
\cite{greenwood_financial_1989}
# Partie 2
bla bla
and here is the content of the references.bib file:
#article{greenwood_financial_1989,
title = {Financial Development, Growth and the Distribution of Income},
url = {https://www.nber.org/papers/w3189},
number = {3189},
journaltitle = {NBER Working Paper Series},
date = {1989},
author = {Greenwood, Jeremy and Jovanovic, Boyan}
}
Does anybody have a solution?
Here's the solution that combines this answer on doing something similar with bibtex and this one on the TeX required to do it in biblatex, plus #Ralf's comment about adding lang: fr
---
title:
author:
date:
abstract:
output:
pdf_document:
template: NULL
number_sections: true
citation_package: biblatex
bibliography: references.bib
biblio-style: bwl-FU
lang: fr
---
In my document, I used :
header-includes:
- \usepackage[french]{babel}
And your Contents section also changes.
I had a similar problem I wanted to place the bibliography above a supplemental section and placing <div id = "refs"></div> where you want the references successfully repositioned the section. I also had no problem renaming the section by simply changing the # title above that section. This did work for PDF output as well as HTML despite appearing to be an HTML only solution, though I was also using the markdown flavored ([#Smith2019]) references in the body of my document I don't know if using the LaTeX style will affect things.
I am compiling a long report into a html document with Bookdown and didn't have any problems knitting it with bookdown::gitbook until recently. Not sure what happened.
The code runs without errors, all the plots and files are generated as needed, but the index.rmd is generated into an .html file named after the first heading's id ("chapter00.html"), rather than "index.html". This means it the website does not work when uploaded to github.
Everything works great if the file name is manually changed to "index.html".
My index.rmd file looks as follows:
---
title: "Eesti inimarengu aruanne 2019"
author: "Eesti Koostöö Kogu"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
documentclass: book
bibliography: [bibliography/bib_chapter23.bib, bibliography/bib_chapterXY.bib]
biblio-style: authoryear
biblatexoptions: [refsegment=chapter]
csl: keel-ja-kirjandus.csl
link-citations: yes
description: "Eesti inimarengu aruanne 2019"
css: eia.css
lang: et
---
# Sissejuhatus {-#chapter00 .chapter_section .intro_section}
_bookdown.yml file is as follows:
book_filename: "EIA_2019_digi"
language:
label:
fig: 'Joonis '
tab: 'Tabel '
eq: 'Valem '
ui:
chapter_name: ""
delete_merged_file: true
_output.yml is as follows:
bookdown::gitbook:
split_by: section
split_bib: yes
config:
toc:
collapse: subsection
scroll_highlight: yes
before: null
after: null
toolbar:
position: fixed
edit : null
download: null
search: yes
sharing:
facebook: no
twitter: no
google: no
linkedin: no
weibo: no
instapaper: no
vk: no
all: ['facebook', 'google', 'twitter', 'linkedin', 'weibo', 'instapaper']
bookdown::pdf_book:
includes:
in_header: preamble.tex
latex_engine: xelatex
citation_package: natbib
keep_tex: yes
bookdown::epub_book: default
Any insight about what may cause the problem? Thanks!
The problem is that you are knitting your bookdown project, when you should render it with bookdown. In the R console:
bookdown::render_book("index.Rmd")
Check the last line of your output is something like
Output created: docs/index.html
[1] "/my/path/mybook/docs/index.html"
That should generate an index.html file from your index.rmd file
(And remember to set Source master branch/docs folder under Settings > Github Pages if you are using github.io to publish)
I had experienced this problem, and I can actually reproduce it in a particular way, which doesn't appear to be exactly the same as yours. If I don't keep any actual content or a markdown header in the index.Rmd file, then the rendered HTML file is named after the first header in the next Rmd file. If I put just one header in the index.Rmd file, then it renders to index.html
I had this problem in a project where I included chapters written in .md files using this approach:
in _bookdown.yml:
book_filename: "PGDEPhysics"
language:
ui:
chapter_name: ""
appendix_name: "Appendix "
delete_merged_file: true
output_dir: "docs"
rmd_files: [
'index.Rmd'
,'content.Rmd'
,'appendix.Rmd'
,'bibliography.Rmd'
]
the file content.Rmd:
```{r content, echo=FALSE}
library(fs)
cvec = dir_ls("Content", regexp = "^(.+).md$")
```
```{r child = cvec}
```
If the first file in the Content folder begins with a top-level heading:
# The first chapter
Everything is fine, and bookdown outputs an index.html file as required. If that first heading the first file starts with a subheading:
## The first chapter
Then we see this in the output:
Output created: docs/welcome.html
instead of the required:
Output created: docs/index.html
('Welcome' is the first top-level heading in index.Rmd)
Solution for me is to just live with it, and have that first .md file begin with a top-level heading.
The difficulty with this feature is that the problem is not noticed at the point it is introduced unless you are clearing out the target folder (in my case, docs) each time you build the book, because an older version of index.html may remain there and the site looks fine during development. The build process only adds files, it doesn't delete them from the target folder.
Best practice workflow, then, is to delete the target folder before you build.
It also can happen if the first chapter (index.Rmd) has more than one level one header (#)
This happened to me as well when including index.Rmd from a location not in the project directory. Moving the file fixed the naming problem.
For instance, I originally had the file in a subdirectory (e.g., doc/index.Rmd) and included this in _bookdown.yml: rmd_files: ["doc/index.Rmd", "doc/introduction.Rmd"]. This led to the output file being introduction.html.
Moving index.Rmd to the root directory and using rmd_files: ["index.Rmd"] led to the output file being index.html.
Note that it seems that removing index.Rmd from _bookdown.yml (i.e., rmd_files: ["doc/introduction.Rmd"]), also leads to an output of introduction.html.
You can only have one yaml header. If you have more then one, than the last one overwrites the main title.
See: https://bookdown.org/yihui/rmarkdown/bookdown-project.html#bookdown-project