/
render-tex.R
29 lines (26 loc) · 1.24 KB
/
render-tex.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
library("methods") # avoids weird broom error
library("rmarkdown")
tex_chapter <- function (chapter = NULL, latex_engine = c("xelatex", "pdflatex",
"lualatex"), code_width = 65) {
options(digits = 3)
set.seed(1014)
latex_engine <- match.arg(latex_engine)
rmarkdown::output_format(rmarkdown::knitr_options("html", chapter),
rmarkdown::pandoc_options(to = "latex",
from = "markdown_style",
ext = ".tex",
args = c("--top-level-division=chapter",
rmarkdown::pandoc_latex_engine_args(latex_engine))
),
clean_supporting = FALSE)
}
path <- commandArgs(trailingOnly = TRUE)
# command line args should contain just one chapter name
if (length(path) == 0) {
message("No input supplied")
} else {
base <- tex_chapter()
base$knitr$opts_knit$width <- 67
base$pandoc$from <- "markdown"
rmarkdown::render(path, base, output_dir = "book/tex", envir = globalenv(), quiet = TRUE)
}