Give people ability to customize title format in footnote
diff --git a/R/footnote.R b/R/footnote.R
index a7e2aa2..5d1e363 100644
--- a/R/footnote.R
+++ b/R/footnote.R
@@ -29,6 +29,8 @@
#' @param number_title Section header for number footnotes. Default is "".
#' @param alphabet_title Section header for alphabet footnotes. Default is "".
#' @param symbol_title Section header for symbol footnotes. Default is "".
+#' @param title_format Choose from "italic"(default), "bold" and "underline".
+#' Multiple options are possible.
#'
#'
#' @examples dt <- mtcars[1:5, 1:5]
@@ -48,7 +50,8 @@
general_title = "Note: ",
number_title = "",
alphabet_title = "",
- symbol_title = ""
+ symbol_title = "",
+ title_format = "italic"
) {
kable_format <- attr(kable_input, "format")
if (!kable_format %in% c("html", "latex")) {
@@ -90,6 +93,10 @@
footnote_titles <- lapply(footnote_titles, linebreak)
}
}
+ title_format <- match.arg(title_format, c("italic", "bold", "underline"),
+ several.ok = TRUE)
+ footnote_titles <- lapply(footnote_titles, footnote_title_format,
+ kable_format, title_format)
footnote_table <- footnote_table_maker(
kable_format, footnote_titles, footnote_contents
)
@@ -102,6 +109,36 @@
}
}
+footnote_title_format <- function(x, format, title_format) {
+ if (x == "") return(x)
+ if (format == "html") {
+ title_style <- ""
+ if ("italic" %in% title_format) {
+ title_style <- paste0(title_style, "font-style: italic;")
+ }
+ if ("bold" %in% title_format) {
+ title_style <- paste0(title_style, "font-weight: bold;")
+ }
+ if ("underline" %in% title_format) {
+ title_style <- paste0(title_style, "text-decoration: underline;")
+ }
+ return(paste0(
+ '<span style="', title_style, '">', x, '</span>'
+ ))
+ } else {
+ if ("italic" %in% title_format) {
+ x <- paste0("\\\\textit\\{", x, "\\}")
+ }
+ if ("bold" %in% title_format) {
+ x <- paste0("\\\\textbf\\{", x, "\\}")
+ }
+ if ("underline" %in% title_format) {
+ x <- paste0("\\\\underline\\{", x, "\\}")
+ }
+ return(x)
+ }
+}
+
footnote_table_maker <- function(format, footnote_titles, footnote_contents) {
number_index <- read.csv(system.file("symbol_index.csv",
package = "kableExtra"))
@@ -176,7 +213,7 @@
paste0('<sup>', x[1], '</sup> ', x[2])
})
if (ft_title != "") {
- title_text <- paste0('<em>', ft_title, '</em>')
+ title_text <- ft_title
footnote_text <- c(title_text, footnote_text)
}
if (!ft_chunk) {
@@ -285,7 +322,7 @@
}
})
if (ft_title != "") {
- title_text <- paste0('\\\\textit{', ft_title, '} ')
+ title_text <- ft_title
footnote_text <- c(title_text, footnote_text)
}
if (!ft_chunk) {
@@ -311,7 +348,7 @@
}
})
if (ft_title != "") {
- title_text <- paste0('\\\\item \\\\textit{', ft_title, '} ')
+ title_text <- paste0('\\\\item ', ft_title, ' ')
footnote_text <- c(title_text, footnote_text)
}
footnote_text <- paste0(footnote_text, collapse = "\n")