Skip to content

Commit aeaecd6

Browse files
Solved the LaTeX2exp error. Closes plotly#2027 (plotly#2030)
Co-authored-by: Carson Sievert <[email protected]>
1 parent 4bb1e44 commit aeaecd6

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

Diff for: R/ggplotly.R

+2-1
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,7 @@ italic <- function(x) paste("<i>", x, "</i>")
13031303

13041304
# if a vector that has one unique value (ignoring missings), return that value
13051305
uniq <- function(x) {
1306+
x <- remove_class(x, "TeX")
13061307
u <- unique(x)
13071308
if (identical(u, NA) || length(u) == 0) return(u)
13081309
u <- u[!is.na(u)]
@@ -1433,4 +1434,4 @@ getAesMap <- function(plot, layer) {
14331434
} else {
14341435
layer$mapping
14351436
}
1436-
}
1437+
}
+1
Loading

Diff for: tests/testthat/helper-vdiffr.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ write_plotly_svg <- function(p, file) {
5151

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

6262
# copied from vdiffr

Diff for: tests/testthat/test-latex2exp.R

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
library(latex2exp)
2+
3+
test_that("latex2exp expressions render correctly", {
4+
p <- qplot(1, "A")+
5+
ylab(TeX("$\\frac{2hc^2}{\\lambda^\\beta}$"))+
6+
xlab(TeX("$\\alpha$"))
7+
8+
expect_doppelganger(config(ggplotly(p), mathjax="cdn"), "latex2exp-rendering")
9+
})

0 commit comments

Comments
 (0)