add kable_as_image; don't use this feature
diff --git a/R/column_spec.R b/R/column_spec.R
index 3af165b..1702f2d 100644
--- a/R/column_spec.R
+++ b/R/column_spec.R
@@ -135,9 +135,6 @@
message("Usually it is recommended to use column_spec before collapse_rows,",
" especially in LaTeX, to get a desired result. ")
}
- if (!is.null(background)) {
- warning("Column background color for LaTeX has not yet been implemented.")
- }
align_collapse <- ifelse(table_info$booktabs, "", "\\|")
kable_align_old <- paste(table_info$align_vector, collapse = align_collapse)
diff --git a/R/kableExtra-package.R b/R/kableExtra-package.R
index 4690022..2664c4d 100644
--- a/R/kableExtra-package.R
+++ b/R/kableExtra-package.R
@@ -61,11 +61,12 @@
#' xml_child xml_children xml_name xml_add_sibling xml_add_child xml_text
#' xml_remove write_xml xml_text<-
#' @importFrom rvest html_table
-#' @importFrom knitr knit_meta_add
+#' @importFrom knitr knit_meta_add include_graphics
#' @importFrom rmarkdown latex_dependency
#' @importFrom magrittr %>%
#' @importFrom utils read.csv
-#' @importFrom readr read_lines read_file
+#' @importFrom readr read_lines read_file write_file
+#' @import magick
#' @name kableExtra-package
#' @aliases kableExtra
#' @docType package
diff --git a/R/tex2image.R b/R/tex2image.R
new file mode 100644
index 0000000..2ce27cb
--- /dev/null
+++ b/R/tex2image.R
@@ -0,0 +1,41 @@
+#' @export
+kable_as_image_latex <- function(kable_input, width = NULL,
+ latex_header_includes = NULL,
+ keep_pdf = FALSE) {
+ temp_tex <- c(
+ "\\documentclass[border=1mm, preview]{standalone}",
+ "\\usepackage[active,tightpage]{preview}",
+ "\\usepackage{varwidth}",
+ "\\usepackage{booktabs}",
+ "\\usepackage{longtable}",
+ "\\usepackage{array}",
+ "\\usepackage{multirow}",
+ "\\usepackage[table]{xcolor}",
+ "\\usepackage{wrapfig}",
+ "\\usepackage{colortbl}",
+ "\\usepackage{graphicx}",
+ latex_header_includes,
+ "\\begin{document}",
+ as.character(kable_input),
+ "\\end{document}"
+ )
+ temp_tex <- paste(temp_tex, collapse = "\n")
+ temp_file <- paste0("table_", format(Sys.time(), "%Y-%m-%d_%H:%M:%S"))
+ write_file(temp_tex, paste0(temp_file, ".tex"))
+ system(paste0("xelatex -interaction=batchmode ", temp_file, ".tex"))
+ temp_file_delete <- paste0(temp_file, c(".tex", ".aux", ".log"))
+ unlink(temp_file_delete)
+
+ table_img_pdf <- image_read(paste0(temp_file, ".pdf"), density = 300)
+ if (!keep_pdf) {
+ unlink(paste0(temp_file, ".pdf"))
+ }
+ table_img <- image_convert(table_img_pdf, "png")
+ if (!is.null(width)) {
+ table_img <- image_scale(table_img, as.character(300*width))
+ }
+ temp_img <- tempfile(fileext = ".png")
+ image_write(table_img, temp_img)
+
+ include_graphics(temp_img)
+}