Skip to content

Commit

Permalink
add author list shortening
Browse files Browse the repository at this point in the history
  • Loading branch information
pfandzelter committed Jul 17, 2024
1 parent 8398ab4 commit fc35b03
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
GO_FILES := $(shell find . -name '*.go')

CURR_TAG := $(shell git describe --tags --always)
BUILD_TIME := $(shell date -u '+%Y-%m-%d-%I:%M:%S%p')
COMMIT := $(shell git rev-parse HEAD)
LD_FLAGS := -X main.version=$(CURR_TAG) -X main.date=$(BUILD_TIME) -X main.commit=$(COMMIT)

bibclean: bibclean.go fields.go pkg/
bibclean: bibclean.go fields.go $(GO_FILES)
go build -ldflags "$(LD_FLAGS)" -o bibclean .
2 changes: 1 addition & 1 deletion bibclean.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func main() {
newfile = flag.String("out", "", "output bibliography file")
bblfile = flag.String("bbl", "", "(optional) auxillary .bbl file to check which references have been used in the text")
defaults = flag.String("defaults", "ieee", "(optional) default data fields, can be \"ieee\" (for IEEEtran.bst), \"acm\" (for ACM-Reference-Format.bst), or \"biblatex\" (for biblatex)")
shorten = flag.String("shorten", "", "(optional) level of applied title shortening to conform with IEEE citation style, can be \"publication\" (shorten only proceeding and journal titles with some common abbreviations) or \"all\" (aggressive shortening including shortening titles, uses the full list of abbrevations)")
shorten = flag.String("shorten", "", "(optional) level of applied title shortening to conform with IEEE citation style, can be \"publication\" (shorten only proceeding and journal titles with some common abbreviations) or \"all\" (aggressive shortening including shortening titles and author list, uses the full list of abbrevations)")
noMerge = flag.Bool("no-merge", false, "(optional) disable merging repeated entries based on key. redundant values will be added as comments")
flag.Var(&additional, "additional", "Additional fields for entries: specify as many as you like in the form \"--additional=article:booktitle --additional=techreport:address\" (this will add a \"booktitle\" field to \"@article\" entries and an \"address\" field to \"@techreport\" entries)")

Expand Down
23 changes: 22 additions & 1 deletion pkg/bibtex/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,27 @@ func ShortenBooktitle(e Element) Element {
return e
}

// ShortenAuthors truncates the author list for more than three authors.
func ShortenAuthors(e Element) Element {
for key, val := range e.Tags {
if key != "author" {
continue
}

// check if there are more than three authors
r := regexp.MustCompile(`\sand.*and`)
if !r.MatchString(val) {
continue
}

// replace everything after the first author with "et al."
r = regexp.MustCompile(`\sand.*$`)
e.Tags[key] = r.ReplaceAllString(val, " and others\"")
}

return e
}

// ShortenAll replaces long words with approved short forms from IEEE.
func ShortenAll(e Element) Element {
for tag := range e.Tags {
Expand All @@ -227,5 +248,5 @@ func ShortenAll(e Element) Element {
}
}

return e
return ShortenAuthors(e)
}

0 comments on commit fc35b03

Please sign in to comment.