Skip to content

Commit

Permalink
typst caption
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Jan 28, 2024
1 parent 8db326b commit 68288c5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
7 changes: 7 additions & 0 deletions R/finalize_typst.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,12 @@ finalize_typst <- function(x) {
out <- sub("$TINYTABLE_TYPST_NCOL", meta(x, "ncols"), out, fixed = TRUE)
out <- sub("$TINYTABLE_TYPST_NHEAD", meta(x, "nhead"), out, fixed = TRUE)

cap <- meta(x, "caption")
if (!is.null(cap)) {
out <- sub("$TINYTABLE_TYPST_CAPTION", sprintf("caption: [%s],", cap), out, fixed = TRUE)
} else {
out <- sub("$TINYTABLE_TYPST_CAPTION", "", out, fixed = TRUE)
}

return(out)
}
1 change: 1 addition & 0 deletions R/tt_typst.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ tt_typst <- function(x, caption, theme, width, notes, ...) {
out <- style_typst(out, i = seq(1, meta(out)$nrows, by = 2), background = "#ededed")
}


class(out) <- c("tinytable", "knit_asis", class(out))
return(out)
}
Expand Down
28 changes: 16 additions & 12 deletions inst/templates/typst.typ
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@
#let nrow = $TINYTABLE_TYPST_NROW;
#let ncol = $TINYTABLE_TYPST_NCOL;
#tablex(
columns: ncol,
header-rows: nhead,
align: left + horizon,
auto-lines: false,
#figure(
$TINYTABLE_TYPST_CAPTION
tablex(
columns: ncol,
header-rows: nhead,
align: left + horizon,
auto-lines: false,

// tinytable lines before
// tinytable lines before

map-cells: cell => {
map-cells: cell => {

// tinytable cell style before
return cell;
},
// tinytable cell style before
return cell;
},

// tinytable cell content after
// tinytable cell content after

) // end tablex
) // end figure

)

0 comments on commit 68288c5

Please sign in to comment.