forked from moderndive/ModernDive_book
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdf_build_from_tex.R
61 lines (54 loc) · 1.97 KB
/
pdf_build_from_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
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
57
58
59
60
61
# This script is used to create PDF of the book and all TeX files for CRC Press.
# Keep all the intermediary files so they can be copied below. This step also
# generates the .tex file in the `docs` folder
bookdown::render_book("index.Rmd", "bookdown::pdf_book",
clean = FALSE,
clean_envir = FALSE,
encoding = "UTF-8"
)
# Rename the PDF generated by bookdown in the lines above so it isn't
# overwritten when Compile PDF from .tex file done below
file.rename(
from = here::here("docs", "moderndive.pdf"),
to = here::here("docs", paste0("moderndive_", Sys.Date(), ".pdf"))
)
# figure-latex is not automatically added to `docs` so need to copy it over to
# get R generated images as linked in .tex file
if (!dir.exists(here::here("docs", "moderndive_files", "figure-latex"))) {
dir.create(here::here("docs", "moderndive_files", "figure-latex"),
recursive = TRUE
)
}
file.copy(
from = here::here("_bookdown_files", "moderndive_files", "figure-latex"),
to = here::here("docs", "moderndive_files"),
recursive = TRUE
)
# Copy references over
if (!dir.exists(here::here("docs", "bib"))) {
dir.create(here::here("docs", "bib"))
}
file.copy(from = "bib", to = "docs", recursive = TRUE)
# For printing the PDF from the .tex file
if (!dir.exists("docs")) {
dir.create("docs")
}
file.copy("krantz.cls",
here::here("docs", "krantz.cls"),
overwrite = TRUE
)
# 1. Go to RStudio -> Preferences -> Sweave -> Typeset LaTeX into PDF
# - Change to XeLaTeX
# 2. Go to Tools -> Project Options -> Sweave >- Typeset LaTeX into PDF
# - Change to XeLaTeX
# 3. Now open up ModernDive.tex in `docs`` and press Compile PDF
# - The compiled PDF will be saved as ModernDive.pdf in `docs``
# 4. Compare to the other ModernDive_*.pdf generated above to
# ensure things look OK.
# Clean up extra files
extra_extensions <- c(
".bbl", ".blg", ".idx", ".ilg", ".ind",
".log", ".synctex.gz", ".toc", ".aux"
)
extra_files <- here::here("docs", paste0("ModernDive", extra_extensions))
file.remove(extra_files)