From a54b815698a5840b6512194ed852e967c2e71dd0 Mon Sep 17 00:00:00 2001 From: Vincent Arel-Bundock Date: Thu, 12 Dec 2024 15:36:39 -0500 Subject: [PATCH] style captions and notes. Finalize --- DESCRIPTION | 2 +- NEWS.md | 2 +- R/finalize_typst.R | 2 +- R/style_tt.R | 5 ++++- inst/tinytest/_tinysnapshot/typst-complicated.txt | 2 +- man/style_tt.Rd | 7 ++++++- sandbox/typst.qmd | 7 +++++++ 7 files changed, 21 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index eb6b295a..526cba7e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: tinytable Type: Package Title: Simple and Configurable Tables in 'HTML', 'LaTeX', 'Markdown', 'Word', 'PNG', 'PDF', and 'Typst' Formats Description: Create highly customized tables with this simple and dependency-free package. Data frames can be converted to 'HTML', 'LaTeX', 'Markdown', 'Word', 'PNG', 'PDF', or 'Typst' tables. The user interface is minimalist and easy to learn. The syntax is concise. 'HTML' tables can be customized using the flexible 'Bootstrap' framework, and 'LaTeX' code with the 'tabularray' package. -Version: 0.6.1.2 +Version: 0.6.1.3 Imports: methods Depends: diff --git a/NEWS.md b/NEWS.md index 11bcee4e..ca14fecd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,7 +8,7 @@ Bugs: New: -* `style_tt("notes")` can style footnotes. +* `style_tt("notes")` and `style_tt("caption")` can style footnotes and captions. Note: This will only style captions handled by the `caption` argument in `tt()`, and not captions created by Quarto. Misc: diff --git a/R/finalize_typst.R b/R/finalize_typst.R index 216b0334..afffef03 100644 --- a/R/finalize_typst.R +++ b/R/finalize_typst.R @@ -10,7 +10,7 @@ setMethod( cap <- x@caption if (length(cap) == 1) { - out <- sub("$TINYTABLE_TYPST_CAPTION", sprintf("caption: [%s],", cap), out, fixed = TRUE) + out <- sub("$TINYTABLE_TYPST_CAPTION", sprintf("caption: %s,", cap), out, fixed = TRUE) } else { out <- sub("$TINYTABLE_TYPST_CAPTION", "", out, fixed = TRUE) } diff --git a/R/style_tt.R b/R/style_tt.R index b905e7b1..4cec207d 100644 --- a/R/style_tt.R +++ b/R/style_tt.R @@ -4,7 +4,10 @@ #' This function applies styling to a table created by `tt()`. It allows customization of text style (bold, italic, monospace), text and background colors, font size, cell width, text alignment, column span, and indentation. The function also supports passing native instructions to LaTeX (tabularray) and HTML (bootstrap) formats. #' #' @param x A table object created by `tt()`. -#' @param i Row indices where the styling should be applied. Can be a single value, a vector, or a logical matrix with the same number of rows and columns as `x`. `i=0` is the header, and negative values are higher level headers. Row indices refer to rows *after* the insertion of row labels by `group_tt()`, when applicable. +#' @param i Numeric vector, logical matrix, or string.. +#' - Numeric vector: Row indices where the styling should be applied. Can be a single value or a vector. +#' - Logical matrix: A matrix with the same number of rows and columns as `x`. `i=0` is the header, and negative values are higher level headers. Row indices refer to rows *after* the insertion of row labels by `group_tt()`, when applicable. +#' - String: "notes" or "caption". #' @param j Column indices where the styling should be applied. Can be: #' + Integer vectors indicating column positions. #' + Character vector indicating column names. diff --git a/inst/tinytest/_tinysnapshot/typst-complicated.txt b/inst/tinytest/_tinysnapshot/typst-complicated.txt index e7f7be92..dfefc85f 100644 --- a/inst/tinytest/_tinysnapshot/typst-complicated.txt +++ b/inst/tinytest/_tinysnapshot/typst-complicated.txt @@ -1,6 +1,6 @@ #show figure: set block(breakable: true) #figure( // start figure preamble - caption: [text([Hello World])], + caption: text([Hello World]), kind: "tinytable", supplement: "Table", // end figure preamble diff --git a/man/style_tt.Rd b/man/style_tt.Rd index 97023bba..5c54a1da 100644 --- a/man/style_tt.Rd +++ b/man/style_tt.Rd @@ -37,7 +37,12 @@ style_tt( \arguments{ \item{x}{A table object created by \code{tt()}.} -\item{i}{Row indices where the styling should be applied. Can be a single value, a vector, or a logical matrix with the same number of rows and columns as \code{x}. \code{i=0} is the header, and negative values are higher level headers. Row indices refer to rows \emph{after} the insertion of row labels by \code{group_tt()}, when applicable.} +\item{i}{Numeric vector, logical matrix, or string.. +\itemize{ +\item Numeric vector: Row indices where the styling should be applied. Can be a single value or a vector. +\item Logical matrix: A matrix with the same number of rows and columns as \code{x}. \code{i=0} is the header, and negative values are higher level headers. Row indices refer to rows \emph{after} the insertion of row labels by \code{group_tt()}, when applicable. +\item String: "notes" or "caption". +}} \item{j}{Column indices where the styling should be applied. Can be: \itemize{ diff --git a/sandbox/typst.qmd b/sandbox/typst.qmd index ea19181e..0e02396e 100644 --- a/sandbox/typst.qmd +++ b/sandbox/typst.qmd @@ -11,6 +11,13 @@ options(tinytable_quarto_figure = TRUE) options(tinytable_print_output = "typst") ``` +```{r} +tt(head(iris), caption = "Hello World", notes = "This is a note") |> + style_tt("notes", color = "orange", italic = TRUE) |> + style_tt("caption", color = "green", bold = TRUE, strikeout = TRUE) +``` + + ```{r} # Semi-complicated tab <- tt(mtcars[1:4, 1:5], caption = "Hello World") |>