improve encoding for LaTeX table. #138
diff --git a/R/add_footnote.R b/R/add_footnote.R
index feb1269..dd78ef5 100644
--- a/R/add_footnote.R
+++ b/R/add_footnote.R
@@ -101,7 +101,7 @@
}
label <- gsub("\\\\", "\\\\\\\\", label)
- export <- enc2utf8(export)
+ export <- solve_enc(export)
table_info <- magic_mirror(input)
if (table_info$tabular == "longtable") {
if (notation != "number") {
diff --git a/R/add_header_above.R b/R/add_header_above.R
index 59bae17..a0c37f3 100644
--- a/R/add_header_above.R
+++ b/R/add_header_above.R
@@ -150,7 +150,7 @@
} else {
new_header <- new_header_split[1]
}
- out <- str_replace(enc2utf8(as.character(kable_input)),
+ out <- str_replace(solve_enc(kable_input),
hline_type,
paste0(hline_type, "\n", new_header))
out <- structure(out, format = "latex", class = "knitr_kable")
diff --git a/R/add_indent.R b/R/add_indent.R
index ff54ea1..de6fc32 100644
--- a/R/add_indent.R
+++ b/R/add_indent.R
@@ -31,7 +31,7 @@
# Add indentation for LaTeX
add_indent_latex <- function(kable_input, positions) {
table_info <- magic_mirror(kable_input)
- out <- enc2utf8(as.character(kable_input))
+ out <- solve_enc(kable_input)
if (table_info$duplicated_rows) {
dup_fx_out <- fix_duplicated_rows_latex(out, table_info)
diff --git a/R/collapse_rows.R b/R/collapse_rows.R
index 98a6ba2..8d42b71 100644
--- a/R/collapse_rows.R
+++ b/R/collapse_rows.R
@@ -117,7 +117,7 @@
row_group_label_position, row_group_label_fonts,
custom_latex_hline, headers_to_remove) {
table_info <- magic_mirror(kable_input)
- out <- enc2utf8(as.character(kable_input))
+ out <- solve_enc(kable_input)
if (is.null(columns)) {
columns <- seq(1, table_info$ncol)
diff --git a/R/column_spec.R b/R/column_spec.R
index bdd8b2b..21eb99c 100644
--- a/R/column_spec.R
+++ b/R/column_spec.R
@@ -178,7 +178,7 @@
kable_align_new <- paste(table_info$align_vector, collapse = align_collapse)
out <- sub(kable_align_old, kable_align_new,
- enc2utf8(as.character(kable_input)),
+ solve_enc(kable_input),
perl = T)
out <- structure(out, format = "latex", class = "knitr_kable")
if (!is.null(width)) {
diff --git a/R/footnote.R b/R/footnote.R
index 42b76a5..5c77e50 100644
--- a/R/footnote.R
+++ b/R/footnote.R
@@ -197,7 +197,7 @@
footnote_latex <- function(kable_input, footnote_table, footnote_as_chunk,
threeparttable) {
table_info <- magic_mirror(kable_input)
- out <- enc2utf8(as.character(kable_input))
+ out <- solve_enc(kable_input)
footnote_text <- latex_tfoot_maker(footnote_table, footnote_as_chunk,
table_info$ncol, threeparttable)
diff --git a/R/group_rows.R b/R/group_rows.R
index f93a4d7..a6f74d0 100644
--- a/R/group_rows.R
+++ b/R/group_rows.R
@@ -145,7 +145,7 @@
bold = T, italic = F, hline_before = F ,hline_after = F,
extra_latex_after = NULL) {
table_info <- magic_mirror(kable_input)
- out <- enc2utf8(as.character(kable_input))
+ out <- solve_enc(kable_input)
if (table_info$duplicated_rows) {
dup_fx_out <- fix_duplicated_rows_latex(out, table_info)
diff --git a/R/kable_as_image.R b/R/kable_as_image.R
index 665f9d9..725452d 100644
--- a/R/kable_as_image.R
+++ b/R/kable_as_image.R
@@ -65,7 +65,7 @@
"\\usepackage{xltxtra,xunicode}",
latex_header_includes,
"\\begin{document}",
- enc2utf8(as.character(kable_input)),
+ solve_enc(kable_input),
"\\end{document}"
)
temp_tex <- paste(temp_tex, collapse = "\n")
diff --git a/R/kable_styling.R b/R/kable_styling.R
index 5e4aff8..3d488fc 100644
--- a/R/kable_styling.R
+++ b/R/kable_styling.R
@@ -207,7 +207,8 @@
repeat_header_method <- match.arg(repeat_header_method)
out <- NULL
- out <- enc2utf8(as.character(kable_input))
+ out <- solve_enc(kable_input)
+
table_info <- magic_mirror(kable_input)
if ("striped" %in% latex_options) {
diff --git a/R/landscape.R b/R/landscape.R
index d7b3cd1..b888131 100644
--- a/R/landscape.R
+++ b/R/landscape.R
@@ -30,7 +30,7 @@
kable_attrs <- attributes(kable_input)
out <- paste0(
"\n\\begin{landscape}",
- enc2utf8(as.character(kable_input)),
+ solve_enc(kable_input),
"\n\\end{landscape}"
)
diff --git a/R/row_spec.R b/R/row_spec.R
index e4f6df1..fcbd226 100644
--- a/R/row_spec.R
+++ b/R/row_spec.R
@@ -179,7 +179,7 @@
color, background, align, font_size, angle,
hline_after, extra_latex_after) {
table_info <- magic_mirror(kable_input)
- out <- enc2utf8(as.character(kable_input))
+ out <- solve_enc(kable_input)
if (table_info$duplicated_rows) {
dup_fx_out <- fix_duplicated_rows_latex(out, table_info)
diff --git a/R/util.R b/R/util.R
index 45f1df1..6d89d1f 100644
--- a/R/util.R
+++ b/R/util.R
@@ -133,5 +133,8 @@
return(list(kable_input, table_info))
}
-
+# Solve enc issue for LaTeX tables
+solve_enc <- function(x) {
+ enc2utf8(as.character(base::format(x, trim = TRUE, justify = 'none')))
+}