Skip to content

Commit 04337a0

Browse files
authored
Fix default math rendering in epub format (#1423)
Fix breaking change of pandoc 2.19 as math has been made optional while previously it defaulted to `--mathml`
1 parent e8dfa70 commit 04337a0

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
- Fix an issue with CSL using hanging indent style in `gitbook()` (thanks, @pablobernabeu, #1422).
44

5+
- Fix an issue with Pandoc 2.19 not rendering math by default in `epub3` format (#1417).
6+
57
# CHANGES IN bookdown VERSION 0.33
68

79
- `extra_dependencies` in `gitbook()` is now correctly working (thanks, @ThierryO, #1408).

R/ebook.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ epub_book = function(
4646
if (!is.null(cover_image)) c('--epub-cover-image', cover_image),
4747
if (!is.null(metadata)) c('--epub-metadata', metadata),
4848
if (!identical(template, 'default')) c('--template', template),
49-
if (!missing(chapter_level)) c('--epub-chapter-level', chapter_level)
49+
if (!missing(chapter_level)) c('--epub-chapter-level', chapter_level),
50+
if (rmarkdown::pandoc_available("2.19") && epub_version == "epub3") c("--mathml")
5051
)
5152
if (is.null(stylesheet)) css = NULL else {
5253
css = rmarkdown::pandoc_path_arg(epub_css(stylesheet))

tests/testthat/test-ebook.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
test_that("epub_book() correctly renders math without warning", {
2+
skip_on_cran()
3+
skip_if_not_pandoc()
4+
skip_if_not_installed("jsonlite")
5+
book <- local_book()
6+
# add complex math
7+
xfun::in_dir(
8+
book,
9+
xfun::write_utf8(c(
10+
"# Methods",
11+
"",
12+
"Inserting Math",
13+
"",
14+
"$$",
15+
"SE = \\sqrt(\\frac{p(1-p)}{n}) \\approx \\sqrt{\\frac{1/3 (1 - 1/3)} {300}} = 0.027",
16+
"$$"
17+
), "03-Methods.Rmd")
18+
)
19+
file.create(tmp_file <- withr::local_tempfile(pattern = "pandoc", fileext = ".log"))
20+
res <- .render_book_quiet(book, output_format = epub_book(pandoc_args = c(sprintf("--log=%s", tmp_file), "--quiet")))
21+
expect_false("CouldNotConvertTeXMath" %in% jsonlite::fromJSON(tmp_file)$type)
22+
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy