R/utils.R

Defines functions find_resource refs_here

Documented in refs_here

find_resource <- function(template, file = 'template.tex') {
  res <- system.file(
    "rmarkdown", "templates", template, "resources", file, package = "CHL5202"
  )
  if (res == "") stop(
    "Couldn't find template file ", template, "/resources/", file, call. = FALSE
  )
  res
}

#' @title Place References.
#'
#' @description Function for placing references. This function writes LaTeX and HTML code behind-the-scenes so you don't have to.
#'
#' @param x String to be rendered by \code{knitr::\link[knitr]{asis_output}}.
#'
#' @return NULL
#'
#' @examples
#' \dontrun{
#' refs_here()
#' }
#'
#' @export

refs_here <- function(x = '') {
  assertthat::assert_that(is.character(x))
  if (knitr::is_latex_output()) {
    x <- glue::glue(
      '\\noindent',
      '\\setlength{\\parindent}{-0.20in}',
      '\\setlength{\\leftskip}{0.20in}',
      '\\setlength{\\parskip}{8pt}',
      '<<x>>',
      '<div id="refs"></div>',
      .sep = '\n', .open = '<<', .close = '>>'
    )
    knitr::asis_output(x)
  } else {
    knitr::asis_output(
      glue::glue('{x}', '<div id="refs"></div>', .sep = '\n')
      )
  }
}
mattwarkentin/CHL5201 documentation built on March 2, 2020, 5:33 a.m.