-
DescriptionI'm trying to generate pdfs using typst and quarto. Is it possible to provide csv file as a parameter for raw typst code to read it? For example:
This does not work though. Any advice is appreciated. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
You could try using the variable shortcode or meta shortcode, but by definition parameters are for computations thus code-cells not raw markup. Could you properly format your post using code blocks for code and terminal outputs? Thanks. |
Beta Was this translation helpful? Give feedback.
-
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
It will produce in the intermediate .md for Pandoc rendering ```{=typst}
// Read the CSV file as raw text
#let csv_content = read("data.csv")
// 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()
)
``` and so in typst // Read the CSV file as raw text
#let csv_content = read("data.csv")
// 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()
) Depending if your project uses R this could be easier than tweaking templates partials Hope it helps |
Beta Was this translation helpful? Give feedback.
If you want to it using knitr engine, you need to produce your typst raw block from R cell output
This leverages
glue::glue()
. And also store…