Skip to content

Commit

Permalink
style_tt refactor complete
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Jan 14, 2024
1 parent 23a222a commit dc7d97a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
22 changes: 10 additions & 12 deletions R/style_tt.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,16 @@ style_tt <- function(
assert_integerish(j, lower = 1, upper = attr(x, "ncol"))


if (component == "cell") {
if (inherits(x, "tinytable_tabularray")) {
if (component == "cell") {
idx <- expand.grid(i = i, j = j)
} else if (component == "row") {
idx <- data.frame(i = i)
} else if (component == "col") {
idx <- data.frame(j = j)
}
} else {
idx <- expand.grid(i = i, j = j)
} else if (component == "row") {
idx <- data.frame(i = i)
} else if (component == "col") {
idx <- data.frame(j = j)
}

# do not style header by default. JS index starts at 0
Expand Down Expand Up @@ -195,13 +199,7 @@ style_tt <- function(
}

# Apply Tabularray command
if (any(c("colspan", "rowspan") %in% names(tabularray))) {
span <- tabularray[names(tabularray) %in% c("colspan", "rowspan")]
span <- paste(span, collapse = ",")
tabularray <- tabularray[!names(tabularray) %in% c("colspan", "rowspan")]
} else {
span <- ""
}
span <- if (!is.null(colspan)) paste0("c=", colspan, ",") else ""

if (inherits(x, "tinytable_tabularray")) {
for (k in seq_len(nrow(idx))) {
Expand Down
5 changes: 4 additions & 1 deletion vignettes/tutorial.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,15 @@ dat <- data.frame(Math = c("\\( x^2 + y^2 = z^2 \\)", "\\( \\frac{1}{2} \\)"))
tt(dat, align = "c")
```

```{r, eval = knitr::is_latex_output()}
::: {.content-visible when-format="pdf"}
In LaTeX (PDF), you can also use the `mode` inner setting from `tabularray` to render math in tables without delimiters (see @sec-tabularray for details on `tabularray`):

```{r, eval = knitr::is_latex_output()}
dat <- data.frame(Math = c("x^2 + y^2 = z^2", "\\frac{1}{2}"))
tt(dat, align = "c") |> style_tt(tabularray_inner = "column{1}={mode=math},")
```
:::

# Style

Expand Down

0 comments on commit dc7d97a

Please sign in to comment.