Skip to content

Commit

Permalink
fix issue with 'lost bracket' NOTE from R-devdel check
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoBosh committed Oct 30, 2023
1 parent 1b97d7d commit 569ee05
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: Rdpack
Type: Package
Title: Update and Manipulate Rd Documentation Objects
Version: 2.5
Version: 2.5.9000
Authors@R: c( person(given = c("Georgi", "N."),
family = "Boshnakov",
role = c("aut", "cre"),
Expand Down
63 changes: 63 additions & 0 deletions R/bib.R
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,69 @@ deparseLatexToRd <- function(x, dropBraces = FALSE)
paste(result, collapse="")
}



`%notin%` <-
function(x, y)
is.na(match(x, y))

## This converts a latex object into a single element character vector
deparseLatexToRd <- function(x, dropBraces = FALSE)
{
specials <- c("\\", "#", "$", "%", "&", "~", "_", "^", "{", "}")
result <- character()
lastTag <- "TEXT"
expectArg <- FALSE
for (i in seq_along(x)) {
a <- x[[i]]
tag <- attr(a, "latex_tag")
if (is.null(tag)) tag <- "NULL"
result <- c(result,
switch(tag,
VERB = ,
COMMENT = a,
TEXT = c(if (lastTag == "MACRO" && expectArg && grepl("^[[:alpha:]]", a))
## restore space that the parser has eaten ('\item text')
" ",
a),
MACRO = {
## see issue #26
## regex in r-devel/R/src/library/tools/R/RdConv2.R:
## pat <- "([^\\]|^)\\\\[#$&_^~]"
## here we add grouping for substitution
pat <- "([^\\]|^)(\\\\)([#$&_^~])" # with more grouping
if(grepl(pat, a)){
a <- gsub(pat, "\\1\\3", a)
}
c(if (lastTag == "MACRO" && expectArg && grepl("^[[:alpha:]]", a))
## restore space that the parser has eaten ('\item text')
" ",
a)
},
BLOCK = if (dropBraces && !expectArg)
Recall(a)
else
c("{", Recall(a), "}"),
ENVIRONMENT = c(
"\\begin{", a[[1L]], "}",
Recall(a[[2L]]),
"\\end{", a[[1L]], "}"),
## enclose maths in \eqn{...}, not $ ... $; # \( and \) parse as MACRO
MATH = c("\\eqn{", Recall(a), "}"),
NULL = stop("Internal error, no tag", domain = NA)
))
lastTag <- tag
expectArg <-
if (tag == "MACRO")
a %notin% paste0("\\", c(specials, "(", ")"))
else
expectArg &&
tag %in% c("BLOCK", "COMMENT") # \cmd{}{}, \cmd%
## currently ignoring \cmd {}, \cmd[]{}, \cmd*{}
}
paste(result, collapse="")
}

Rdpack_bibstyles <- local({
styles <- list()
function(package, authors){
Expand Down

0 comments on commit 569ee05

Please sign in to comment.