From f157380e7abcb7964612a480e09e59a45e7a01be Mon Sep 17 00:00:00 2001 From: Jan Meis Date: Tue, 30 Jan 2024 13:14:55 +0100 Subject: [PATCH] Properly escape < and > if they appear in the column headings in LaTeX tables. --- DESCRIPTION | 4 ++-- NEWS.md | 4 ++++ R/descr.R | 8 +++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 95d0c8a..848a1c3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: DescrTab2 Type: Package Title: Publication Quality Descriptive Statistics Tables -Version: 2.1.25 -Date: 2023-12-15 +Version: 2.1.26 +Date: 2024-01-30 Authors@R: c(person("Jan", "Meis", role = c("aut", "cre"), email="meis@imbi.uni-heidelberg.de", comment = c(ORCID = "0000-0001-5407-7220")), person("Lukas", "Baumann", role = c("aut"), comment = c(ORCID = "0000-0001-7931-7470")), person("Maximilian", "Pilz", role = c("aut"), comment = c(ORCID = "0000-0002-9685-1613")), diff --git a/NEWS.md b/NEWS.md index 6eb53b5..3e43350 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# Version 2.1.26 + +* Properly escape < and > if they appear in the column headings in LaTeX tables. + # Version 2.1.25 * Throw an error if a group level is called "Total", "Variable", "p", "test_name", "CI", or "CI_name". diff --git a/R/descr.R b/R/descr.R index 0c0a6e2..2eb0ba7 100644 --- a/R/descr.R +++ b/R/descr.R @@ -1374,8 +1374,10 @@ if ("CI_name" %in% names(tibl)) { alig <- paste0(c("l", rep("c", ncol(tibl) - 1)), collapse = "") alig2 <- paste0(c("l", rep("c", ncol(tibl) - 1))) - actual_colnames <- names(tibl[!indx_varnames, ]) - + actual_colnames <- names(tibl[!indx_varnames, ]) |> + as_tibble() |> + escape_latex_symbols(numEscapes = 2) |> + pull(value) N_numbers <- c("", paste0("(N=", DescrPrintObj[["group"]][["lengths"]][DescrPrintObj[["group_labels"]] %in% names(tibl)], ")")) @@ -1424,7 +1426,7 @@ if ("CI_name" %in% names(tibl)) { ) %>% column_spec(1, width = paste0(width + 1, "em")) %>% kableExtra::pack_rows(index = lengths, latex_gap_space = "0.5cm", escape = FALSE) %>% - add_header_above(actual_colnames, line = FALSE, align = alig2) %>% + add_header_above(actual_colnames, line = FALSE, align = alig2, escape = FALSE) %>% kable_styling( latex_options = "repeat_header", repeat_header_continued = FALSE