--- 
title: "Title of the Memoir"
author: "Authors' names"
date: "`r Sys.Date()`"
url: https://GitHubID.github.io/Repository/
github-repo: GitHubID/Repository
description: "Bookdown template based on LaTeX memoir class"
cover-image: "images/logo.png"
# Title page...
maintitlepage:
  epigraph: |
    This document is reproducible thanks to:
    \begin{itemize}
      \item \LaTeX and its class memoir (\url{http://www.ctan.org/pkg/memoir}).
      \item R (\url{http://www.r-project.org/}) and RStudio (\url{http://www.rstudio.com/})
      \item bookdown (\url{http://bookdown.org/}) and memoiR (\url{https://ericmarcon.github.io/memoiR/})
    \end{itemize}
  credits: |
    Name of the owner of the logo
    
    \url{http://www.company.com}
    
    An explanatory sentence.
    Leave an empty line for line breaks.
  logo: "images/logo.png"
# ... or a PDF cover
pdftitlepage: images/cover.pdf
# Language
lang: en-US
otherlangs: [fr-FR,it]
# Bibliography
bibliography: references.bib
# Citation style in HTML
# citation-style: chicago-author-date.csl # By default.
# LaTeX
documentclass: memoir
classoption:
  - extrafontsizes
  - onecolumn
  - openright
# Paper, font
papersize: A4
fontsize: 12pt
# Fonts installed by a package. LaTeX tex-gyre package must be installed for:
# mainfont: texgyretermes          # Times New Roman for the text
mainfontoptions:
  - Extension=.otf
  - UprightFont=*-regular
  - BoldFont=*-bold
  - BoldItalicFont=*-bolditalic
  - ItalicFont=*-italic
# mathfont: texgyretermes-math.otf # Times New Roman for equations
# memoir Style
MemoirChapStyle: daleif1           # or companion with large margins
MemoirPageStyle: Ruled             # or companion with large margins
# Margins
largemargins: false                # or true for large margins
smallmargin: 1.5in                 # outer margin (small).
largemargin: 3in                   # outer margin (large)
marginnote:  1.8in                 # note width in large margin
spinemargin: 1.5in                 # spine margin. Reduce to 1.2 with large margins.
uppermargin: 1.5in                 # upper margin
lowermargin: 1in                   # lower margin
# Table of contents
toc-depth: 2
# Section numbering
secnum-depth: section
# List of tables / Figures
lot: false
lof: true
# Bibliography
biblatexoptions:
  - backend=biber
  - style=authoryear-ibid  # or verbose-inote with large margins
# - pageref=true           # uncomment for verbose-inotes style
  - isbn=false
  - backref=true
  - giveninits=true
  - uniquename=init
  - maxcitenames=2
  - maxbibnames=150
  - sorting=nyt
  - sortcites=false
longbibliography: false    # if true, two columns and smaller font in PDF
# Chapter summary text
chaptersummary: In a Nutshell
# Back Cover
backcover:
  - language: english
    abstract: |
      English abstract, on the last page.
  
      This is a bookdown template based on LaTeX memoir class.
    keywords:
      - Keyword in English
      - As a list
    abstractlabel: Abstract
    keywordlabel: Keywords
backcoverfontsize: normalsize
# Figure cropping may be set to false if ghostscript is not installed
fig_crop: true
# URL color
urlcolor: blue
# Do not modify
site: bookdown::bookdown_site
always_allow_html: true
graphics: true
link-citations: true
colorlinks: true
csquotes: true
---

<!-- HTML code necessary for key messages --> 
<img src="images/trombone.png" alt="image" hidden/>

```{r}
#| label: DoNotModify
#| include: false
### Utilities. Do not modify.
# Installation of packages if necessary
install_packages <- function(packages) {
  install_package <- function(package) {
    if (!package %in% installed.packages()[, 1]) {
      install.packages(package, repos = "https://cran.rstudio.com/")
    }
  }
  invisible(sapply(packages, install_package))
}

# Basic packages
install_packages(c("bookdown", "formatR", "kableExtra", "magick", "ragg"))

# Chunk font size hook: allows size='small' or any valid Latex font size in chunk options
def.chunk.hook  <- knitr::knit_hooks$get("chunk")
knitr::knit_hooks$set(chunk = function(x, options) {
  x <- def.chunk.hook(x, options)
  ifelse(
    options$size != "normalsize", 
    paste0("\n \\", options$size,"\n\n", x, "\n\n \\normalsize"), 
    x
  )
})

# Output hook for full-width figures
defOut <- knitr::knit_hooks$get("plot")
knitr::knit_hooks$set(
  plot = function(x, options) {
    # Apply the original hook
    x <- defOut(x, options)
    # Only full-width figures
    if (options$out.width == "\\widthw") {
      # Modify output of the original hook, see code on:
      # https://github.com/yihui/knitr/blob/master/R/hooks-latex.R
      # Modify align1 output with align=center. Original code:
      # switch(a, left = '\n\n', center = '\n\n{\\centering ', right = '\n\n\\hfill{}', '\n')
      # replace centering by a minipage
      x  <- gsub(
        "\\n\\n\\{\\\\centering",
        "\\\\setbox0=\\\\hbox\\{\\\\begin\\{minipage\\}\\[h\\]\\{\\\\widthw\\}\\\\centering",
        x
      )
      # Modify align2 output with align=center. Original code:
      # switch(a, left = '\\hfill{}\n\n', '\n\n}\n\n', right = '\n\n', '')
      # replace } by the necessary code to place the minipage
      x  <- gsub(
        "\\n\\n\\}\\n\\n",
        "\\\\end\\{minipage\\}\\}\\\\needspace\\{\\\\ht0+\\\\dp0+2\\\\baselineskip\\}
          \\\\definesHSpace\\\\hspace\\{-\\\\rf\\}\\\\box0",
        x
      )
    }
    return(x)
  }
)

# Figures with side captions
if (rmarkdown::metadata$largemargins)
  knitr::opts_chunk$set(fig.env = 'SCfigure')
```

```{r}
#| label: Options
#| include: false
### Customized options for this document
# Add necessary packages here
packages <- c("tidyverse")
# Install them
install_packages(packages)
# Create packages.bib file to reference them as @R-package
knitr::write_bib(packages, file = "packages.bib")

# knitr options
knitr::opts_chunk$set(
  cache =   FALSE,    # Cache chunk results
  include = TRUE,     # Show/Hide chunks
  echo =    TRUE,     # Show/Hide code
  warning = FALSE,    # Show/Hide warnings
  message = FALSE,    # Show/Hide messages
  # Figure alignment and size
  fig.align = 'center', out.width = '80%', fig.asp = .75,
  # Graphic devices (ragg_png is better than standard png)
  dev = c("ragg_png", "pdf"),
  # Code chunk format
  tidy = TRUE, tidy.opts = list(blank = FALSE, width.cutoff = 60),
  size = "scriptsize", knitr.graphics.auto_pdf = TRUE
  )
options(width = 60)

# ggplot style
library("tidyverse")
theme_set(theme_bw())
theme_update(
  panel.background = element_rect(fill = "transparent", colour = NA),
  plot.background = element_rect(fill = "transparent", colour = NA)
)
knitr::opts_chunk$set(dev.args = list(bg = "transparent"))

# Random seed
set.seed(973)
```


# Introduction {-}

This document allows you to create a book in PDF format (and ePub format) at the same time as an HTML version to be published on the web.
The syntax is that of **Markdown** with some extensions.

The **bookdown** package must be installed from CRAN or GitHub:

```{r}
#| label: bookdown
#| eval: false
install.packages("bookdown")
# or the development version
# devtools::install_github("rstudio/bookdown")
```

The book is organized in chapters. 
Each chapter is an Rmd file, whose name normally begins with its number (e.g. `01-intro.Rmd`).
All Rmd files in the project folder are actually treated as chapters, sorted by filename.
The index.Rmd file is special: it contains the document header and the first chapter.

This first chapter is placed in the foreword of the printed book: it should not be numbered (hence the `{-}` code next to the title) in the HTML version.
It must end with the LaTeX command `\mainmatter` which marks the beginning of the body of the book.

The outline levels start with `#` for chapters (only one per file), `##` for sections, etc.

Compilation in PDF format is done by XeLaTeX, which must be installed.

While writing, it is strongly advised to create only the HTML file, which is much faster than a LaTeX compilation.
Each chapter can be viewed very quickly by clicking on the _Knit_ button above the source window.
The entire book is created by clicking on the _Build Book_ button in the RStudio _Build_ window.
The button's drop-down list allows you to create all documents or limit yourself to one format.

<!-- The \mainmatter command marks the beginning of the LaTeX document body--> 
<!-- It must not be deleted-->
\mainmatter
