forked from Robinlovelace/spatial-microsim-book
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.R
93 lines (78 loc) · 2.68 KB
/
build.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# TODO for the book project overall
# Individual chapters on eprints
# Implement regex to make bibliography happen in CRC press style
# Add urls to all the references and packages
# Propensity to cycle
# IPF in R/loglin/mipfp/GREGWT
# Reference UrbanSim
# Chapter summaries at outset?
# Mention of collaborative project early on
# file.copy(from = "~/Documents/smr.bib", to = "bibliography.bib", overwrite = T)
# View the order chapters will be knitted (see R/book-functions.R)
# chap_ord <- c(7,16,10,5,12,2,8,4,13,14,15,11,1,3,6,9)
cfiles <- list.files(pattern = "*.Rmd$")
# cfiles <- cfiles[chap_ord] # chapter order
cfiles
# Add book header
book_header = readLines(textConnection('---
title: "Spatial microsimulation with R"
output:
\ \ pdf_document:
\ \ \ \ fig_caption: yes
\ \ \ \ highlight: monochrome
\ \ \ \ includes: null
\ \ \ \ keep_tex: yes
\ \ \ \ number_sections: yes
\ \ \ \ toc: yes
bibliography: bibliography.bib
csl: elsevier-harvard.csl
layout: default
---'))
source("R/book-functions.R")
# file.remove("book.Rmd")
# Rmd_bind(book_header = book_header)
Rmd_bind_mod(book_header = book_header)
# Packages needed to build the book
# install.packages("knitr", "rmarkdown", "png", "ggmap", "dplyr", "ipfp")
library(knitr)
library(rmarkdown)
# Build the book:
render("book.Rmd", output_format = "pdf_document")
# Build the CRC-formated version - requires local files
# need to build the .tex manually for references to compile
source("R/build-CRC-version.R")
# Make latex-specific changes automated
booktex <- readLines("spatial-microsim-book.tex")
booktex[grep("\\{Glossary\\}", booktex)]
booktex <- gsub(pattern = "chapter\\{Glossary\\}", "chapter*\\{Glossary\\}\n\\\\addcontentsline{toc}{chapter}{Glossary}
", booktex)
writeLines(booktex, "spatial-microsim-book.tex")
# in case index does not build - run again!
# system("pdflatex --interaction=nonstopmode spatial-microsim-book.tex")
# For website build see gh-pages version
# Files to move to gh-pages branch
# file.remove("book.Rmd")
# Remove latex-specific document links for website
cfiles <- list.files("/tmp", pattern = "*.Rmd", full.names = T)
for(i in cfiles){
text <- readLines(i)
sel <- grepl("\\(\\#", text)
text <- text[!sel]
writeLines(text, con = i)
}
# # # regex with R - convert book ready for regexxing
# d <- readLines("introduction.Rmd")
# sel <- grep("@", d)
# s <- d[sel]
# gsub(".+?(?=a)", replacement = "", s, perl = T) # test of greedy matching
#
# # select quotes
#
# s <- grep(" @", d)
# s <- grep("\\ @|\\[@", d)
# d[s]
# backup
# system("cp -rv ~/Dropbox/spatial-microsim-book /media/robin/data/backups/")
# command-line tools for dif tracking
# latexdiff book-b4-comments.tex book.tex > dif.tex
# pdflatex dif.tex