chapter_numbering yaml option: turn numbering off or start at a value

The automatic chapter numbering can now be controlled from the yaml
header. The default TRUE numbers the # chapters from 1 as before.
chapter_numbering: false turns the numbering off -- headings keep
exactly what was typed, including manually typed numbers, and the
overview TOC shows the titles as typed (the numbering script is not
emitted at all). A number starts the enumeration at that value, e.g.
chapter_numbering: 5 for a continuation deck; references, appendix and
thank-you chapters stay excluded and uncounted in every mode.

Change-Id: I69af1414aedd14c9be09650c78b3219bf63c4d1a
diff --git a/R/revealjs_presentation.R b/R/revealjs_presentation.R
index d93e617..31c14f1 100644
--- a/R/revealjs_presentation.R
+++ b/R/revealjs_presentation.R
@@ -124,7 +124,9 @@
 #' the overview slide's table of contents uses them as its ordered list's
 #' enumeration. Decks rendered with `slide_level = 1` (one `#` heading per
 #' slide) are left unnumbered -- there, headings denote slides, not
-#' chapters.
+#' chapters. The numbering can be turned off with `chapter_numbering: false`
+#' in the yaml header, or started at another number with e.g.
+#' `chapter_numbering: 5` (useful for continuation decks).
 #' 
 #' ## Overview slides
 #' 
@@ -225,6 +227,13 @@
 #'   produced, with level 1 headers building horizontally and level 2 headers
 #'   building vertically. It is not recommended that you use deeper nesting of
 #'   section levels with reveal.js.
+#' @param chapter_numbering `TRUE` (the default) numbers the `#` chapter
+#'   headings automatically ("1. Introduction", "2. Methods", ...), skipping
+#'   references, appendix and thank-you chapters. `FALSE` turns the numbering
+#'   off -- headings keep exactly what was typed, including any manually
+#'   typed numbers. A number starts the enumeration at that value:
+#'   `chapter_numbering = 5` numbers the first chapter "5." (useful for
+#'   continuation decks).
 #' @param theme Visual theme. The dedicated IDS corporate design theme
 #'   ("ids") is the default and the only supported theme.
 #' @param transition Slide transition (
@@ -278,6 +287,7 @@
 revealjs_presentation <- function(incremental = FALSE,
                                   center = FALSE,
                                   slide_level = 2,
+                                  chapter_numbering = TRUE,
                                   toc = FALSE,
                                   toc_depth = 3,
                                   fig_width = 8,
@@ -326,6 +336,21 @@
   # slide level
   args <- c(args, "--slide-level", as.character(slide_level))
 
+  # chapter numbering: FALSE disables the automatic "1. ", "2. " prefixes on
+  # chapter headings; a number starts the enumeration at that value (useful
+  # e.g. for continuation decks). TRUE, the default, numbers from 1.
+  if (identical(chapter_numbering, FALSE)) {
+    args <- c(args, pandoc_variable_arg("chapter-numbering-off"))
+  } else if (is.numeric(chapter_numbering)) {
+    if (chapter_numbering != 1) {
+      args <- c(args, pandoc_variable_arg(
+        "chapter-numbering-start", as.integer(chapter_numbering)
+      ))
+    }
+  } else if (!isTRUE(chapter_numbering)) {
+    stop("chapter_numbering must be TRUE, FALSE or a number", call. = FALSE)
+  }
+
   # theme
   theme <- match.arg(theme, revealjs_themes())
   if (identical(theme, "default")) {