From cb77db609312afaf82df85d3686a10e96a013227 Mon Sep 17 00:00:00 2001 From: "Mathew W. McLean" Date: Mon, 7 Oct 2024 19:03:30 +1100 Subject: [PATCH 1/5] Remove appveyor CI Signed-off-by: Mathew W. McLean --- .appveyor.yml | 63 --------------------------------------------------- 1 file changed, 63 deletions(-) delete mode 100644 .appveyor.yml diff --git a/.appveyor.yml b/.appveyor.yml deleted file mode 100644 index cf67ef5..0000000 --- a/.appveyor.yml +++ /dev/null @@ -1,63 +0,0 @@ -init: - ps: | - $ErrorActionPreference = "Stop" - Invoke-WebRequest https://raw.github.com/krlmlr/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1" - Import-Module '..\appveyor-tool.ps1' -install: - ps: Bootstrap - - -cache: - - C:\RLibrary - -environment: - matrix: - - R_VERSION: devel - POPPLERQT5FILE: 'dev\windows\appveyor\poppler-qt5-debug.zip' - CRAN: https://cran.rstudio.com - - R_VERSION: release - RTOOLS_VERSION: 32 - CRAN: https://cran.rstudio.com - POPPLERQT5FILE: 'dev\windows\appveyor\poppler-qt5-debug.zip' - global: - NOT_CRAN: true - -build_script: - - travis-tool.sh install_deps -# - travis-tool.sh install_r devtools -# - Rscript -e 'devtools::install_github("romainfrancois/bibtex")' -# - travis-tool.sh install_github romainfrancois/bibtex -# - Rscript -e "install.packages('covr', repos = 'https://cran.rstudio.com')" -# - travis-tool.sh install_github jimhester/covr -# - travis-tool.sh install_github rstats-db/RSQLite - - -test_script: - - travis-tool.sh run_tests - -on_failure: - - travis-tool.sh dump_logs - - 7z a failure.zip *.Rcheck\* - - appveyor PushArtifact failure.zip - -# on_success: -# - R -e "covr::coveralls(type = 'all')" - -artifacts: - - path: '*.Rcheck\**\*.log' - name: Logs - - - path: '*.Rcheck\**\*.out' - name: Logs - - - path: '*.Rcheck\**\*.fail' - name: Logs - - - path: '*.Rcheck\**\*.Rout' - name: Logs - - - path: '\*_*.tar.gz' - name: Bits - - - path: '\*_*.zip' - name: Bits \ No newline at end of file From d6b70fc36f410d19429a5e1b0ab9b2241ffb6999 Mon Sep 17 00:00:00 2001 From: "Mathew W. McLean" Date: Mon, 7 Oct 2024 19:05:42 +1100 Subject: [PATCH 2/5] Avoid msg about page numbers in ReadPDFs for 1page PDFs * Always use pdfinfo to determine number of pages in each PDF in ReadPDFs even when use.metadata is FALSE * This avoids a message from pdftotext about incorrect pages * Refactor test-readPDF.R to make it clearer when tests are skipped if poppler is not installed Signed-off-by: Mathew W. McLean --- R/ReadPDFs.R | 22 +++++++++++++++- tests/testthat/test-readPDF.R | 47 ++++++++++++++++++++++++----------- 2 files changed, 53 insertions(+), 16 deletions(-) diff --git a/R/ReadPDFs.R b/R/ReadPDFs.R index a816a47..c3a33f9 100755 --- a/R/ReadPDFs.R +++ b/R/ReadPDFs.R @@ -89,8 +89,28 @@ ReadPDFs <- function (path, .enc = 'UTF-8', recursive = TRUE, out, pages.idx)) }else { + .findPages <- function(files) + { + n.files <- length(files) + page.bounding.boxes <- lapply(files, function(x) + system2("pdfinfo", paste(shQuote('-enc'), + shQuote(.enc), shQuote("-box"), + shQuote(normalizePath(x))), + stdout = TRUE, stderr = TRUE)) + pages.idx <- lapply(page.bounding.boxes, grep, pattern = "^Pages:") + pages <- rep(Inf, n.files) + for (i in seq_along(pages.idx)) + { + if (length(pages.idx[[i]])) + pages[i] <- as.integer(sub("^Pages:\\s+(\\d+)", "\\1", + page.bounding.boxes[[i]][pages.idx[[i]]], + perl = TRUE)) + } + return(pages) + } + doi.meta.ind <- logical(n.files) - pages <- rep(Inf, n.files) + pages <- .findPages(files) } ######################################## diff --git a/tests/testthat/test-readPDF.R b/tests/testthat/test-readPDF.R index cce8a55..71480d9 100755 --- a/tests/testthat/test-readPDF.R +++ b/tests/testthat/test-readPDF.R @@ -17,6 +17,13 @@ tmpdir <- tempdir() ## curdir <- getwd() exe.path <- tmpdir # file.path(tmpdir, "bin", fsep = "\\") ## Sys.setenv(PATH = paste(Sys.getenv("PATH"), exe.path, sep = ":")) +skip_if_no_poppler <- function(poppler.unavailable = !nzchar(Sys.which("pdfinfo"))) +{ + if (poppler.unavailable) + skip("poppler is not installed. Could not find pdfinfo executable.") + else + invisible() +} poppler.fail <- !nzchar(Sys.which("pdfinfo")) jss.fail <- try(download.file(paste0("https://www.jstatsoft.org/index.php/", "jss/article/view/v056i11/v56i11.pdf"), @@ -40,8 +47,8 @@ if (inherits(arxiv2.fail, "try-error")) biomet.fail <- !file.copy(system.file("pdf", "biometrikaEx.pdf", package = "RefManageR"), exe.path) if (biomet.fail) - biomet.fail <- try(download.file(paste0("https://stat.uconn.edu/wp-content/", - "uploads/sites/729/2019/10/83-4-715.pdf"), + biomet.fail <- try(download.file(paste0("https://raw.githubusercontent.com/ropensci/", + "RefManageR/master/inst/pdf/biometrikaEx.pdf"), destfile = file.path(exe.path, "biometrikaEx.pdf"), mode = "wb")) if (inherits(biomet.fail, "try-error")) @@ -58,7 +65,8 @@ jstor.fail <- !file.copy(system.file("pdf", "jstor.pdf", test_that("Recognizes DOI", { skip_on_cran() - if (poppler.fail || arxiv1.fail) + skip_if_no_poppler(poppler.fail) + if (arxiv1.fail) skip("Couldn't download arxiv1") expect_message(ReadPDFs(file.path(exe.path, "FIZaop.pdf"), use.metadata = FALSE), @@ -67,9 +75,10 @@ test_that("Recognizes DOI", { test_that("Creates a BibEntry object", { skip_on_cran() - if (poppler.fail || all(jstor.fail, biomet.fail, arxiv1.fail, arxiv2.fail, + skip_if_no_poppler(poppler.fail) + if (all(jstor.fail, biomet.fail, arxiv1.fail, arxiv2.fail, jss.fail)) - skip("Couldn't download Poppler or a single PDF") + skip("Couldn't download any PDFs") msgs <- capture_messages(bib <- ReadPDFs(exe.path, progress = TRUE, use.crossref = TRUE)) expect_is(bib, "BibEntry") @@ -80,16 +89,18 @@ test_that("Creates a BibEntry object", { test_that("Add file field", { skip_on_cran() + skip_if_no_poppler(poppler.fail) if (poppler.fail || all(jstor.fail, biomet.fail, arxiv1.fail, arxiv2.fail, jss.fail)) - skip("Couldn't download Poppler or a single PDF") + skip("Couldn't download any PDFs") bib <- ReadPDFs(exe.path, progress = TRUE, use.crossref = FALSE) expect_is(unlist(bib$file), "character") }) test_that("Reading one PDF file name", { skip_on_cran() - if (poppler.fail || jstor.fail) + skip_if_no_poppler(poppler.fail) + if (jstor.fail) skip("Couldn't copy jstor.pdf") bib1 <- ReadPDFs(file.path(exe.path, "jstor.pdf"), use.metadata = FALSE) expect_is(bib1, "BibEntry") @@ -98,8 +109,9 @@ test_that("Reading one PDF file name", { test_that("Recognizes JSTOR", { skip_on_cran() - if (poppler.fail || jstor.fail) - skip("Couldn't download Poppler or JSTOR PDF") + skip_if_no_poppler(poppler.fail) + if (jstor.fail) + skip("Couldn't copy jstor.pdf") bib <- ReadPDFs(exe.path, progress = FALSE, use.crossref = FALSE) expect_equal(bib[author = "carrol"]$eprinttype, "jstor") expect_equal(bib[author = "carrol"]$url, @@ -108,7 +120,8 @@ test_that("Recognizes JSTOR", { test_that("Recognizes arxiv", { skip_on_cran() - if (poppler.fail || arxiv2.fail) + skip_if_no_poppler(poppler.fail) + if (arxiv2.fail) skip("Couldn't download arxiv2 reference") bib <- ReadPDFs(exe.path, progress = FALSE, use.crossref = FALSE) expect_equal(bib[author = "paul"]$eprinttype, "arxiv") @@ -118,7 +131,8 @@ test_that("Recognizes arxiv", { test_that("Can parse arXiv date", { skip_on_cran() - if (poppler.fail || arxiv2.fail) + skip_if_no_poppler(poppler.fail) + if (arxiv2.fail) skip("Couldn't download arxiv2 reference") ## Entry misses year/date if use.metadata is FALSE bib <- ReadPDFs(exe.path, progress = FALSE, use.crossref = FALSE) @@ -128,7 +142,8 @@ test_that("Can parse arXiv date", { test_that("Reading year and author", { skip_on_cran() - if (poppler.fail || jss.fail) + skip_if_no_poppler(poppler.fail) + if (jss.fail) skip("Couldn't download JSS reference") bib <- ReadPDFs(exe.path, progress = FALSE, use.crossref = FALSE) expect_equal(unlist(bib[author = "luo"]$author$family), @@ -138,7 +153,8 @@ test_that("Reading year and author", { test_that("Reading journal and title", { skip_on_cran() - if (poppler.fail || biomet.fail) + skip_if_no_poppler(poppler.fail) + if (biomet.fail) skip("Couldn't download Biometrika reference") bib <- ReadPDFs(exe.path, progress = FALSE, use.crossref = FALSE) expect_match(bib[year = "1996"]$journal, "Biometrika") @@ -149,9 +165,10 @@ test_that("Reading journal and title", { test_that("use.metadata = FALSE", { skip_on_cran() - if (poppler.fail || all(jstor.fail, biomet.fail, arxiv1.fail, + skip_if_no_poppler(poppler.fail) + if (all(jstor.fail, biomet.fail, arxiv1.fail, arxiv2.fail, jss.fail)) - skip("Couldn't download Poppler or a single pdf") + skip("Couldn't download any PDFs") bib <- ReadPDFs(exe.path, use.metadata = FALSE, use.crossref = FALSE) expect_is(bib, "BibEntry") bib <- ReadPDFs(exe.path, use.metadata = FALSE, use.crossref = TRUE) From 2d33c38cb074966bf3d3a3a25e9b7ebdb68a68df Mon Sep 17 00:00:00 2001 From: "Mathew W. McLean" Date: Mon, 7 Oct 2024 19:06:07 +1100 Subject: [PATCH 3/5] Fix pkg documentation for latest roxygen2 Signed-off-by: Mathew W. McLean --- R/RefManageR-package.R | 20 ++++---------------- man/RefManageR-package.Rd | 34 ++++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/R/RefManageR-package.R b/R/RefManageR-package.R index 544fa5b..94e3be0 100644 --- a/R/RefManageR-package.R +++ b/R/RefManageR-package.R @@ -1,20 +1,8 @@ -#' Import and Manage BibTeX and BibLaTeX references with RefManageR -#' -#' RefManageR provides tools for importing and working with -#' bibliographic references. It greatly enhances the bibentry class by -#' providing a class BibEntry which stores BibTeX and BibLaTeX references, -#' supports UTF-8 encoding, and can be easily searched by any field, by date -#' ranges, and by various formats for name lists (author by last names, -#' translator by full names, etc.). Entries can be updated, combined, sorted, printed -#' in a number of styles, and exported. BibTeX and BibLaTeX .bib files can be -#' read into R and converted to BibEntry objects. Interfaces to NCBI's -#' Entrez, CrossRef, and Zotero are provided for importing references and -#' references can be created from locally stored PDFs using Poppler. Includes -#' functions for citing and generating a bibliography with hyperlinks for -#' documents prepared with RMarkdown or RHTML. +#' @keywords internal +"_PACKAGE" + #' @name RefManageR-package #' @aliases RefManageR refmanager -#' @docType package #' @author McLean, M. W. \email{mathew.w.mclean@@gmail.com} #' @details #' \bold{Importing and Creating References} @@ -56,7 +44,7 @@ #' \code{\link{Cite}}. Its interface is similar to \code{\link{options}}. #' @keywords package #' @references McLean, M. W. (2014). Straightforward Bibliography Management in R Using the RefManageR Package. -#' \href{https://arxiv.org/abs/1403.2036}{arXiv: 1403.2036 [cs.DL]}. Submitted. +#' \href{https://arxiv.org/abs/1403.2036}{arXiv: 1403.2036 [cs.DL]}. #' @references Kime, P., M. Wemheuer, and P. Lehman (2022). The biblatex Package. #' \url{http://mirrors.ibiblio.org/CTAN/macros/latex/contrib/biblatex/doc/biblatex.pdf}. #' @references Hornik, K., D. Murdoch, and A. Zeileis (2012). diff --git a/man/RefManageR-package.Rd b/man/RefManageR-package.Rd index 6e873c8..950ea4e 100755 --- a/man/RefManageR-package.Rd +++ b/man/RefManageR-package.Rd @@ -5,20 +5,9 @@ \alias{RefManageR-package} \alias{RefManageR} \alias{refmanager} -\title{Import and Manage BibTeX and BibLaTeX references with RefManageR} +\title{RefManageR: Straightforward 'BibTeX' and 'BibLaTeX' Bibliography Management} \description{ -RefManageR provides tools for importing and working with -bibliographic references. It greatly enhances the bibentry class by -providing a class BibEntry which stores BibTeX and BibLaTeX references, -supports UTF-8 encoding, and can be easily searched by any field, by date -ranges, and by various formats for name lists (author by last names, -translator by full names, etc.). Entries can be updated, combined, sorted, printed -in a number of styles, and exported. BibTeX and BibLaTeX .bib files can be -read into R and converted to BibEntry objects. Interfaces to NCBI's -Entrez, CrossRef, and Zotero are provided for importing references and -references can be created from locally stored PDFs using Poppler. Includes -functions for citing and generating a bibliography with hyperlinks for -documents prepared with RMarkdown or RHTML. +Provides tools for importing and working with bibliographic references. It greatly enhances the 'bibentry' class by providing a class 'BibEntry' which stores 'BibTeX' and 'BibLaTeX' references, supports 'UTF-8' encoding, and can be easily searched by any field, by date ranges, and by various formats for name lists (author by last names, translator by full names, etc.). Entries can be updated, combined, sorted, printed in a number of styles, and exported. 'BibTeX' and 'BibLaTeX' '.bib' files can be read into 'R' and converted to 'BibEntry' objects. Interfaces to 'NCBI Entrez', 'CrossRef', and 'Zotero' are provided for importing references and references can be created from locally stored 'PDF' files using 'Poppler'. Includes functions for citing and generating a bibliography with hyperlinks for documents prepared with 'RMarkdown' or 'RHTML'. } \details{ \bold{Importing and Creating References} @@ -61,7 +50,7 @@ functions such as \code{\link{print.BibEntry}}, \code{\link{[.BibEntry}}, and } \references{ McLean, M. W. (2014). Straightforward Bibliography Management in R Using the RefManageR Package. -\href{https://arxiv.org/abs/1403.2036}{arXiv: 1403.2036 [cs.DL]}. Submitted. +\href{https://arxiv.org/abs/1403.2036}{arXiv: 1403.2036 [cs.DL]}. Kime, P., M. Wemheuer, and P. Lehman (2022). The biblatex Package. \url{http://mirrors.ibiblio.org/CTAN/macros/latex/contrib/biblatex/doc/biblatex.pdf}. @@ -71,8 +60,25 @@ Who Did What? The Roles of R Package Authors and How to Refer to Them. The R Jou \url{https://journal.r-project.org/archive/2012-1/RJournal_2012-1_Hornik~et~al.pdf} Patashnik, O (1988). Bibtexing. \url{https://tug.org/texmf-docs/bibtex/btxdoc.pdf}. +} +\seealso{ +Useful links: +\itemize{ + \item \url{https://github.com/ropensci/RefManageR/} + \item Report bugs at \url{https://github.com/ropensci/RefManageR/issues} +} + } \author{ +\strong{Maintainer}: Mathew W. McLean \email{mathew.w.mclean@gmail.com} (\href{https://orcid.org/0000-0002-7891-9645}{ORCID}) + +Other contributors: +\itemize{ + \item Andy Bunn \email{bunna@wwu.edu} (function latexify used by toBiblatex) [contributor] +} + + McLean, M. W. \email{mathew.w.mclean@gmail.com} } +\keyword{internal} \keyword{package} From 876ccea561f28c176b9a57f2ec99c560cf1efee1 Mon Sep 17 00:00:00 2001 From: "Mathew W. McLean" Date: Mon, 7 Oct 2024 19:08:08 +1100 Subject: [PATCH 4/5] Fixes for non-ASCII name list fields in toBiblatex and toBibtex * Add latexify() from dplR instead of tools::encoded_text_to_latex to improve conversion of non-ASCII characters to valid latex * Fixes #102, #105, #106 Signed-off-by: Mathew W. McLean --- DESCRIPTION | 12 +- NAMESPACE | 5 +- R/WriteBib.R | 1 - R/toBiblatex.R | 226 ++++++++++++++++++++++++++++++- R/toBibtex.R | 25 ++-- inst/NEWS.md | 9 ++ man/toBiblatex.Rd | 7 +- tests/testthat/test-tobiblatex.R | 90 ++++++++++++ 8 files changed, 353 insertions(+), 22 deletions(-) create mode 100644 tests/testthat/test-tobiblatex.R diff --git a/DESCRIPTION b/DESCRIPTION index 1ac5cd3..eab3958 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,9 +1,11 @@ Package: RefManageR -Version: 1.4.0 +Version: 1.4.3 Title: Straightforward 'BibTeX' and 'BibLaTeX' Bibliography Management -Authors@R: person(c("Mathew", "W."), "McLean", role = c("aut", "cre"), +Authors@R: c(person(c("Mathew", "W."), "McLean", role = c("aut", "cre"), email = "mathew.w.mclean@gmail.com", - comment = c(ORCID = "0000-0002-7891-9645")) + comment = c(ORCID = "0000-0002-7891-9645")), + person("Andy", "Bunn", role = "ctb", + email = "bunna@wwu.edu", comment = "function latexify used by toBiblatex")) Maintainer: Mathew W. McLean Description: Provides tools for importing and working with bibliographic references. It greatly enhances the 'bibentry' class by providing a class @@ -27,6 +29,8 @@ Imports: httr, lubridate (>= 1.5.0), stringr, + stringi, + R.utils, methods, bibtex (>= 0.4.1) Suggests: @@ -39,4 +43,4 @@ Depends: VignetteBuilder: knitr BugReports: https://github.com/ropensci/RefManageR/issues URL: https://github.com/ropensci/RefManageR/ -RoxygenNote: 7.2.1 +RoxygenNote: 7.3.2 diff --git a/NAMESPACE b/NAMESPACE index f5e416d..d8fecac 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -49,6 +49,7 @@ export(as.BibEntry) export(fields) export(is.BibEntry) export(toBiblatex) +importFrom(R.utils,captureOutput) importFrom(bibtex,do_read_bib) importFrom(httr,GET) importFrom(httr,POST) @@ -73,6 +74,9 @@ importFrom(methods,hasArg) importFrom(plyr,llply) importFrom(plyr,progress_text) importFrom(stats,setNames) +importFrom(stringi,stri_trans_nfc) +importFrom(stringi,stri_trans_nfd) +importFrom(stringi,stri_unescape_unicode) importFrom(stringr,str_length) importFrom(stringr,str_sub) importFrom(stringr,str_trim) @@ -82,7 +86,6 @@ importFrom(tools,Rd2txt) importFrom(tools,Rd2txt_options) importFrom(tools,bibstyle) importFrom(tools,deparseLatex) -importFrom(tools,encoded_text_to_latex) importFrom(tools,getBibstyle) importFrom(tools,latexToUtf8) importFrom(tools,loadPkgRdMacros) diff --git a/R/WriteBib.R b/R/WriteBib.R index 600575f..5a17a2b 100644 --- a/R/WriteBib.R +++ b/R/WriteBib.R @@ -21,7 +21,6 @@ #' @note To write the contents of \code{bib} \dQuote{as is}, the argument #' \code{biblatex} should be \code{TRUE}, otherwise #' conversion is done as in \code{\link{toBibtex.BibEntry}}. -#' @importFrom tools encoded_text_to_latex #' @author McLean, M. W. based on \code{write.bib} by Gaujoux, R. #' in package \code{bibtex}. #' @export diff --git a/R/toBiblatex.R b/R/toBiblatex.R index 76da930..5db7f01 100644 --- a/R/toBiblatex.R +++ b/R/toBiblatex.R @@ -10,6 +10,9 @@ #' @param extra.fields character vector; fields that are not supported in standard BibTeX styles are by default dropped #' in the result return by the toBibtex function. #' Any fields specified in extra.fields will \emph{not} be dropped if present in an entry. +#' @param encoded.names.to.latex if \code{TRUE} (the default) then name list fields +#' such as \sQuote{author} and \sQuote{editor} will have non-ASCII characters +#' translated to LaTeX escape sequences by \code{\link[dplR]{latexify}}. #' @param ... ignored #' @export #' @return an object of class \dQuote{Bibtex} - character vectors where each element holds one line of a BibTeX or BibLaTeX file @@ -50,7 +53,7 @@ #' } #' @seealso \code{\link{toBibtex}}, \code{\link{BibEntry}}, \code{\link{print.BibEntry}} #' @author McLean, M. W. \email{mathew.w.mclean@@gmail.com} -#' @importFrom tools encoded_text_to_latex parseLatex deparseLatex latexToUtf8 +#' @importFrom tools parseLatex deparseLatex latexToUtf8 #' @keywords database IO utilities #' @aliases toBibtex.BibEntry toBibtex #' @examples @@ -60,14 +63,16 @@ #' toBiblatex(bib[70:72]) #' toBibtex(bib[70:72]) #' } -toBiblatex <- function(object, ...){ +toBiblatex <- function(object, encoded.names.to.latex = TRUE, ...){ format_bibentry1 <- function(object) { object <- unclass(object)[[1L]] rval <- paste0("@", attr(object, "bibtype"), "{", attr(object, "key"), ",") - nl.ind <- which(names(object) %in% .BibEntryNameList) - for (i in nl.ind) - object[i] <- encoded_text_to_latex(format_author(object[[i]]), "UTF-8") + if (encoded.names.to.latex) { + nl.ind <- which(names(object) %in% .BibEntryNameList) + for (i in nl.ind) + object[i] <- EncodedNameListToLaTeX(object[[i]]) + } rval <- c(rval, vapply(names(object), function(n) paste0(" ", n, " = {", object[[n]], "},"), ""), "}", "") return(rval) @@ -81,3 +86,214 @@ toBiblatex <- function(object, ...){ class(rval) <- "Bibtex" rval } + +#' Wrapper for dplr::latexify that returns original +#' text if translation to LaTeX fails +#' @noRd +#' @seealso \url{https://github.com/ropensci/RefManageR/issues/106} +EncodedNameListToLaTeX <- function(name.list, encoding = "UTF-8") +{ + formatted.text <- format_author(name.list) + out <- latexify(formatted.text, encoding, doublebackslash = FALSE) + if (grepl("^[{]?[?]", out)) + return(formatted.text) + return(out) +} + +#' Modified version of dplR::latexify +#' @importFrom stringi stri_trans_nfc stri_trans_nfd stri_unescape_unicode +#' @importFrom R.utils captureOutput +#' @author Andy Bunn +latexify <- function(x, + doublebackslash = FALSE, + dashdash = TRUE, + quotes = c("straight", "curved"), + packages = c("fontenc", "textcomp")) +{ + y <- as.character(x) + encBytes <- Encoding(y) == "bytes" + if (any(encBytes)) { + y[encBytes] <- captureOutput(cat(y[encBytes], sep = "\n")) + } + y <- stri_trans_nfd(y) + Letters <- paste0(c(LETTERS, letters), collapse = "") + fontenc <- "fontenc" %in% packages + textcomp <- "textcomp" %in% packages + eurosym <- "eurosym" %in% packages + straightQuotes <- match.arg(quotes) == "straight" + y <- gsub("(?![[:space:]])[[:cntrl:]]", "", y, perl = TRUE) + y <- gsub("[[:space:]]+", " ", y) + substitutions <- list(c("\\\\^", "\\\\textasciicircum{}"), + c("~", "\\\\textasciitilde{}"), c("<", "\\\\textless{}"), + c(">", "\\\\textgreater{}"), c("\\\\|", "\\\\textbar{}"), + c("([#$%&_])", "\\\\\\1"), if (isTRUE(dashdash)) { + c("-", "\\\\mbox{-}") + }, if (textcomp && straightQuotes) { + c("'", "\\\\textquotesingle{}") + }, if (textcomp && straightQuotes) { + c("`", "\\\\textasciigrave{}") + }, c("\"", if (fontenc && straightQuotes) { + "\\\\textquotedbl{}" + } else { + "\\\\textquotedblright{}" + }), c("/", "\\\\slash{}")) + substitutions <- substitutions[!vapply(substitutions, is.null, + logical(1))] + substitutions <- c(substitutions, list(c("\\u0132", "\\\\IJ{}"), + c("\\u0133", "\\\\ij{}"), + c("\\u01f1", "DZ"), c("\\u01f2", "Dz"), + c("\\u01f3", "dz"), c("\\u01c4", "DZ\\u033c"), + c("\\u01c5", "Dz\\u030c"), + c("\\u01c6", "dz\\u030c"), + c("\\u01c7", "LJ"), c("\\u01c8", "Lj"), + c("\\u01c9", "lj"), c("\\u01ca", "NJ"), + c("\\u01cb", "Nj"), c("\\u01cc", "nj"), + c("\\ufb00", "ff"), c("\\ufb01", "fi"), + c("\\ufb02", "fl"), c("\\ufb03", "ffi"), + c("\\ufb04", "ffl"), c("\\ufb05", "\\u017ft"), + c("\\ufb06", "st"))) + above <- list(diaeresis = c("\\u0308", "\""), acute = c("\\u0301", "'"), + dotabove = c("\\u0307", "."), macron = c("\\u0304", "="), + circumflex = c("\\u0302", "^"), grave = c("\\u0300", "`"), + tilde = c("\\u0303", "~"), doubleacute = c("\\u030b", "H"), + ringabove = c("\\u030a", "r"), breve = c("\\u0306", "u"), + caron = c("\\u030c", "v"), invbreve = c("\\u0311", "newtie")) + + below <- list(macronbelow = c("\\u0331", "b"), cedilla = c("\\u0327", "c"), + dotbelow = c("\\u0323", "d"), tie = c("\\u0361", "t"), + ogonek = c("\\u0328", "k")) + accents <- c(above, below) + command <- paste0("\\\\[", Letters, "]+|\\\\.") + combining <- paste0(vapply(accents, "[", character(1), 1), + collapse = "") + accPre <- paste0("(", command, "|.)({})?(? Date: Mon, 7 Oct 2024 19:21:09 +1100 Subject: [PATCH 5/5] Update documentation for latexify author Signed-off-by: Mathew W. McLean --- R/toBiblatex.R | 5 +++-- man/toBiblatex.Rd | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/R/toBiblatex.R b/R/toBiblatex.R index 5db7f01..6a3a589 100644 --- a/R/toBiblatex.R +++ b/R/toBiblatex.R @@ -12,7 +12,7 @@ #' Any fields specified in extra.fields will \emph{not} be dropped if present in an entry. #' @param encoded.names.to.latex if \code{TRUE} (the default) then name list fields #' such as \sQuote{author} and \sQuote{editor} will have non-ASCII characters -#' translated to LaTeX escape sequences by \code{\link[dplR]{latexify}}. +#' translated to LaTeX escape sequences. #' @param ... ignored #' @export #' @return an object of class \dQuote{Bibtex} - character vectors where each element holds one line of a BibTeX or BibLaTeX file @@ -52,7 +52,8 @@ #' \item \emph{rest} - to Misc #' } #' @seealso \code{\link{toBibtex}}, \code{\link{BibEntry}}, \code{\link{print.BibEntry}} -#' @author McLean, M. W. \email{mathew.w.mclean@@gmail.com} +#' @author McLean, M. W. \email{mathew.w.mclean@@gmail.com}, Andy Bunn for code for +#' translating non-ASCII characters to LaTeX. #' @importFrom tools parseLatex deparseLatex latexToUtf8 #' @keywords database IO utilities #' @aliases toBibtex.BibEntry toBibtex diff --git a/man/toBiblatex.Rd b/man/toBiblatex.Rd index 1ad8625..f7bb9be 100755 --- a/man/toBiblatex.Rd +++ b/man/toBiblatex.Rd @@ -21,7 +21,7 @@ toBiblatex(object, encoded.names.to.latex = TRUE, ...) \item{encoded.names.to.latex}{if \code{TRUE} (the default) then name list fields such as \sQuote{author} and \sQuote{editor} will have non-ASCII characters -translated to LaTeX escape sequences by \code{\link[dplR]{latexify}}.} +translated to LaTeX escape sequences.} \item{...}{ignored} @@ -90,7 +90,8 @@ if (requireNamespace("bibtex")) { \code{\link{toBibtex}}, \code{\link{BibEntry}}, \code{\link{print.BibEntry}} } \author{ -McLean, M. W. \email{mathew.w.mclean@gmail.com} +McLean, M. W. \email{mathew.w.mclean@gmail.com}, Andy Bunn for code for +translating non-ASCII characters to LaTeX. } \keyword{IO} \keyword{database}