Skip to content

How to use parameters with typst and quarto? #12317

Answered by cderv
durraniu asked this question in Q&A
Discussion options

You must be logged in to vote

If you want to it using knitr engine, you need to produce your typst raw block from R cell output

---
title: "CSV Data Report"
format: typst
keep-typ: true
params:
  csv_file: "data.csv"
---

```{r}
#| echo: false
#| output: asis
knitr::knit_expand(text = '
// Read the CSV file as raw text
#let csv_content = read("{{ params$csv_file }}")

// Split the CSV content into rows
#let rows = csv_content.split("\\n")

// Split each row into columns
#let data = rows.map(row => row.split(","))

= Data from CSV

#table(
  columns: 2,
  [*Column 1*], [*Column 2*],
  ..data.flatten()
)
') |> knitr::raw_block("typst")
```

This leverages

  • Templating logic: You could also use glue::glue(). And also store…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
3 replies
@durraniu
Comment options

@gordonwoodhull
Comment options

@mcanouil
Comment options

Comment options

You must be logged in to vote
1 reply
@durraniu
Comment options

Answer selected by durraniu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
4 participants