Skip to content

Commit

Permalink
Merge pull request #217 from yihui/patch-1
Browse files Browse the repository at this point in the history
Some minor tweaks for convert()
  • Loading branch information
nanxstats authored Apr 16, 2024
2 parents c55513d + 5302ee7 commit dc07990
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ jobs:

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
extra-packages: |
any::rcmdcheck
emmeans=?ignore-before-r=4.3.0
needs: check

- uses: r-lib/actions/check-r-package@v2
Expand Down
13 changes: 5 additions & 8 deletions R/conversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ cell_size <- function(col_rel_width, col_total_width) {
#'
#' @noRd
convert <- function(text,
load_stringi = class(try(stringi::stri_replace_all_fixed, silent = TRUE)) != "try-error") {
load_stringi = requireNamespace("stringi", quietly = TRUE)) {
# grepl(">|<|=|_|\\^|(\\\\)|(\\n)", c(">", "<", "=", "_", "\n", "\\line", "abc"))
index <- grepl(">|<|=|_|\\^|(\\\\)|(\\n)", text)

Expand All @@ -91,12 +91,9 @@ convert <- function(text,

# Define Pattern for latex code

unicode_latex$int <- as.integer(as.hexmode(unicode_latex$unicode))
char_latex <- ifelse(unicode_latex$int <= 255 & unicode_latex$int != 177, unicode_latex$chr,
ifelse(unicode_latex$int < 32768,
paste0("\\uc1\\u", unicode_latex$int, "*"),
paste0("\\uc1\\u", unicode_latex$int - 65536, "*")
)
unicode_int <- as.integer(as.hexmode(unicode_latex$unicode))
char_latex <- ifelse(unicode_int <= 255 & unicode_int != 177, unicode_latex$chr,
sprintf("\\uc1\\u%d*", unicode_int - ifelse(unicode_int < 32768, 0, 65536))
)

names(char_latex) <- unicode_latex$latex
Expand All @@ -108,7 +105,7 @@ convert <- function(text,
vectorize_all = FALSE, opts_fixed = list(case_insensitive = FALSE)
)
} else {
for (i in 1:length(char_latex)) {
for (i in seq_along(char_latex)) {
text[index] <- gsub(names(char_latex[i]), char_latex[i], text[index], fixed = TRUE)
}
}
Expand Down

0 comments on commit dc07990

Please sign in to comment.