Created
January 31, 2022 09:02
-
-
Save baptiste/714fd0b52fa4fe8907cbf646c33ae3ee to your computer and use it in GitHub Desktop.
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
grab_math_strings <- function(fe){ | |
parse <- readLines(glue("{fe}-math.tex")) | |
content <- parse[parse != ''] | |
lines <- grep("math start", content) | |
start <- lines+1 | |
end <- c(lines[-1], length(content) + 1) - 1 | |
library(purrr) | |
eqs <- map2(start, end, function(x,y) paste(gsub("\\\\\\(|\\\\\\)|\\\\\\[|\\\\\\]", "$$", content[x:y]), collapse = ' ')) | |
eqs | |
} | |
extract_math <- function(f){ | |
library(glue) | |
fe <- fs::path_ext_remove(f) | |
system(glue("de-macro {fe}")) | |
system(glue("pandoc --lua-filter ./filter.lua {fe}-clean.tex -o {fe}-math.tex")) | |
grab_math_strings(fe) | |
} | |
export_math <- function(eqs, out = 'tmp.json', hstep=0, vstep=50, fontSize=36){ | |
library(minixcali) | |
d <- Excali_doc() | |
for (i in seq_along(eqs)) { | |
equation <- xkd_math( | |
x = (i - 1)*hstep, | |
y = (i - 1)*vstep, | |
text = eqs[[i]], | |
originalText = eqs[[i]], | |
fontSize=fontSize | |
) | |
d$add(equation) | |
} | |
d$export(out) | |
} | |
eqs <- extract_math('01-maxwell-math.tex') | |
export_math(eqs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment