## 12.5 Editing

In this section, we explain how to edit, build, preview, and serve the book locally.

### 12.5.1 Build the book

To build all Rmd files into a book, you can call the function bookdown::render_book(). It uses the settings specified in the _output.yml (if it exists). If multiple output formats are specified in it, all formats will be built. If you are using RStudio, this can be done through the Build tab. Open the drop down menu Build Book if you only want to build one format.

### 12.5.2 Preview a chapter

Building the whole book can be slow when the size of the book is big or your book contains large amounts of computation. We can use the preview_chapter() function in bookdown to only build a single chapter at a time. Equivalently, you can click the Knit button in RStudio.

### 12.5.3 Serve the book

Instead of running render_book() or preview_chapter() each time you want to view the changes, you can use the function bookdown::serve_book() to start a live preview of the book. Any time a Rmd file is saved, the book will be recompiled automatically, and the preview will be updated to reflect the changes.

The bookdown package comes with two addins for RStudio which assist the editing of books:

• “Preview Book”: this calls bookdown::serve_book() to compile and serve the book.

• “Input LaTeX Math”: provides a text box which allows you to write LaTeX equations, to avoid common errors when typing the raw LaTeX math expressions.