Solve #149
diff --git a/R/add_header_above.R b/R/add_header_above.R
index a0c37f3..4489c81 100644
--- a/R/add_header_above.R
+++ b/R/add_header_above.R
@@ -136,8 +136,7 @@
header <- standardize_header_input(header)
if (escape) {
- header$header <- escape_latex2(header$header)
- header$header <- linebreak(header$header, align = align, double_escape = TRUE)
+ header$header <- input_escape(header$header, align)
}
align <- match.arg(align, c("c", "l", "r"))
diff --git a/R/footnote_marker.R b/R/footnote_marker.R
index d5d021b..72b3306 100644
--- a/R/footnote_marker.R
+++ b/R/footnote_marker.R
@@ -10,6 +10,9 @@
#' return "b" in HTML.
#' @param format Either `html` or `latex`. All functions here can read
#' default value from global option `knitr.table.format`.
+#' @param double_escape T/F if output is in LaTeX, whether it should be double
+#' escaped. If you are using footnote_marker in `group_rows`` labeling row or
+#' `add_header_above`, you need to set this to be `TRUE`.
#'
#' @examples dt <- mtcars[1:5, 1:5]
#' colnames(dt)[1] <- paste0("mpg", footnote_marker_alphabet(2, "html"))
@@ -17,7 +20,7 @@
#' footnote(knitr::kable(dt, "html"), alphabet = c("Note a", "Note b"))
#'
#' @export
-footnote_marker_number <- function(x, format) {
+footnote_marker_number <- function(x, format, double_escape = FALSE) {
if (missing(format) || is.null(format)) {
format <- getOption('knitr.table.format')
}
@@ -27,14 +30,16 @@
}
if (format == "html") {
return(paste0("<sup>", x, "</sup>"))
- } else {
+ } else if (!double_escape) {
return(paste0("\\textsuperscript{", x, "}"))
+ } else {
+ return(paste0("\\\\textsuperscript{", x, "}"))
}
}
#' @rdname footnote_marker_number
#' @export
-footnote_marker_alphabet <- function(x, format) {
+footnote_marker_alphabet <- function(x, format, double_escape = FALSE) {
if (missing(format) || is.null(format)) {
format <- getOption('knitr.table.format')
}
@@ -45,14 +50,16 @@
if (is.numeric(x)) x <- letters[x]
if (format == "html") {
return(paste0("<sup>", x, "</sup>"))
- } else {
+ } else if (!double_escape) {
return(paste0("\\textsuperscript{", x, "}"))
+ } else {
+ return(paste0("\\\\textsuperscript{", x, "}"))
}
}
#' @rdname footnote_marker_number
#' @export
-footnote_marker_symbol <- function(x, format) {
+footnote_marker_symbol <- function(x, format, double_escape = FALSE) {
if (missing(format) || is.null(format)) {
format <- getOption('knitr.table.format')
}
@@ -65,9 +72,12 @@
if (format == "html") {
x <- number_index$symbol.html[x]
return(paste0("<sup>", x, "</sup>"))
- } else {
+ } else if (!double_escape) {
x <- number_index$symbol.latex[x]
x <- gsub("\\\\\\\\", "\\\\", x)
return(paste0("\\textsuperscript{", x, "}"))
+ } else {
+ x <- number_index$symbol.latex[x]
+ return(paste0("\\\\textsuperscript{", x, "}"))
}
}
diff --git a/R/group_rows.R b/R/group_rows.R
index a6f74d0..85962cf 100644
--- a/R/group_rows.R
+++ b/R/group_rows.R
@@ -154,14 +154,13 @@
}
if (escape) {
- group_label <- escape_latex2(group_label)
- group_label <- linebreak(group_label, align = latex_align, double_escape = TRUE)
+ group_label <- input_escape(group_label, latex_align)
}
- if(bold){
+ if (bold) {
group_label <- paste0("\\\\textbf{", group_label, "}")
}
- if(italic) group_label <- paste0("\\\\textit{", group_label, "}")
+ if (italic) group_label <- paste0("\\\\textit{", group_label, "}")
# Add group label
rowtext <- table_info$contents[start_row + 1]
if (table_info$booktabs) {
diff --git a/R/util.R b/R/util.R
index 3f8237a..2de14b1 100644
--- a/R/util.R
+++ b/R/util.R
@@ -138,3 +138,8 @@
enc2utf8(as.character(base::format(x, trim = TRUE, justify = 'none')))
}
+input_escape <- function(x, latex_align) {
+ x <- escape_latex2(x)
+ x <- linebreak(x, align = latex_align, double_escape = TRUE)
+}
+