-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat_bib.R
106 lines (84 loc) · 3.96 KB
/
format_bib.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
93
94
95
96
97
98
99
100
101
102
103
104
105
library(dplyr)
library(bibtex)
library(htmltools)
library(RefManageR)
#-------------------#
# Make bibliography
#-------------------#
# bibliography items
embedURL <- RefManageR:::MakeBibLaTeX()
# Create modifications for Article, and Misc types
with(embedURL,{
embedURL$fmtJTitle <- function (paper) {
title <- paper$title
url <- paper$url
if (!is.null(title) & !is.null(url))
if (grepl("[.?!]$", title, useBytes = TRUE))
paste0("\\dQuote{", paste0("[", collapse(cleanupLatex(title)),
"](", url, ")"), "}")
else paste0("\\dQuote{", paste0("[", collapse(cleanupLatex(title)),
"](", url, ")"), "}. ")
else if (!is.null(title))
if (grepl("[.?!]$", title, useBytes = TRUE))
paste0("\\dQuote{", collapse(cleanupLatex(title)), "}")
else paste0("\\dQuote{", collapse(cleanupLatex(title)), "}. ")
}
embedURL$formatArticle <- function (paper) {
collapse(c(fmtPrefix(paper), fmtBAuthor(paper), fmtJTitle(paper),
fmtAddOn(paper$titleaddon), fmtLanguage(paper$language),
fmtTranslator(paper), fmtCommentator(paper$commentator),
fmtAnnotator(paper$annotator), fmtVersion(paper$version),
sentenceP(paste0(c(paste0(c(fmtJournal(paper), fmtSeries(paper$series)),
collapse = ""), fmtVolume(paper$volume, paper$number),
fmtJournDate(paper)), collapse = " "),
fmtBTitle(paper$issuetitle, paper$issuesubtitle),
fmtEditor(paper, suffix = NULL, prefix = ". "),
fmtNote(paper$note, prefix = ". ", suffix = NULL),
pgs = fmtPages(paper$pages, paper$pagination),
sep = ""), fmtISSN(paper$issn), fmtDOI(paper$doi),
fmtEprint(paper), fmtAddendum(paper$addendum),
fmtPubstate(paper$pubstate)))
}
embedURL$formatMisc <- function (paper) {
collapse(c(fmtPrefix(paper), fmtBAuthor(paper), fmtJTitle(paper),
fmtAddOn(paper$titleaddon), fmtLanguage(paper$language),
fmtEditor(paper, !length(paper$author)), fmtHowPublished(paper$howpublished),
addPeriod(fmtType(paper$type)), fmtVersion(paper$version),
fmtNote(paper$note), sentence(fmtPublisher(paper$organization,
paper$location, paper$address),
fmtDate(attr(paper, "dateobj")), sep = ""),
fmtDOI(paper$doi), fmtEprint(paper),
fmtAddendum(paper$addendum),
fmtPubstate(paper$pubstate)))
}
})
# Register bibliography
tools::bibstyle("embedURL", embedURL)
# Set options
BibOptions(bib.style = "embedURL", match.author = "exact",
sorting = 'ydnt', max.names = 99, first.inits = FALSE,
style = "text", no.print.fields = c("doi", "urldate", "issn", "note"))
bold_name <- function(refsList){
# add delim, and split entries
refsList[which(nchar(refsList) == 0)] <- "<DELIM>"
paste0(refsList, collapse = " ") %>%
strsplit(split = "<DELIM>") %>%
unlist() -> entries
# bold my name
entries <- gsub("Harrigan, Caitlin F.", "<b>Harrigan, Caitlin F.</b>", fixed = T, entries)
entries <- gsub("Caitlin F. Harrigan", "<b>Caitlin F. Harrigan</b>", fixed = T, entries)
entries <- gsub("Harrigan, Caitlin", "<b>Harrigan, Caitlin</b>", fixed = T, entries)
entries <- gsub("Caitlin Harrigan", "<b>Caitlin Harrigan</b>", fixed = T, entries)
# remove numeric if necessary
#entries <- gsub('\\[', '', entries)
#entries <- gsub('\\]', '.', entries)
return(entries)
}
print_publications <- function(refs){
refs <- refs %>%
PrintBibliography() %>%
capture.output() %>%
bold_name() %>%
unlist()
paste(paste0(1:length(refs), '. ', refs, '\n'), collapse = '')
}