Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ dev.R
^_pkgdown\.yaml$
^pkgdown$
^LICENSE\.md$
^AGENTS\.md$
^vignettes/\.quarto$
^vignettes/*_files$
^dev/*
^tests/testthat/fonts/*
^tynding_
^data_internals/
^\.github$
Expand All @@ -31,7 +31,7 @@ dev.R
^release.sh
^example1.png
^example2.png
\.typ$
^[^/]+\.typ$
\.pdf$
^\.vscode$
^src/\.cargo$
Expand Down
57 changes: 57 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Repository Guidelines

## Project Structure & Module Organization

This repository is an R package named `tynding` that provides bindings to
Typst through Rust.

- `R/` contains exported R functions and wrappers.
- `src/rust/` contains the Rust implementation, Cargo metadata, and vendored
Rust dependencies.
- `src/` contains R package build glue such as `Makevars` and C entrypoints.
- `tests/testthat/` contains the R test suite, Typst fixtures, and test fonts.
- `man/` contains generated Rd documentation from roxygen comments.
- `docs/` contains the generated pkgdown site.
- `sandbox/` is for local experiments and generated examples.

## Build, Test, and Development Commands


- Compile Rust source:

```R
devtools::document()
```

- Load latest version:

```R
devtools::load_all()
```

- Run R tests:

```R
devtools::test()
```

- Run Rust tests:


```bash
cd src/rust && cargo test
```


## Coding Style & Naming Conventions

R code uses 2-space indentation and an 80-column line width, as configured in
`air.toml`. Prefer clear snake_case names for R functions, variables, and test
files. Document exported R functions with roxygen2 comments and keep generated
`man/` files in sync when documentation changes.

Rust code in `src/rust/` uses Rust 2021 and requires `rustc >= 1.89.0`. Follow
standard `rustfmt` formatting and keep Rust-facing names consistent with the
R wrappers they support.


12 changes: 9 additions & 3 deletions R/compile.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
#' @param output Optional output path. Defaults to the input path with the
#' extension implied by the output format.
#' @param font_path Optional path to font files.
#' @param pdf_standard Optional PDF standard specification. Options are: : `1.4`,
#' `1.5`, `1.6`, `1.7`, `2.0`, `a-1b`, `a-1a`, `a-2b`, `a-2u`, `a-2a`, `a-3b`,
#' `a-3u`, `a-3a`, `a-4`, `a-4f`, `a-4e`, `ua-1`. Only used for PDF output.
#' @param pdf_standard Optional PDF standard specification. Can be a single
#' standard or a character vector of compatible standards. Options are: `1.4`,
#' `1.5`, `1.6`, `1.7`, `2.0`, `a-1b`, `a-1a`, `a-2b`, `a-2u`, `a-2a`,
#' `a-3b`, `a-3u`, `a-3a`, `a-4`, `a-4f`, `a-4e`, `ua-1`. Only used for PDF
#' output.
#' @param output_format Optional output format. Supported values are `pdf`,
#' `html`, `png`, and `svg`. Defaults to `NULL`, which means "infer from
#' `output` when possible, otherwise use `pdf`". For multi-page `png` and `svg`
Expand Down Expand Up @@ -39,6 +41,10 @@ typst_compile <- function(
ignore_system_fonts = FALSE,
...
) {
if (!is.null(pdf_standard)) {
pdf_standard <- paste(pdf_standard, collapse = ",")
}

inputs_list <- list(...)

inputs <- vapply(
Expand Down
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

<img src="https://github.com/JosephBARBIERDARNAL/static/blob/main/r-libs/tynding/image.png?raw=true" alt="tynding logo" align="right" width="150px"/>

`tynding` is an R package that compiles Typst documents natively from R.
`tynding` is an R package that compiles Typst documents **natively** from R.

- it exposes a small API for <u>writing</u>, _evaluating_, and **compiling** Typst files
- it lets you specify:
It exposes a small API for <u>writing</u> and **compiling** Typst files and lets you specify:
- output format (pdf, png, svg, html)
- font path to search for font files
- pdf standard (for accessibility)
Expand All @@ -23,7 +22,7 @@ install.packages("tynding", repos = c("https://y-sunflower.r-universe.dev"))
```

> [!NOTE]
> `tynding` uses Typst 0.14.2, and the plan is to keep it as close as possible to the latest upstream version.
> `tynding` uses Typst 0.15.0, and the plan is to keep it as close as possible to the latest upstream version.

<br>
<br>
Expand Down Expand Up @@ -71,7 +70,17 @@ typ_file <- typst_write(markup)
pdf_file <- typst_compile(typ_file, pdf_standard = "ua-1")
```

For `ua-1`, your document needs a title. Unsupported or invalid standards raise an error.
Unsupported or invalid standards raise an error. Since Typst 0.15.0, you can export to multiple PDF standards at once when they are compatible:

```r
markup <- c(
'#set document(title: "accessible PDF")',
"= hello world"
)

typ_file <- typst_write(markup)
pdf_file <- typst_compile(typ_file, pdf_standard = c("a-2b", "ua-1"))
```

<br>

Expand Down
9 changes: 0 additions & 9 deletions justfile

This file was deleted.

8 changes: 5 additions & 3 deletions man/typst_compile.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Makevars.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
TARGET_DIR = ./rust/target
LIBDIR = $(TARGET_DIR)/@LIBDIR@
STATLIB = $(LIBDIR)/libtynding.a
PKG_LIBS = -L$(LIBDIR) -ltynding
PKG_LIBS = -L$(LIBDIR) -ltynding @SSL_LIBS@

all: $(SHLIB) rust_clean

Expand Down
Loading
Loading