Skip to content

Commit

Permalink
Merge pull request #1512 from kbrevoort/issue-1416
Browse files Browse the repository at this point in the history
Resolve Issue 1416
  • Loading branch information
rich-iannone authored Dec 19, 2023
2 parents 5db482e + 0072f93 commit b76fd28
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
25 changes: 19 additions & 6 deletions R/utils_render_latex.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,32 @@ footnote_mark_to_latex <- function(
spec <- "^i"
}

if (grepl("\\.", spec)) mark <- paste0(mark, ".")
if (grepl("b", spec)) mark <- paste0("\\textbf{", mark, "}")
if (grepl("i", spec)) mark <- paste0("\\textit{", mark, "}")
if (grepl("\\(|\\[", spec)) mark <- paste0("(", mark)
if (grepl("\\)|\\]", spec)) mark <- paste0(mark, ")")
if (grepl("\\.", spec)) mark <- sprintf_unless_na("%s.", mark)
if (grepl("b", spec)) mark <- sprintf_unless_na("\\textbf{%s}", mark)
if (grepl("i", spec)) mark <- sprintf_unless_na("\\textit{%s}", mark)
if (grepl("\\(|\\[", spec)) mark <- sprintf_unless_na("(%s", mark)
if (grepl("\\)|\\]", spec)) mark <- sprintf_unless_na("%s)", mark)

if (grepl("\\^", spec)) {
mark <- paste0("\\textsuperscript{", mark, "}")
mark <- sprintf_unless_na("\\textsuperscript{%s}", mark)
}

mark[is.na(mark)] <- ""

mark
}

#' @noRd
sprintf_unless_na <- function(fmt, x) {

ifelse(
is.na(x),
NA_character_,
sprintf(fmt, as.character(x))
)

}

#' @noRd
latex_body_row <- function(content, type) {

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/tab_footnote.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
Code
.
Output
[1] "\\setlength{\\LTpost}{0mm}\n\\begin{longtable}{rlcrrrrll}\n\\toprule\nnum & char & fctr & date & time & datetime & currency & row & group \\\\ \n\\midrule\\addlinespace[2.5pt]\n\\textsuperscript{\\textit{1}} 0.1111 & apricot & one & 2015-01-15 & 13:35 & 2018-01-01 02:22 & 49.95 & row\\_1 & grp\\_a \\\\ \n\\bottomrule\n\\end{longtable}\n\\begin{minipage}{\\linewidth}\n\\textsuperscript{\\textit{NA}}A footnote.\\\\\n\\textsuperscript{\\textit{1}}A footnote.\\\\\n\\end{minipage}\n"
[1] "\\setlength{\\LTpost}{0mm}\n\\begin{longtable}{rlcrrrrll}\n\\toprule\nnum & char & fctr & date & time & datetime & currency & row & group \\\\ \n\\midrule\\addlinespace[2.5pt]\n\\textsuperscript{\\textit{1}} 0.1111 & apricot & one & 2015-01-15 & 13:35 & 2018-01-01 02:22 & 49.95 & row\\_1 & grp\\_a \\\\ \n\\bottomrule\n\\end{longtable}\n\\begin{minipage}{\\linewidth}\nA footnote.\\\\\n\\textsuperscript{\\textit{1}}A footnote.\\\\\n\\end{minipage}\n"

---

Expand Down Expand Up @@ -301,7 +301,7 @@
Code
.
Output
[1] "\\setlength{\\LTpost}{0mm}\n\\begin{longtable}{rlcrrrrll}\n\\toprule\nnum & char & fctr & date & time & datetime & currency & row & group \\\\ \n\\midrule\\addlinespace[2.5pt]\n\\textsuperscript{\\textit{1}} 0.1111 & apricot & one & 2015-01-15 & 13:35 & 2018-01-01 02:22 & 49.95 & row\\_1 & grp\\_a \\\\ \n\\bottomrule\n\\end{longtable}\n\\begin{minipage}{\\linewidth}\n\\textsuperscript{\\textit{NA}}A footnote. \\textsuperscript{\\textit{NA}}A second footnote. \\textsuperscript{\\textit{1}}location note\\\\\n\\end{minipage}\n"
[1] "\\setlength{\\LTpost}{0mm}\n\\begin{longtable}{rlcrrrrll}\n\\toprule\nnum & char & fctr & date & time & datetime & currency & row & group \\\\ \n\\midrule\\addlinespace[2.5pt]\n\\textsuperscript{\\textit{1}} 0.1111 & apricot & one & 2015-01-15 & 13:35 & 2018-01-01 02:22 & 49.95 & row\\_1 & grp\\_a \\\\ \n\\bottomrule\n\\end{longtable}\n\\begin{minipage}{\\linewidth}\nA footnote. A second footnote. \\textsuperscript{\\textit{1}}location note\\\\\n\\end{minipage}\n"

---

Expand Down

2 comments on commit b76fd28

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.