forked from Hendrik147/HR_Analytics_in_R_book
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdf_build_from_tex.R
46 lines (38 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
# 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 = "docs/moderndive.pdf",
to = paste0("docs/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("docs/moderndive_files/figure-latex"))
dir.create("docs/moderndive_files/figure-latex", recursive = TRUE)
file.copy(from = "_bookdown_files/moderndive_files/figure-latex",
to = "docs/moderndive_files",
recursive = TRUE)
# Copy references over
if(!dir.exists("docs/bib")) dir.create("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", "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 docs/ModernDive.tex and press Compile PDF
# - The compiled PDF will be saved as docs/ModernDive.pdf
# 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 <- paste0("docs/ModernDive", extra_extensions)
file.remove(extra_files)
# 5. Copy docs folder to Google Drive in moderndive_{Sys.Date()} folder
# Couldn't figure out a way to automate this with the nesting of folders