Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where un-escaped curly braces can arrive in the styling_latex_font_size() function #767

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions R/kable_styling.R
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,18 @@ styling_latex_position_float <- function(x, table_info, option, table.envir,
styling_latex_font_size <- function(x, table_info, font_size) {
row_height <- font_size + 2
if (table_info$tabular != "longtable" & table_info$table_env) {
# Following two lines use negative lookbehinds to find curly braces
# which have not been escaped and escape them. This situation arises
# when the user has declared latex column types like this (C = center):
#
# \newcommand{\PreserveBackslash}[1]{\let\temp=\\#1\let\\=\temp}
# \newcolumntype{C}[1]{>{\PreserveBackslash\centering}p{#1}}
table_info$begin_tabular <- gsub("(?<!\\\\){", "\\\\{",
table_info$begin_tabular,
perl = TRUE)
table_info$begin_tabular <- gsub("(?<!\\\\)}", "\\\\}",
table_info$begin_tabular,
perl = TRUE)
return(sub(table_info$begin_tabular,
paste0("\\\\fontsize\\{", font_size, "\\}\\{", row_height,
"\\}\\\\selectfont\n", table_info$begin_tabular),
Expand Down