Skip to content

Commit

Permalink
protect the math environments for epub as suggested in jgm/pandoc#2758
Browse files Browse the repository at this point in the history
…(not an optimal solution, and hoping Pandoc can address the real issue)
  • Loading branch information
yihui committed Apr 29, 2016
1 parent 1e480ce commit 8a4d8c0
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions R/ebook.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ epub_book = function(
)
content = restore_part_epub(content)
content = restore_appendix_epub(content)
content = protect_math_env(content)
writeUTF8(content, input_file)
NULL
},
Expand Down Expand Up @@ -120,6 +121,23 @@ restore_appendix_epub = function(x) {
x
}

# wrap math environments in $$, otherwise they are discarded by Pandoc
# https://github.com/jgm/pandoc/issues/2758
protect_math_env = function(x) {
env = 'equation' # may add more LaTeX environments later
s1 = sprintf('\\begin{%s}', env)
s2 = sprintf('\\end{%s}', env)
for (s in s1) {
i = x == s
x[i] = paste0('$$', x[i])
}
for (s in s2) {
i = x == s
x[i] = paste0(x[i], '$$')
}
x
}

# manually base64 encode images in css: https://github.com/jgm/pandoc/issues/2733
epub_css = function(files, output = tempfile('epub', fileext = '.css')) {
css = unlist(lapply(files, function(css) {
Expand Down

0 comments on commit 8a4d8c0

Please sign in to comment.