R/bcat_book.R

Defines functions bcat_pdf_book bcat_gitbook

Documented in bcat_gitbook bcat_pdf_book

#' Rbearcat Gitbook
#'
#' An R Markdown output format for the Gitbook format (HTML).
#'
#' @param css relative path to a css formatting document.
#' If \code{NULL} (default), function will use the style.css file included with the package.
#' @param after_body relative path to HTML file to include after body of each chapter.
#' If \code{NULL} (default), function will use the footer.html file included with the package.
#' @param collapse specify level at which to collapse the table of contents.
#' @param ... other options passed to \code{bookdown::gitbook}
#'
#' @return An \code{rmarkdown::output_format} object for rendering Gitbook output.
#'
#' @author Saannidhya Rawat
#' @export
#'
bcat_gitbook <- function(css = NULL,
                         after_body = NULL,
                         collapse = "subsection",
                         ...){

  if (is.null(css)) {
    css <- system.file("bookdown", "assets", "css",
                       "style.css", package = "Rbearcat")
  }

  if (is.null(after_body)){
    after_body <- system.file("bookdown", "assets", "css",
                              "footer.html", package = "Rbearcat")
  }

  bookdown::gitbook(css = css,
                    keep_md = TRUE,
                    includes = rmarkdown::includes(after_body = after_body),
                    config = list(sharing = NULL,
                                  toc = list(collapse = collapse,
                                             scroll_highlight = TRUE),
                                  download = "PDF"),
                    ...)

}

#' Rbearcat PDF Book
#'
#' An R Markdown output format for the PDF books.
#'
#' @param in_header relative path to a tex formatting document included in the preamble.
#' If \code{NULL} (default), function will use the preamble.tex file included with the package.
#' @param before_body relative path to a tex document included in before the body of the document.
#' If \code{NULL} (default), function will use the before_body.tex file included with the package.
#' @param toc_depth depth of headers to include in table of contents
#' @param ... other options passed to \code{bookdown::pdf_book}
#'
#' @return An \code{rmarkdown::output_format} object for rendering PDF books.
#'
#' @author Saannidhya Rawat
#' @export
#'
bcat_pdf_book <- function(in_header = NULL,
                          before_body = NULL,
                          toc_depth = 4,
                          ...){

  if (is.null(in_header)) {
    in_header <- system.file("bookdown", "assets", "latex",
                             "preamble.tex", package = "Rbearcat")
  }

  if (is.null(before_body)){
    before_body <- system.file("bookdown", "assets", "latex",
                               "before_body.tex", package = "Rbearcat")
  }

  bookdown::pdf_book(includes = rmarkdown::includes(in_header = in_header,
                                                    before_body = before_body),
                     latex_engine = "xelatex",
                     citation_package = "natbib",
                     keep_tex = TRUE,
                     toc_appendix = TRUE,
                     toc_bib = TRUE,
                     toc_depth = toc_depth,
                     ...)

}

Try the Rbearcat package in your browser

Any scripts or data that you put into this service are public.

Rbearcat documentation built on March 21, 2026, 5:07 p.m.