-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArXiv.R
47 lines (35 loc) · 1.79 KB
/
ArXiv.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
args <- commandArgs(trailingOnly = TRUE)
ms_to_ArXiv <- function(file_name) {
tmp_file <- readLines(file_name)
tmp_file <- gsub("figure/", "", tmp_file)
tmp_file <- gsub("\\linenumbers", "", tmp_file, fixed = TRUE)
tmp_file <- gsub("\\nolinenumber", "", tmp_file, fixed = TRUE)
lineno_pkg <- which(grepl('lineno', tmp_file))
tmp_file <- c(tmp_file[1:(lineno_pkg - 1)], tmp_file[(lineno_pkg + 1):length(tmp_file)])
# geometry_line <- which(grepl("{geometry}", tmp_file, fixed = TRUE))
# tmp_file[geometry_line] <- "\\usepackage[top=0.85in,left=1.5in,footskip=0.75in]{geometry}"
# tmp_file <- gsub("bib-haiti", 'ms', tmp_file)
bib_spot <- which(grepl("\\bibliography{bib-haiti,bib-lit}", tmp_file, fixed = TRUE))
bib_content <- readLines(gsub("\\.tex", "\\.bbl", file_name))
new_file <- c(tmp_file[1:(bib_spot - 1)], bib_content, tmp_file[(bib_spot + 1):length(tmp_file)])
writeLines(new_file, con = file_name)
}
si_to_ArXiv <- function() {
tmp_file <- readLines("ArXiv/si.tex")
tmp_file <- gsub("inputs/", "", tmp_file)
tmp_file <- gsub("figure/", "", tmp_file)
# tmp_file <- gsub("../bib-haiti", 'ms', tmp_file)
input_lines <- which(grepl("\\\\input\\{([^}]*)\\}", tmp_file))
input_files <- paste0(gsub("\\\\input\\{|\\}", "", tmp_file[input_lines]), ".tex")
for (i in 1:length(input_files)) {
tmp_input_file <- readLines(paste0("ArXiv/", input_files[i]))
tmp_input_file <- gsub("figure/", "", tmp_input_file)
writeLines(tmp_input_file, con = paste0("ArXiv/", input_files[i]))
}
bib_spot <- which(grepl("bib-haiti", tmp_file, fixed = TRUE))
bib_content <- readLines("ArXiv/si.bbl")
new_file <- c(tmp_file[1:(bib_spot - 1)], bib_content, tmp_file[(bib_spot + 1):length(tmp_file)])
writeLines(new_file, con = "ArXiv/si.tex")
}
ms_to_ArXiv(args[1])
si_to_ArXiv()