Created
September 26, 2017 15:52
-
-
Save HughParsonage/37dd61adf04be0772ba6db5d37216dcf to your computer and use it in GitHub Desktop.
tex-parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parse2 <- function(x) { | |
# x <- "ab{c{f}}d{e}f{g}h{ij{{k}}}lm" | |
x_split <- unlist(strsplit(x, "", fixed = TRUE)) | |
tex_group <- cumsum(x_split == "{") - cumsum(x_split == "}") | |
max_tex_group <- max(tex_group) | |
out <- setDT(list(char = x_split, tex_group = tex_group)) | |
out[, I := .I] | |
for (j in seq_len(max_tex_group)) { | |
tgj <- paste0("tg", j) | |
out[tex_group >= j, (tgj) := cumsum(char == "{" & tex_group == j)] | |
} | |
out | |
} | |
footnote_opens <- function(DT) { | |
c("\\", "f", "o", "o", "t", "n", "o", "t", "e", "{") | |
for (k in 0:9) { | |
DT[, (paste0("v", k)) := shift(char, k + 1)] | |
} | |
DT %>% | |
.[char == "{"] %>% | |
.[v0 == "e"] %>% | |
.[v1 == "t"] %>% | |
.[v2 == "o"] %>% | |
.[v3 == "n"] %>% | |
.[v4 == "t"] %>% | |
.[v5 == "o"] %>% | |
.[v6 == "o"] %>% | |
.[v7 == "f"] %>% | |
.[v8 == "\\"] | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment