ieee_article.R 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #' IEEE Transactions journal format.
  2. #'
  3. #' Format for creating submissions to IEEE Transaction journals. Adapted from
  4. #' \href{http://www.ieee.org/publications_standards/publications/authors/author_templates.html}{http://www.ieee.org/publications_standards/publications/authors/author_templates.html}.
  5. #'
  6. #' @inheritParams rmarkdown::pdf_document
  7. #' @param draftmode Specify the draft mode to control spacing and whether images
  8. #' should be rendered. Valid options are: \code{"final"} (default), \code{"draft"},
  9. #' \code{"draftcls"}, or \code{"draftclsnofoot"}.
  10. #' @param hyphenfixes A \code{character} value that provides the correct
  11. #' hyphenations for ambiguous words. Separate new words with spaces.
  12. #' @param IEEEspecialpaper A \code{character} value containing the publication's
  13. #' special paper designation.
  14. #' @param with_ifpdf A \code{logical} value turning on (\code{TRUE}) or off
  15. #' (\code{FALSE}) the \code{ifpdf} LaTeX package.
  16. #' @param with_cite A \code{logical} value turning on (\code{TRUE}) or off
  17. #' (\code{FALSE}) the \code{cite} LaTeX package.
  18. #' @param with_amsmath A \code{logical} value turning on (\code{TRUE}) or off
  19. #' (\code{FALSE}) the \code{amsmath} LaTeX package.
  20. #' @param with_algorithmic A \code{logical} value turning on (\code{TRUE}) or
  21. #' off (\code{FALSE}) the \code{algorithmic} LaTeX package.
  22. #' @param with_subfig A \code{logical} value turning on (\code{TRUE}) or off
  23. #' (\code{FALSE}) the \code{subfig} LaTeX package.
  24. #' @param with_array A \code{logical} value turning on (\code{TRUE}) or off
  25. #' (\code{FALSE}) the \code{array} LaTeX package.
  26. #' @param with_dblfloatfix A \code{logical} value turning on (\code{TRUE}) or
  27. #' off (\code{FALSE}) the \code{dblfloatfix} LaTeX package.
  28. #' @param ... Additional arguments to \code{rmarkdown::pdf_document}
  29. #'
  30. #' @return R Markdown output format to pass to
  31. #' \code{\link[rmarkdown:render]{render}}
  32. #'
  33. #' @examples
  34. #'
  35. #' \dontrun{
  36. #' library(rmarkdown)
  37. #' draft("MyArticle.Rmd", template = "ieee_article", package = "rticles")
  38. #' }
  39. #'
  40. #' @details
  41. #' Presently, only the \code{"conference"} paper mode offered by the
  42. #' \code{IEEEtran.cls} is supported.
  43. #'
  44. #' @references
  45. #' Shell, Michael. "How to use the IEEEtran LATEX class." Journal of LATEX Class
  46. #' Files 1.11 (2002): 10-20.
  47. #' \url{http://mirrors.rit.edu/CTAN/macros/latex/contrib/IEEEtran/IEEEtran_HOWTO.pdf}
  48. #' @export
  49. ieee_article <- function(...,
  50. draftmode = c("final", "draft", "draftcls",
  51. "draftclsnofoot"),
  52. hyphenfixes = "op-tical net-works semi-conduc-tor",
  53. IEEEspecialpaper = "",
  54. with_ifpdf = FALSE,
  55. with_cite = FALSE,
  56. with_amsmath = FALSE,
  57. with_algorithmic = FALSE,
  58. with_subfig = FALSE,
  59. with_array = FALSE,
  60. with_dblfloatfix = FALSE,
  61. keep_tex = TRUE,
  62. md_extensions = c("-autolink_bare_uris")) {
  63. args <- c()
  64. draftmode <- match.arg(draftmode)
  65. args <- c(args, "draftmode" = draftmode)
  66. args <- c(args, "hyphenfixes" = hyphenfixes)
  67. # Avoid declaration of pandoc variable if field is empty
  68. if(nchar(IEEEspecialpaper) > 1){
  69. args <- c(args, "IEEEspecialpaper" = IEEEspecialpaper)
  70. }
  71. plist <- c("with_ifpdf" = with_ifpdf,
  72. "with_cite" = with_cite,
  73. "with_amsmath" = with_amsmath,
  74. "with_algorithmic" = with_algorithmic,
  75. "with_subfig" = with_subfig,
  76. "with_array" = with_array,
  77. "with_dblfloatfix" = with_dblfloatfix)
  78. # Obtain only variables that should be turned on
  79. requested_withs <- sapply(plist, isTRUE)
  80. args <- c(args, plist[requested_withs])
  81. # pandoc_variable_arg not exported from rmarkdown
  82. pandoc_arg_variable = function(var_name, value){
  83. c("-V", paste0(var_name, "=", value))
  84. }
  85. # Convert to pandoc arguments
  86. pandoc_arg_list <- mapply(pandoc_arg_variable, names(args), args)
  87. inherit_pdf_document(...,
  88. pandoc_args = pandoc_arg_list,
  89. template = find_resource("ieee_article", "template.tex"),
  90. keep_tex = keep_tex,
  91. md_extensions = md_extensions)
  92. }