-
Notifications
You must be signed in to change notification settings - Fork 0
/
render.R
57 lines (44 loc) · 1.45 KB
/
render.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Script to render Rmd to PDF and docx
# Define custom functions ----
#' Convert latex file to docx
#'
#' Requires pandoc to be installed and on command line
#'
#' @param latex Path to input latex file.
#' @param docx Path to output docx file.
#' @param template Path to template docx file.
#' @param wd Working directory to run conversion. Should be same as
#' directory containing any files needed to render latex to pdf.
#'
#' @return List including STDOUT of pandoc; externally, the
#' docx file will be rendered in `wd`.
#'
latex2docx <- function(latex, docx, template = NULL, wd = getwd()) {
assertthat::assert_that(assertthat::is.readable(latex))
assertthat::assert_that(assertthat::is.dir(fs::path_dir(docx)))
latex <- fs::path_abs(latex)
docx <- fs::path_abs(docx)
template <- if (!is.null(template)) {
glue::glue("--reference-doc={fs::path_abs(template)}")
} else {
NULL
}
processx::run(
command = "pandoc",
args = c("-s", latex, template, "-o", docx),
wd = wd
)
}
# Render docs ----
# - PDF
rmarkdown::render(
"net_energy_equity_springer/net_energy_equity_springer.Rmd",
output_dir = "net_energy_equity_springer"
)
# - docx
latex2docx(
latex = "net_energy_equity_springer/net_energy_equity_springer.tex",
docx = "net_energy_equity_springer/net_energy_equity_springer.docx",
template = "sv-journ.dot",#here::here("ms/new-phytologist.docx"),
wd = getwd()#here::here("net_energy_equity_springer")
)