R/uc_rmd.R

Defines functions UC_word_document UC_pdf_document UC_html_document

Documented in UC_html_document UC_pdf_document UC_word_document

#' Rbearcat HTML document
#'
#' An R Markdown output format for HTML documents.
#'
#' @param number_sections logical. Set to \code{FALSE} to leave sections unnumbered.
#' @param toc logical. set to \code{FALSE} to excluded the table of contents side-bar.
#' @param toc_depth number of layers in TOC.
#' @param ... other options passed to \code{bookdown::html_document2}.
#' See \code{\link[bookdown]{html_document2}}
#' and \code{\link[rmarkdown]{html_document}} for all available options.
#' @param css relative path to a css formatting document.
#' If \code{NULL} (default), function will use the style.css file included with the package.
#'
#' @return An \code{rmarkdown::output_format} object for rendering HTML
#'   documents.
#'
#' @author Saannidhya Rawat
#' @export
#'
UC_html_document <- function(number_sections = FALSE,
                               toc = TRUE,
                               toc_depth = 2,
                               css = NULL,
                               ...){

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

  bookdown::html_document2(
    css = css,
    highlight = "tango",
    theme = "default",
    number_sections = number_sections,
    toc = toc,
    toc_depth = toc_depth,
    toc_float = list(collapsed = TRUE,
                     smooth_scroll = TRUE),
    ...
  )

}

#' Rbearcat PDF document
#'
#' An R Markdown output format for PDF documents.
#'
#' @param number_sections logical. Set to \code{TRUE} to number sections.
#' @param toc logical. set to \code{TRUE} to include a table of contents.
#' @param toc_depth number of layers in TOC.
#' @param highlight_bw set to \code{TRUE} to convert colors in syntax
#' highlighted code blocks to grayscale.
#' @param ... other options passed to \code{bookdown::pdf_document2}.
#' See \code{\link[bookdown]{pdf_document2}}
#' and \code{\link[rmarkdown]{pdf_document}} for all available options.
#' @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.
#'
#' @return An \code{rmarkdown::output_format} object for rendering PDF
#'   documents.
#'
#' @author Saannidhya Rawat
#' @export
#'
UC_pdf_document <- function(number_sections = FALSE,
                              toc = FALSE,
                              toc_depth = 2,
                              highlight_bw = FALSE,
                              in_header = NULL,
                              ...){

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

  bookdown::pdf_document2(
    includes = rmarkdown::includes(in_header = in_header),
    highlight = "tango",
    latex_engine = "xelatex",
    citation_package = "natbib",
    number_sections = number_sections,
    toc = toc,
    toc_depth = toc_depth,
    highlight_bw = highlight_bw,
    ...
  )

}

#' Rbearcat word document
#'
#' An R Markdown output format for Word documents (docx).
#'
#' @param toc logical. set to \code{TRUE} to include a table of contents.
#' @param toc_depth number of layers in TOC.
#' @param reference_docx relative path to a docx reference document.
#' If \code{NULL} (default), function will use the style.docx file included with the package.
#' @param ... other options passed to \code{bookdown::word_document2}.
#' See \code{\link[bookdown]{word_document2}}
#' and \code{\link[rmarkdown]{word_document}} for all available options.
#'
#' @return An \code{rmarkdown::output_format} object for rendering Word
#'   documents.
#'
#' @author Saannidhya Rawat
#' @export
#'
#'

UC_word_document <- function(toc = FALSE,
                               toc_depth = 2,
                               reference_docx = NULL,
                               ...){

  if (is.null(reference_docx)) {
    reference_docx <- system.file("rmarkdown", "templates", "bcat_rmd" ,"assets", "word",
                                  "style.docx", package = "Rbearcat")
  }

  bookdown::word_document2(
    reference_docx = reference_docx,
    highlight = "tango",
    toc = toc,
    toc_depth = toc_depth,
    fig_caption = FALSE,
    number_sections = FALSE,
    ...
  )

}

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.