Skip to content

Commit

Permalink
fix handing of references to be consistent, add tex_native global tag…
Browse files Browse the repository at this point in the history
… for TeX articles
  • Loading branch information
s-u committed Nov 10, 2023
1 parent 583a738 commit fe32a9f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions R/rj_pdf_article.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ rjournal_pdf_article <- function(..., self_contained = FALSE) {
}
pre_processor <- fmt$pre_processor
fmt$pre_processor <- function(front_matter, input, ...) {
if(!is.null(front_matter$bibliography)) {
if(!is.null(front_matter$bibliography) && !isTRUE(front_matter$tex_native)) {
xfun::write_utf8(
c(xfun::read_utf8(input), "\n# References\n"),
input
Expand All @@ -51,7 +51,6 @@ rjournal_pdf_article <- function(..., self_contained = FALSE) {
file.rename(filename, filename2)
filename <- filename2
}

# Copy purl-ed R file with the correct name
dest_file <- xfun::with_ext(filename, "R")
our_file <- TRUE
Expand Down Expand Up @@ -79,6 +78,16 @@ rjournal_pdf_article <- function(..., self_contained = FALSE) {
temp_tex <- xfun::read_utf8(output_file)
# Add author line
temp_tex <- post_process_authors(temp_tex)
## remove CLS references if we are using native ones
## coversely, if CLS is already included, don't add TeX ones
if (isTRUE(metadata$tex_native)) {
cls.b <- grep("^\\\\begin\\{CSLReferences\\}", temp_tex)
cls.e <- grep("^\\\\end\\{CSLReferences\\}", temp_tex)
if (length(cls.b) == 1 && length(cls.e) == 1 && cls.b < cls.e)
temp_tex <- temp_tex[-(cls.b:cls.e)]
} else if (length(grep("^\\\\begin\\{CSLReferences\\}", temp_tex)) &&
length(bil <- grep("^\\\\bibliography", temp_tex)))
temp_tex <- temp_tex[-bil]
xfun::write_utf8(temp_tex, output_file)

# Bookdown post-processing, silently capture error as it will attempt to
Expand Down

0 comments on commit fe32a9f

Please sign in to comment.