Chapter 4 Editing the book

The contents of the book are written in RMarkdown. You can use any formatting code that Pandoc’s Markdown supports, e.g., a math equation \(a^2 + b^2 = c^2\). Moreover, you can include chunks of R-code, like this:

```{r}
print("This is an R-command!")
```

The results of these chunks can be rendered to the GitBook:

## [1] "This is an R-command!"

To edit the book, you can change the text in the .Rmd files. Each Rmd file should contain one and only one chapter. A chapter is defined by the first-level heading #, e.g., # Editing the book.

Any sub-headings within the chapter are indicated with several # signs, e.g., ## (level 2) and ### (level 3).

4.1 Creating new chapters

To create a new chapter, you must follow two steps: 1) Create the file, and 2) Include it in the list of chapters.

First, to create the file for a new chapter in Rstudio, click File > New File > Text file. At the top of the file, write your chapter heading, as explained above. Then, click File > Save. Save the file as .Rmd, without spaces in the file name, e.g.: editing_the_book.Rmd.

Second, to include it in the list of chapters, open the file _bookdown.yml (click it in the Files explorer in the bottom right of Rstudio). This file has a list of .Rmd files to be included in the book. In this example, the list looks like this:

rmd_files: [“index.Rmd”, “prerequisites.Rmd”, “get_your_gitbook.Rmd”, “editing_the_book.Rmd”, “figures_tables.Rmd”, “examples.Rmd”, “open_educational.Rmd”, “use_in_course.Rmd”, “licenses.Rmd”, “references.Rmd”]

Insert the file name of your new chapter in the desired position in this list.

4.2 Linking across chapters

You can label chapter and section titles using {#label} after them. The labels can be used as cross-references. For example, we can link to Chapter 5. If you do not manually label chapters, there will be automatic labels anyway, e.g., Chapter 6.

4.3 Advanced editing

The convenient Rmarkdown Cheat Sheet by Rstudio covers most of the knowledge required for advanced Rmarkdown editing. You can print it out and stick it to your wall!