Fix #105
diff --git a/NAMESPACE b/NAMESPACE
index d32ccda..a21e753 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -8,6 +8,9 @@
export(collapse_rows)
export(column_spec)
export(footnote)
+export(footnote_marker_alphabet)
+export(footnote_marker_number)
+export(footnote_marker_symbol)
export(group_rows)
export(kableExtra_latex_packages)
export(kable_as_image)
diff --git a/R/cell_spec.R b/R/cell_spec.R
index c6ef41d..0774fcb 100644
--- a/R/cell_spec.R
+++ b/R/cell_spec.R
@@ -50,7 +50,9 @@
background_as_tile = TRUE,
latex_background_in_cell = TRUE) {
- if (missing(format) || is.null(format)) format = getOption('knitr.table.format')
+ if (missing(format) || is.null(format)) {
+ format <- getOption('knitr.table.format')
+ }
if (is.null(format)) {
message("Setting cell_spec format as html")
format <- "html"
@@ -75,9 +77,10 @@
escape, background_as_tile) {
if (escape) x <- escape_html(x)
cell_style <- NULL
- if (bold) cell_style <- paste(cell_style,"font-weight: bold;")
- if (italic) cell_style <- paste(cell_style, "font-style: italic;")
- if (monospace) cell_style <- paste(cell_style, "font-family: monospace;")
+ cell_style <- paste(cell_style, ifelse(bold, "font-weight: bold;", ""))
+ cell_style <- paste(cell_style, ifelse(italic, "font-style: italic;", ""))
+ cell_style <- paste(cell_style,
+ ifelse(monospace, "font-family: monospace;", ""))
if (!is.null(color)) {
cell_style <- paste0(cell_style, "color: ", html_color(color), ";")
}
diff --git a/R/footnote.R b/R/footnote.R
index 63caf6d..92ad36a 100644
--- a/R/footnote.R
+++ b/R/footnote.R
@@ -2,17 +2,17 @@
#'
#' @export
footnote <- function(kable_input,
- general = NULL,
- number = NULL,
- alphabet = NULL,
- symbol = NULL,
- footnote_order = c("general", "number",
- "alphabet", "symbol"),
- footnote_as_chunk = FALSE,
- general_title = "Note: ",
- number_title = "",
- alphabet_title = "",
- symbol_title = ""
+ general = NULL,
+ number = NULL,
+ alphabet = NULL,
+ symbol = NULL,
+ footnote_order = c("general", "number",
+ "alphabet", "symbol"),
+ footnote_as_chunk = FALSE,
+ general_title = "Note: ",
+ number_title = "",
+ alphabet_title = "",
+ symbol_title = ""
) {
kable_format <- attr(kable_input, "format")
if (!kable_format %in% c("html", "latex")) {
@@ -94,8 +94,7 @@
}
# HTML
-footnote_html <- function(kable_input, footnote_table,
- footnote_as_chunk) {
+footnote_html <- function(kable_input, footnote_table, footnote_as_chunk) {
kable_attrs <- attributes(kable_input)
kable_xml <- read_kable_as_xml(kable_input)
@@ -146,6 +145,8 @@
}
# LaTeX
-footnote_latex <- function() {
+footnote_latex <- function(kable_input, footnote_table, footnote_as_chunk) {
+ table_info <- magic_mirror(kable_input)
+
}
diff --git a/R/footnote_marker.R b/R/footnote_marker.R
index 0b2dd8d..b0d1988 100644
--- a/R/footnote_marker.R
+++ b/R/footnote_marker.R
@@ -1 +1,53 @@
#' Footnote marker
+#' @export
+footnote_marker_number <- function(x, format) {
+ if (missing(format) || is.null(format)) {
+ format <- getOption('knitr.table.format')
+ }
+ if (is.null(format)) {
+ message("Setting footnote_marker_number format as html")
+ format <- "html"
+ }
+ if (format == "html") {
+ return(paste0("<sup>", x, "</sup>"))
+ } else {
+ return(paste0("\\\\textsuperscript{", x, "}"))
+ }
+}
+
+#' @export
+footnote_marker_alphabet <- function(x, format) {
+ if (missing(format) || is.null(format)) {
+ format <- getOption('knitr.table.format')
+ }
+ if (is.null(format)) {
+ message("Setting footnote_marker_alphabet format as html")
+ format <- "html"
+ }
+ if (is.numeric(x)) x <- letters[x]
+ if (format == "html") {
+ return(paste0("<sup>", x, "</sup>"))
+ } else {
+ return(paste0("\\\\textsuperscript{", x, "}"))
+ }
+}
+
+#' @export
+footnote_marker_symbol <- function(x, format) {
+ if (missing(format) || is.null(format)) {
+ format <- getOption('knitr.table.format')
+ }
+ if (is.null(format)) {
+ message("Setting footnote_marker_symbol format as html")
+ format <- "html"
+ }
+ number_index <- read.csv(system.file("symbol_index.csv",
+ package = "kableExtra"))
+ if (format == "html") {
+ x <- number_index$symbol.html[x]
+ return(paste0("<sup>", x, "</sup>"))
+ } else {
+ x <- number_index$symbol.latex[x]
+ return(paste0("\\\\textsuperscript{", x, "}"))
+ }
+}
diff --git a/man/footnote_marker_number.Rd b/man/footnote_marker_number.Rd
new file mode 100644
index 0000000..cfa0c16
--- /dev/null
+++ b/man/footnote_marker_number.Rd
@@ -0,0 +1,11 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/footnote_marker.R
+\name{footnote_marker_number}
+\alias{footnote_marker_number}
+\title{Footnote marker}
+\usage{
+footnote_marker_number(x, format)
+}
+\description{
+Footnote marker
+}
diff --git a/tests/visual_tests/add_footnote_adv_html.Rmd b/tests/visual_tests/footnote_html.Rmd
similarity index 83%
rename from tests/visual_tests/add_footnote_adv_html.Rmd
rename to tests/visual_tests/footnote_html.Rmd
index bf8fd4e..2f6e558 100644
--- a/tests/visual_tests/add_footnote_adv_html.Rmd
+++ b/tests/visual_tests/footnote_html.Rmd
@@ -10,7 +10,7 @@
library(kableExtra)
mtcars[1:5, 1:5] %>%
- kable("html") %>%
+ kable("html", caption = paste0("test", footnote_marker_symbol(1))) %>%
kable_styling() %>%
footnote("ccc", c("number 1; ", "number 2. "), c("a 1; ", "a 2."), c("s 1; ", "s 2."),
number_title = "special: ", alphabet_title = "abc: ",
diff --git a/tests/visual_tests/add_footnote_adv_html.Rmd b/tests/visual_tests/footnote_latex.Rmd
similarity index 83%
copy from tests/visual_tests/add_footnote_adv_html.Rmd
copy to tests/visual_tests/footnote_latex.Rmd
index bf8fd4e..2f6e558 100644
--- a/tests/visual_tests/add_footnote_adv_html.Rmd
+++ b/tests/visual_tests/footnote_latex.Rmd
@@ -10,7 +10,7 @@
library(kableExtra)
mtcars[1:5, 1:5] %>%
- kable("html") %>%
+ kable("html", caption = paste0("test", footnote_marker_symbol(1))) %>%
kable_styling() %>%
footnote("ccc", c("number 1; ", "number 2. "), c("a 1; ", "a 2."), c("s 1; ", "s 2."),
number_title = "special: ", alphabet_title = "abc: ",