blob: df5433907b61e8cce3c078bf70b3e57081a20599 [file] [log] [blame]
Hao Zhucdd7f922018-01-08 11:39:40 -05001#' Footnote marker
Hao Zhue0782ab2018-01-09 13:24:13 -05002#'
3#' @description Put footnote mark in superscription in table. Unless you are
4#' using it in the `caption` of `kable`, you will need to put `escape = F`
5#' in `kable` (similar with `cell_spec`). Again, similar with `cell_spec`, the
6#' `format` option here can read default value from global option
7#' `knitr.table.format`.
8#'
9#' @param x a number. For example, for `footnote_marker_alphabet(2)` will
10#' return "b" in HTML.
11#' @param format Either `html` or `latex`. All functions here can read
12#' default value from global option `knitr.table.format`.
13#'
Hao Zhu1ac13ad2018-01-08 16:12:24 -050014#' @export
15footnote_marker_number <- function(x, format) {
16 if (missing(format) || is.null(format)) {
17 format <- getOption('knitr.table.format')
18 }
19 if (is.null(format)) {
20 message("Setting footnote_marker_number format as html")
21 format <- "html"
22 }
23 if (format == "html") {
24 return(paste0("<sup>", x, "</sup>"))
25 } else {
Hao Zhu19c4fa52018-01-09 12:01:14 -050026 return(paste0("\\textsuperscript{", x, "}"))
Hao Zhu1ac13ad2018-01-08 16:12:24 -050027 }
28}
29
Hao Zhue0782ab2018-01-09 13:24:13 -050030#' @rdname footnote_marker_number
Hao Zhu1ac13ad2018-01-08 16:12:24 -050031#' @export
32footnote_marker_alphabet <- function(x, format) {
33 if (missing(format) || is.null(format)) {
34 format <- getOption('knitr.table.format')
35 }
36 if (is.null(format)) {
37 message("Setting footnote_marker_alphabet format as html")
38 format <- "html"
39 }
40 if (is.numeric(x)) x <- letters[x]
41 if (format == "html") {
42 return(paste0("<sup>", x, "</sup>"))
43 } else {
Hao Zhu19c4fa52018-01-09 12:01:14 -050044 return(paste0("\\textsuperscript{", x, "}"))
Hao Zhu1ac13ad2018-01-08 16:12:24 -050045 }
46}
47
Hao Zhue0782ab2018-01-09 13:24:13 -050048#' @rdname footnote_marker_number
Hao Zhu1ac13ad2018-01-08 16:12:24 -050049#' @export
50footnote_marker_symbol <- function(x, format) {
51 if (missing(format) || is.null(format)) {
52 format <- getOption('knitr.table.format')
53 }
54 if (is.null(format)) {
55 message("Setting footnote_marker_symbol format as html")
56 format <- "html"
57 }
58 number_index <- read.csv(system.file("symbol_index.csv",
59 package = "kableExtra"))
60 if (format == "html") {
61 x <- number_index$symbol.html[x]
62 return(paste0("<sup>", x, "</sup>"))
63 } else {
64 x <- number_index$symbol.latex[x]
Hao Zhu19c4fa52018-01-09 12:01:14 -050065 return(paste0("\\textsuperscript{", x, "}"))
Hao Zhu1ac13ad2018-01-08 16:12:24 -050066 }
67}