Skip to content

Commit

Permalink
here is the minimal example
Browse files Browse the repository at this point in the history
  • Loading branch information
yihui committed Nov 10, 2015
1 parent d9de37f commit 68c601f
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 0 deletions.
18 changes: 18 additions & 0 deletions 01-intro.Rmd
@@ -0,0 +1,18 @@
# Introduction {#intro}

You can label chapter and section titles using `{#label}` after them, e.g., we can reference Chapter \@ref(intro). If you do not manually label them, there will be automatic labels anyway, e.g., Chapter \@ref(methods).

Figures and tables with captions will be placed in `figure` and `table` environments, respectively.

```{r nice-fig, fig.cap='Here is a nice figure!', out.width='80%', fig.asp=.75, fig.align='center'}
par(mar = c(4, 4, .1, .1))
plot(pressure, type = 'b', pch = 19)
```

Reference a figure by its code chunk label with the `fig:` prefix, e.g., see Figure \@ref(fig:nice-fig). Similarly, you can reference tables generated from `knitr::kable()`, e.g., see Table \@ref(tab:nice-tab).

```{r nice-tab}
knitr::kable(head(iris, 20), caption = 'Here is a nice table!', booktabs = TRUE)
```

You can write citations, too. For example, we are using the **bookdown** package [@R-bookdown] in this sample book, which was built on top of R Markdown and **knitr** [@xie2015].
3 changes: 3 additions & 0 deletions 02-literature.Rmd
@@ -0,0 +1,3 @@
# Literature

Here is a review of existing methods.
3 changes: 3 additions & 0 deletions 03-method.Rmd
@@ -0,0 +1,3 @@
# Methods

We describe our methods in this chapter.
7 changes: 7 additions & 0 deletions 04-application.Rmd
@@ -0,0 +1,7 @@
# Applications

Some _significant_ applications are demonstrated in this chapter.

## Example one

## Example two
3 changes: 3 additions & 0 deletions 05-summary.Rmd
@@ -0,0 +1,3 @@
# Final Words

We have finished a nice book.
9 changes: 9 additions & 0 deletions 06-references.Rmd
@@ -0,0 +1,9 @@
`r if (knitr:::is_html_output()) '# References'`

```{r include=FALSE}
# automatically create a bib database for R packages
knitr::write_bib(c(
.packages(), 'bookdown', 'knitr', 'rmarkdown'
), 'packages.bib')
```

12 changes: 12 additions & 0 deletions Makefile
@@ -0,0 +1,12 @@
RMD_FILES := $(filter-out _%, $(wildcard *.Rmd))
HTML_FILES := $(patsubst %.Rmd, %.html, $(RMD_FILES))

all: $(HTML_FILES)

%.html: %.Rmd
Rscript -e "bookdown::render_book('$<', 'bookdown::html_chapters')"

pdf: book.pdf

%.pdf: %.Rmd $(RMD_FILES)
Rscript -e "bookdown::render_book('$<', 'bookdown::pdf_book')"
2 changes: 2 additions & 0 deletions _config.yml
@@ -0,0 +1,2 @@
main_rmd: "book.Rmd"
chapter_name: "CHAPTER "
10 changes: 10 additions & 0 deletions book.bib
@@ -0,0 +1,10 @@
@Book{xie2015,
title = {Dynamic Documents with {R} and knitr},
author = {Yihui Xie},
publisher = {Chapman and Hall/CRC},
address = {Boca Raton, Florida},
year = {2015},
edition = {2nd},
note = {ISBN 978-1498716963},
url = {http://yihui.name/knitr/},
}
16 changes: 16 additions & 0 deletions bookdown-demo.Rproj
@@ -0,0 +1,16 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: knitr
LaTeX: pdfLaTeX

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes
34 changes: 34 additions & 0 deletions index.Rmd
@@ -0,0 +1,34 @@
---
title: "A Minimal Book Example"
author: "Yihui Xie"
date: "`r Sys.Date()`"
knit: "bookdown::render_book"
output:
bookdown::html_chapters:
css: style.css
md_extensions: +markdown_in_html_blocks
bookdown::pdf_book:
includes:
in_header: preamble.tex
keep_tex: yes
latex_engine: xelatex
documentclass: book
bibliography: [book.bib, packages.bib]
biblio-style: apalike
link-citations: yes
---

# Prerequisites

This is a _sample_ book written in **Markdown**. You can use anything that Pandoc's Markdown supports, e.g., a math equation $a^2 + b^2 = c^2$.

For now, you have to install the development versions of **bookdown**, **rmarkdown**, and **knitr**:

```{r eval=FALSE}
install.packages(
c("bookdown", "knitr"),
repos = c("http://yihui.name/xran", "http://cran.rstudio.com")
)
```

Remember each Rmd file contains one and only one chapter.
1 change: 1 addition & 0 deletions preamble.tex
@@ -0,0 +1 @@
\usepackage{booktabs}
23 changes: 23 additions & 0 deletions style.css
@@ -0,0 +1,23 @@
.kable_wrapper {
border-spacing: 20px 0;
border-collapse: separate;
border: none;
margin: auto;
}
.kable_wrapper > tbody > tr > td {
vertical-align: top;
}
p.caption {
color: #777;
margin-top: 10px;
}
p code {
white-space: inherit;
}
pre {
word-break: normal;
word-wrap: normal;
}
pre code {
white-space: inherit;
}

0 comments on commit 68c601f

Please sign in to comment.