Skip to content

Commit

Permalink
Solved the LaTeX2exp error. Closes plotly#2027 (plotly#2030)
Browse files Browse the repository at this point in the history
Co-authored-by: Carson Sievert <[email protected]>
  • Loading branch information
moutikabdessabour and cpsievert authored Nov 1, 2021
1 parent 4bb1e44 commit aeaecd6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion R/ggplotly.R
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,7 @@ italic <- function(x) paste("<i>", x, "</i>")

# if a vector that has one unique value (ignoring missings), return that value
uniq <- function(x) {
x <- remove_class(x, "TeX")
u <- unique(x)
if (identical(u, NA) || length(u) == 0) return(u)
u <- u[!is.na(u)]
Expand Down Expand Up @@ -1433,4 +1434,4 @@ getAesMap <- function(plot, layer) {
} else {
layer$mapping
}
}
}
1 change: 1 addition & 0 deletions tests/testthat/_snaps/latex2exp/latex2exp-rendering.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/testthat/helper-vdiffr.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ write_plotly_svg <- function(p, file) {

# strip out non-deterministic fullLayout.uid
# TODO: if and when plotly provides an API to pre-specify, use it!
svg_txt <- readLines(file, warn = FALSE)
svg_txt <- readLines(basename(file), warn = FALSE)
strextract <- function(str, pattern) regmatches(str, regexpr(pattern, str))
def <- strextract(svg_txt, 'defs id=\\"defs-[[:alnum:]]+\\"')
uid <- sub("defs-", "", strextract(def, "defs-[[:alnum:]]+"))
svg_txt <- gsub(uid, "", svg_txt, fixed = TRUE)
writeLines(svg_txt, file)
writeLines(svg_txt, basename(file))
}

# copied from vdiffr
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test-latex2exp.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
library(latex2exp)

test_that("latex2exp expressions render correctly", {
p <- qplot(1, "A")+
ylab(TeX("$\\frac{2hc^2}{\\lambda^\\beta}$"))+
xlab(TeX("$\\alpha$"))

expect_doppelganger(config(ggplotly(p), mathjax="cdn"), "latex2exp-rendering")
})

0 comments on commit aeaecd6

Please sign in to comment.