Fixed #115
diff --git a/R/footnote.R b/R/footnote.R
index d67382b..4d1894e 100644
--- a/R/footnote.R
+++ b/R/footnote.R
@@ -83,8 +83,8 @@
footnote_contents <- lapply(footnote_contents, escape_html)
footnote_titles <- lapply(footnote_titles, escape_html)
} else {
- footnote_contents <- lapply(footnote_contents, escape_latex)
- footnote_titles <- lapply(footnote_titles, escape_latex)
+ footnote_contents <- lapply(footnote_contents, escape_latex2)
+ footnote_titles <- lapply(footnote_titles, escape_latex2)
}
}
footnote_table <- footnote_table_maker(
diff --git a/R/from_knitr.R b/R/from_knitr.R
index 1948795..205148d 100644
--- a/R/from_knitr.R
+++ b/R/from_knitr.R
@@ -14,6 +14,15 @@
x
}
+escape_latex2 <- function(x) {
+ x = gsub('\\\\', '\\\\\\\\textbackslash', x)
+ x = gsub('([#$%&_{}])', '\\\\\\\\\\1', x)
+ x = gsub('\\\\textbackslash', '\\\\\\\\textbackslash{}', x)
+ x = gsub('~', '\\\\\\\\textasciitilde{}', x)
+ x = gsub('\\^', '\\\\\\\\textasciicircum{}', x)
+ x
+}
+
# escape special HTML characters
# @author Yihui Xie
escape_html <- function(x) {
diff --git a/inst/NEWS.md b/inst/NEWS.md
index 30a60d4..677ee46 100644
--- a/inst/NEWS.md
+++ b/inst/NEWS.md
@@ -1,3 +1,8 @@
+kableExtra 0.7.1
+--------------------------------------------------------------------------------
+* Fixed #115, a bug in latex footnote about escaping.
+
+
kableExtra 0.7.0
--------------------------------------------------------------------------------
* Now HTML table will be previewed in Viewer panel
diff --git a/tests/visual_tests/footnote_latex.Rmd b/tests/visual_tests/footnote_latex.Rmd
index b2f9e5e..65bef09 100644
--- a/tests/visual_tests/footnote_latex.Rmd
+++ b/tests/visual_tests/footnote_latex.Rmd
@@ -25,7 +25,12 @@
```{r}
mtcars[1:5, 1:5] %>%
- kable("latex", booktabs = T) %>%
+ kable("latex", booktabs = T, caption = "hi") %>%
+ kable_styling(position = "left") %>%
footnote(number = c("For this particular use (i.e. a general note) the comments above are adequate. For proper footnotes in tables you should probably use the threeparttable package. You should also probably be using the booktabs package. See this answer to this question", "Note 2"),
number_title = "Note: ", threeparttable = T, footnote_as_chunk = T)
```
+
+```{r}
+kable(cars, caption = 'table caption', format = 'latex', escape = TRUE) %>% kableExtra::footnote(general = 'an_underscore', escape = T)
+```