rss_article.R 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #' Royal Statistical Society Journal Format
  2. #'
  3. #' Format for creating articles for Royal Statistical Society
  4. #' Adapted from \url{https://www.rss.org.uk/RSS/Publications/Journals/Journals_get_involved/RSS/Publications/Journals_sub/Get_Involved.aspx}
  5. #' @inheritParams rmarkdown::pdf_document
  6. #' @param ... Arguments to \code{rmarkdown::pdf_document}
  7. #'
  8. #' @return R Markdown output format to pass to
  9. #' \code{\link[rmarkdown:render]{render}}
  10. #' @export
  11. #'
  12. rss_article <- function(...,
  13. keep_tex = TRUE,
  14. citation_package = "natbib") {
  15. fmt <- rmarkdown::pdf_document(
  16. ...,
  17. highlight = NULL,
  18. citation_package = citation_package,
  19. template =
  20. system.file("rmarkdown",
  21. "templates",
  22. "rss_article",
  23. "resources",
  24. "template.tex",
  25. package = "rticles"),
  26. keep_tex = keep_tex
  27. )
  28. fmt$inherits <- "pdf_document"
  29. fmt$knitr$knit_hooks$source <- function(x, options) {
  30. if (options$prompt && length(x)) {
  31. x <- gsub("\\n", paste0("\n", getOption("continue")), x)
  32. x <- paste0(getOption("prompt"), x)
  33. }
  34. paste0(
  35. c(
  36. '\n\\begin{lstlisting}[language=',
  37. options$engine,
  38. "]",
  39. x,
  40. '\\end{lstlisting}',
  41. ''
  42. ),
  43. collapse = '\n'
  44. )
  45. }
  46. fmt
  47. }