Merge branch 'master' of https://github.com/haozhu233/kableExtra
diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
new file mode 100644
index 0000000..a8affb2
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -0,0 +1,28 @@
+---
+name: Bug report
+about: Create a report to help us improve
+
+---
+
+**Describe the bug**
+A clear and concise description of what the bug is.
+
+**To Reproduce**
+Think about using `reprex` to generate an example in R. 
+
+```
+# code to reproduce the bug.
+```
+
+If you need to attach the entire rmarkdown doc, try to use ```` to quote your entire doc.
+
+````
+---
+title: "A reproducible example in rmarkdown"
+output: html_document
+---
+
+```{r}
+library(kableExtra)
+```
+````
diff --git a/R/add_indent.R b/R/add_indent.R
index a8a455e..35cc196 100644
--- a/R/add_indent.R
+++ b/R/add_indent.R
@@ -48,7 +48,9 @@
 
   for (i in positions + table_info$position_offset) {
     rowtext <- table_info$contents[i]
-    out <- sub(rowtext, latex_indent_unit(rowtext), out, perl = TRUE)
+    out <- sub(paste0(rowtext, "\\\\\\\\\n"),
+               paste0(latex_indent_unit(rowtext), "\\\\\\\\\n"),
+               out, perl = TRUE)
     table_info$contents[i] <- latex_indent_unit(rowtext)
   }
   out <- structure(out, format = "latex", class = "knitr_kable")
diff --git a/R/group_rows.R b/R/group_rows.R
index f6f0d43..4ac5654 100644
--- a/R/group_rows.R
+++ b/R/group_rows.R
@@ -186,7 +186,9 @@
                       regex_escape(extra_latex_after, double_backslash = TRUE))
   }
   new_rowtext <- paste0(pre_rowtext, rowtext)
-  out <- sub(rowtext, new_rowtext, out)
+  out <- sub(paste0(rowtext, "\\\\\\\\\n"),
+  	         paste0(new_rowtext, "\\\\\\\\\n"),
+  	         out)
   out <- gsub("\\\\addlinespace\n", "", out)
   out <- structure(out, format = "latex", class = "knitr_kable")
   table_info$group_rows_used <- TRUE
diff --git a/R/kable_as_image.R b/R/kable_as_image.R
index c5b263e..46dbcbc 100644
--- a/R/kable_as_image.R
+++ b/R/kable_as_image.R
@@ -28,7 +28,9 @@
 #' `jpeg`, `gif`, `tiff`, etc. Default is `png`.
 #' @param latex_header_includes A character vector of extra LaTeX header stuff.
 #' Each element is a row. You can have things like
-#' `c("\\\\usepackage{threeparttable}", "\\\\usepackage{icons}")`
+#' `c("\\\\usepackage{threeparttable}", "\\\\usepackage{icons}")`  You could
+#' probably add your language package here if you use non-English text in your
+#' table, such as `\\\\usepackage[magyar]{babel}`.
 #' @param keep_pdf A T/F option to control if the mid-way standalone pdf should
 #' be kept. Default is `FALSE`.
 #' @param density Resolution to read the PDF file. Default value is 300, which
@@ -70,7 +72,7 @@
     )
     temp_tex <- paste(temp_tex, collapse = "\n")
     temp_file <- paste0("table_", format(Sys.time(), "%Y-%m-%d_%H%M%S"))
-    writeLines(temp_tex, paste0(temp_file, ".tex"))
+    writeLines(temp_tex, paste0(temp_file, ".tex"), useBytes = T)
     system(paste0("xelatex -interaction=batchmode ", temp_file, ".tex"))
     temp_file_delete <- paste0(temp_file, c(".tex", ".aux", ".log"))
     if(!keep_tex) {
diff --git a/R/kable_styling.R b/R/kable_styling.R
index 3b50738..b7a343b 100644
--- a/R/kable_styling.R
+++ b/R/kable_styling.R
@@ -49,6 +49,11 @@
 #' such as tabu or tabularx.You shouldn't expect all features could be
 #' supported in self-defined environments.
 #'
+#' @details  For LaTeX, if you use other than English environment
+#' - all tables are converted to 'UTF-8'. If you use, for example, Hungarian
+#' characters on a Windows machine, make sure to use
+#' Sys.setlocale("LC_ALL","Hungarian") to avoid unexpected conversions.
+#'
 #' @examples x_html <- knitr::kable(head(mtcars), "html")
 #' kable_styling(x_html, "striped", position = "left", font_size = 7)
 #'
diff --git a/R/util.R b/R/util.R
index 5d53369..bfc2d36 100644
--- a/R/util.R
+++ b/R/util.R
@@ -113,6 +113,8 @@
     "\\usepackage{threeparttable}",
     "\\usepackage{threeparttablex}",
     "\\usepackage[normalem]{ulem}",
+    "\\usepackage[normalem]{ulem}",
+    "\\usepackage[utf8]{inputenc}",
     "\\usepackage{makecell}"
   ))
 }
@@ -140,6 +142,7 @@
 
 # Solve enc issue for LaTeX tables
 solve_enc <- function(x) {
+  #may behave differently based on Sys.setlocale settings with respect to characters
   enc2utf8(as.character(base::format(x, trim = TRUE, justify = 'none')))
 }
 
diff --git a/README.md b/README.md
index ffba70f..2ac66c2 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,8 @@
 [![CRAN_version](http://www.r-pkg.org/badges/version/kableExtra)](https://cran.r-project.org/package=kableExtra)
 [![CRAN_download](http://cranlogs.r-pkg.org/badges/kableExtra)](https://cran.r-project.org/package=kableExtra)
 [![CRAN_download_total](http://cranlogs.r-pkg.org/badges/grand-total/kableExtra)](https://cran.r-project.org/package=kableExtra)
+[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1035917.svg)](https://doi.org/10.5281/zenodo.1035917)
+
 
 ***
 
diff --git a/man/kable_as_image.Rd b/man/kable_as_image.Rd
index 24c8b62..8c3a363 100644
--- a/man/kable_as_image.Rd
+++ b/man/kable_as_image.Rd
@@ -21,7 +21,9 @@
 
 \item{latex_header_includes}{A character vector of extra LaTeX header stuff.
 Each element is a row. You can have things like
-\code{c("\\\\usepackage{threeparttable}", "\\\\usepackage{icons}")}}
+\code{c("\\\\usepackage{threeparttable}", "\\\\usepackage{icons}")}  You could
+probably add your language package here if you use non-English text in your
+table, such as \code{\\\\usepackage[magyar]{babel}}.}
 
 \item{keep_pdf}{A T/F option to control if the mid-way standalone pdf should
 be kept. Default is \code{FALSE}.}
diff --git a/man/kable_styling.Rd b/man/kable_styling.Rd
index 2d693ea..8db8475 100644
--- a/man/kable_styling.Rd
+++ b/man/kable_styling.Rd
@@ -68,6 +68,13 @@
 such as tabu or tabularx.You shouldn't expect all features could be
 supported in self-defined environments.
 }
+
+For LaTeX, if you use other than English environment
+\itemize{
+\item all tables are converted to 'UTF-8'. If you use, for example, Hungarian
+characters on a Windows machine, make sure to use
+Sys.setlocale("LC_ALL","Hungarian") to avoid unexpected conversions.
+}
 }
 \examples{
 x_html <- knitr::kable(head(mtcars), "html")