| Title: | An R Package for Generating Typst Markup |
|---|---|
| Description: | Translate R functions into valid Typst markup and provide a large number of built-in tools for working with Typst data types and Quarto documents. |
| Authors: | Joseph Barbier [aut, cre] |
| Maintainer: | Joseph Barbier <[email protected]> |
| License: | file LICENSE |
| Version: | 0.4.0 |
| Built: | 2026-05-25 07:07:01 UTC |
| Source: | https://github.com/y-sunflower/r2typ |
Format x to its Typst equivalent. This function
is used internally to convert R data types to their
equivalent in Typst. It works recursively.
format_as_typst(x, named)format_as_typst(x, named)
x |
The object to convert. |
named |
Whether |
Formatted to Typst
format_as_typst(c(1, 2, 3)) format_as_typst(list(1, 2, 3)) format_as_typst(list(a=1, b=2, c=3)) format_as_typst(pt_(20)) format_as_typst(TRUE) format_as_typst(FALSE) format_as_typst(NULL)format_as_typst(c(1, 2, 3)) format_as_typst(list(1, 2, 3)) format_as_typst(list(a=1, b=2, c=3)) format_as_typst(pt_(20)) format_as_typst(TRUE) format_as_typst(FALSE) format_as_typst(NULL)
let is the keyword used to define variables in Typst.
It allows to create reusable components.
let(name, value)let(name, value)
name |
Name of the variables. |
value |
Value to assign to |
A character string
let("yellow", rgb_("#FFC300")) let("mycirc", circle(width=cm_(3), fill=yellow, square(height=cm_(1))))let("yellow", rgb_("#FFC300")) let("mycirc", circle(width=cm_(3), fill=yellow, square(height=cm_(1))))
... argumentsThis functions parses user arguments
from .... The goal is to get which arguments
are named or not, convert to their Typst format
and return a list with parsed info.
parse_typst_args(name, ...)parse_typst_args(name, ...)
name |
Name of the function |
... |
Any kind of named or not arguments. |
A list with function name, named args and unnamed args: list(name = name, named_str = named_str, unnamed_str = unnamed_str, expression_str = expression_str).
Convert to raw Typst for Quarto.
Using this function is required to include the
output of {r2typ} in your document.
Define output behavior when "knit printing" a typst_markup
object with knitr (mostly with Quarto).
Learn more in the Quarto usage vignette.
as_quarto_typst(x) ## S3 method for class 'typst_markup' knit_print(x, ...)as_quarto_typst(x) ## S3 method for class 'typst_markup' knit_print(x, ...)
x |
A character vector to interpret as raw typst or
an object of class |
... |
Ignored |
For as_quarto_typst(), a raw version wrapped in the
expected Quarto format. For knit_print.typst_markup(), output
from as_quarto_typst().
heading(level = 2, numbering = "1.1", "Hello world") |> as_quarto_typst() typ_markup <- heading(level = 2, numbering = "1.1", "Hello world") as_quarto_typst(typ_markup)heading(level = 2, numbering = "1.1", "Hello world") |> as_quarto_typst() typ_markup <- heading(level = 2, numbering = "1.1", "Hello world") as_quarto_typst(typ_markup)
Generates Typst set rules for a given function.
set_place(...) set_align(...) set_h(...) set_v(...) set_block(...) set_box(...) set_colbreak(...) set_stack(...) set_grid(...) set_hide(...) set_pagebreak(...) set_move(...) set_pad(...) set_page(...) set_scale(...) set_skew(...) set_rotate(...) set_bibliography(...) set_document(...) set_emph(...) set_figure(...) set_footnote(...) set_heading(...) set_enum(...) set_outline(...) set_par(...) set_parbreak(...) set_quote(...) set_strong(...) set_table(...) set_text(...) set_linebreak(...) set_overline(...) set_smallcaps(...) set_smartquote(...) set_strike(...) set_sub(...) set_super(...) set_underline(...) set_upper(...) set_raw(...) set_highlight(...) set_lower(...) set_image(...) set_circle(...) set_ellipse(...) set_line(...) set_rect(...) set_square(...)set_place(...) set_align(...) set_h(...) set_v(...) set_block(...) set_box(...) set_colbreak(...) set_stack(...) set_grid(...) set_hide(...) set_pagebreak(...) set_move(...) set_pad(...) set_page(...) set_scale(...) set_skew(...) set_rotate(...) set_bibliography(...) set_document(...) set_emph(...) set_figure(...) set_footnote(...) set_heading(...) set_enum(...) set_outline(...) set_par(...) set_parbreak(...) set_quote(...) set_strong(...) set_table(...) set_text(...) set_linebreak(...) set_overline(...) set_smallcaps(...) set_smartquote(...) set_strike(...) set_sub(...) set_super(...) set_underline(...) set_upper(...) set_raw(...) set_highlight(...) set_lower(...) set_image(...) set_circle(...) set_ellipse(...) set_line(...) set_rect(...) set_square(...)
... |
Named or unnamed arguments passed to the Typst function.
Named arguments become Typst parameters (e.g. |
A character string containing the generated Typst code.
set_place(dx = pt_(50)) set_h(weak = TRUE) set_v(weak = TRUE) set_block(breakable = FALSE, width = percent(50), height = auto, fill = aqua) set_box(clip = FALSE, width = percent(50), height = auto, fill = red) set_colbreak(weak = TRUE) set_stack(dir = ttb) set_grid(columns = 2, rows = 2, gutter = pt_(3)) set_pagebreak(weak = TRUE) set_move(dx = pt_(3), dy = pt_(5)) set_pad(x = percent(0) + pt_(5), y = percent(10) + pt_(0)) set_page( flipped = TRUE, columns = 2, fill = red ) set_scale(x = percent(-100)) set_skew(ax = deg(-12)) set_rotate(deg(-12)) set_bibliography(full = TRUE) set_document(author = "Me, myself & I") set_emph() set_figure(alt = "This is an alternative text") set_footnote(numbering = "*") set_heading(level = 3) set_enum(tight = FALSE) set_outline(depth = 1) set_par( `first-line-indent` = em(1), spacing = em(0.65), justify = TRUE ) set_quote(block = TRUE) set_strong(delta = 400) set_table(align = center, inset = pt_(10)) set_text(fill = silver, size = pt_(20)) set_linebreak(justify = TRUE) set_overline(evade = FALSE) set_smallcaps(all = TRUE) set_smartquote(double = FALSE) set_strike(offset = em(2)) set_sub(typographic = FALSE) set_super(typographic = FALSE) set_underline(stroke = pt_(3) + olive) set_raw(lang = "python", block = TRUE) set_highlight(extent = pt_(3)) image_(width = percent(80), height = auto) set_circle(fill = blue) set_ellipse(fill = green) set_line(length = percent(80), angle = deg(20)) set_rect(fill = aqua, radius = pt_(3)) set_square(size = pt_(5), fill = olive)set_place(dx = pt_(50)) set_h(weak = TRUE) set_v(weak = TRUE) set_block(breakable = FALSE, width = percent(50), height = auto, fill = aqua) set_box(clip = FALSE, width = percent(50), height = auto, fill = red) set_colbreak(weak = TRUE) set_stack(dir = ttb) set_grid(columns = 2, rows = 2, gutter = pt_(3)) set_pagebreak(weak = TRUE) set_move(dx = pt_(3), dy = pt_(5)) set_pad(x = percent(0) + pt_(5), y = percent(10) + pt_(0)) set_page( flipped = TRUE, columns = 2, fill = red ) set_scale(x = percent(-100)) set_skew(ax = deg(-12)) set_rotate(deg(-12)) set_bibliography(full = TRUE) set_document(author = "Me, myself & I") set_emph() set_figure(alt = "This is an alternative text") set_footnote(numbering = "*") set_heading(level = 3) set_enum(tight = FALSE) set_outline(depth = 1) set_par( `first-line-indent` = em(1), spacing = em(0.65), justify = TRUE ) set_quote(block = TRUE) set_strong(delta = 400) set_table(align = center, inset = pt_(10)) set_text(fill = silver, size = pt_(20)) set_linebreak(justify = TRUE) set_overline(evade = FALSE) set_smallcaps(all = TRUE) set_smartquote(double = FALSE) set_strike(offset = em(2)) set_sub(typographic = FALSE) set_super(typographic = FALSE) set_underline(stroke = pt_(3) + olive) set_raw(lang = "python", block = TRUE) set_highlight(extent = pt_(3)) image_(width = percent(80), height = auto) set_circle(fill = blue) set_ellipse(fill = green) set_line(length = percent(80), angle = deg(20)) set_rect(fill = aqua, radius = pt_(3)) set_square(size = pt_(5), fill = olive)
Generates Typst show rules for a given function.
show_place(set_rule) show_align(set_rule) show_h(set_rule) show_v(set_rule) show_block(set_rule) show_box(set_rule) show_colbreak(set_rule) show_stack(set_rule) show_grid(set_rule) show_hide(set_rule) show_pagebreak(set_rule) show_move(set_rule) show_pad(set_rule) show_page(set_rule) show_scale(set_rule) show_skew(set_rule) show_rotate(set_rule) show_bibliography(set_rule) show_list(set_rule) show_document(set_rule) show_emph(set_rule) show_figure(set_rule) show_footnote(set_rule) show_heading(set_rule) show_enum(set_rule) show_outline(set_rule) show_par(set_rule) show_parbreak(set_rule) show_quote(set_rule) show_strong(set_rule) show_table(set_rule) show_text(set_rule) show_linebreak(set_rule) show_overline(set_rule) show_smallcaps(set_rule) show_smartquote(set_rule) show_strike(set_rule) show_sub(set_rule) show_super(set_rule) show_underline(set_rule) show_upper(set_rule) show_raw(set_rule) show_highlight(set_rule) show_lower(set_rule) show_image(set_rule) show_circle(set_rule) show_ellipse(set_rule) show_line(set_rule) show_rect(set_rule) show_square(set_rule)show_place(set_rule) show_align(set_rule) show_h(set_rule) show_v(set_rule) show_block(set_rule) show_box(set_rule) show_colbreak(set_rule) show_stack(set_rule) show_grid(set_rule) show_hide(set_rule) show_pagebreak(set_rule) show_move(set_rule) show_pad(set_rule) show_page(set_rule) show_scale(set_rule) show_skew(set_rule) show_rotate(set_rule) show_bibliography(set_rule) show_list(set_rule) show_document(set_rule) show_emph(set_rule) show_figure(set_rule) show_footnote(set_rule) show_heading(set_rule) show_enum(set_rule) show_outline(set_rule) show_par(set_rule) show_parbreak(set_rule) show_quote(set_rule) show_strong(set_rule) show_table(set_rule) show_text(set_rule) show_linebreak(set_rule) show_overline(set_rule) show_smallcaps(set_rule) show_smartquote(set_rule) show_strike(set_rule) show_sub(set_rule) show_super(set_rule) show_underline(set_rule) show_upper(set_rule) show_raw(set_rule) show_highlight(set_rule) show_lower(set_rule) show_image(set_rule) show_circle(set_rule) show_ellipse(set_rule) show_line(set_rule) show_rect(set_rule) show_square(set_rule)
set_rule |
A set rule made with one of the set functions in |
A character string containing the generated Typst code.
These functions generate special objects representing alignment in Typst code.
They can be used as arguments in functions like text_() or heading() to
produce properly formatted Typst code.
## S3 method for class 'typst_alignment' left_align + right_align horizon top bottom center left right## S3 method for class 'typst_alignment' left_align + right_align horizon top bottom center left right
left_align |
A typst alignment |
right_align |
A typst alignment |
An object of class typst_alignment (inherits from typst_expression) of length 1.
An object of class typst_alignment (inherits from typst_expression) of length 1.
An object of class typst_alignment (inherits from typst_expression) of length 1.
An object of class typst_alignment (inherits from typst_expression) of length 1.
An object of class typst_alignment (inherits from typst_expression) of length 1.
An object of class typst_alignment (inherits from typst_expression) of length 1.
An object of class typst_alignment.
left center + horizon top + rightleft center + horizon top + right
The auto keyword in Typst.
autoauto
An object of class typst_auto (inherits from typst_expression) of length 1.
An object of class typst_auto and typst_expression.
autoauto
These functions generate special objects representing colors in Typst code.
They can be used as arguments in functions like text_() or heading() to
produce properly formatted Typst code.
rgb_(hex) silver grey black white navy blue aqua teal eastern purple fuchsia maroon red orange yellow olive green limergb_(hex) silver grey black white navy blue aqua teal eastern purple fuchsia maroon red orange yellow olive green lime
hex |
An hexadecimal color. |
An object of class typst_color (inherits from typst_expression) of length 1.
An object of class typst_color (inherits from typst_expression) of length 1.
An object of class typst_color (inherits from typst_expression) of length 1.
An object of class typst_color (inherits from typst_expression) of length 1.
An object of class typst_color (inherits from typst_expression) of length 1.
An object of class typst_color (inherits from typst_expression) of length 1.
An object of class typst_color (inherits from typst_expression) of length 1.
An object of class typst_color (inherits from typst_expression) of length 1.
An object of class typst_color (inherits from typst_expression) of length 1.
An object of class typst_color (inherits from typst_expression) of length 1.
An object of class typst_color (inherits from typst_expression) of length 1.
An object of class typst_color (inherits from typst_expression) of length 1.
An object of class typst_color (inherits from typst_expression) of length 1.
An object of class typst_color (inherits from typst_expression) of length 1.
An object of class typst_color (inherits from typst_expression) of length 1.
An object of class typst_color (inherits from typst_expression) of length 1.
An object of class typst_color (inherits from typst_expression) of length 1.
An object of class typst_color (inherits from typst_expression) of length 1.
An object of class typst_color and typst_expression.
rgb_("#ffffff") text_(font = "Roboto", fill = rgb_("#ffffff"), "cookies are healthy!!") red blue blackrgb_("#ffffff") text_(font = "Roboto", fill = rgb_("#ffffff"), "cookies are healthy!!") red blue black
.typ file to a .pdf file and return the output pathCompile a .typ file to a .pdf file and return the output path.
typst_compile(file, ...)typst_compile(file, ...)
file |
Path to an existing |
... |
Additional arguments passed to |
The path to the compiled PDF file.
These functions generate special objects representing directions in Typst.
They can be used as arguments in functions like stack().
ltr rtl ttb bttltr rtl ttb btt
An object of class typst_direction (inherits from typst_expression) of length 1.
An object of class typst_direction (inherits from typst_expression) of length 1.
An object of class typst_direction (inherits from typst_expression) of length 1.
An object of class typst_direction (inherits from typst_expression) of length 1.
An object of class typst_direction and typst_expression.
ltr rtl ttb bttltr rtl ttb btt
Used to create all Typst functions in r2typ.
Arguments are parsed and then translated to Typst.
Generates Typst code with element. Named arguments are included
as Typst keyword arguments (e.g. level, numbering), and unnamed arguments
are used as the heading content.
But please note that this behavior might be different in some functions
to respect true Typst syntax (such as #table() for instance).
typst_function(name, ...) assert(...) bytes(...) datetime(...) duration(...) eval_(...) panic(...) regex(...) repr(...) str_(...) symbol(...) decimal(...) type(...) version(...) place(...) align(...) h(...) v(...) block(...) box_(...) colbreak(...) stack(...) grid_(...) hide(...) pagebreak(...) move(...) pad(...) page(...) scale_(...) skew(...) rotate(...) bibliography(...) set_list(...) list_(...) document(...) emph(...) figure(...) footnote(...) heading(...) enum(...) outline(...) par_(...) parbreak(...) quote_(...) strong(...) table_(...) text_(...) linebreak(...) overline(...) smallcaps(...) smartquote(...) strike(...) sub_(...) super(...) underline(...) upper(...) raw_(...) highlight(...) lower(...) image_(...) circle(...) ellipse(...) line_(...) rect_(...) square(...)typst_function(name, ...) assert(...) bytes(...) datetime(...) duration(...) eval_(...) panic(...) regex(...) repr(...) str_(...) symbol(...) decimal(...) type(...) version(...) place(...) align(...) h(...) v(...) block(...) box_(...) colbreak(...) stack(...) grid_(...) hide(...) pagebreak(...) move(...) pad(...) page(...) scale_(...) skew(...) rotate(...) bibliography(...) set_list(...) list_(...) document(...) emph(...) figure(...) footnote(...) heading(...) enum(...) outline(...) par_(...) parbreak(...) quote_(...) strong(...) table_(...) text_(...) linebreak(...) overline(...) smallcaps(...) smartquote(...) strike(...) sub_(...) super(...) underline(...) upper(...) raw_(...) highlight(...) lower(...) image_(...) circle(...) ellipse(...) line_(...) rect_(...) square(...)
name |
Function name |
... |
Named or unnamed arguments passed to the Typst function.
Named arguments become Typst parameters (e.g. |
A character vector with well formatted Typst.
A character string containing the generated Typst code.
assert(1 < 2, message = "math broke") bytes("more cookies...") datetime(year = 2012, month = 8, day = 3) duration(days = 3, hours = 12) eval_("*Markup!*", mode = "markup") panic("this is wrong") regex("\\d+") repr("hello") str_("hello") symbol("10") decimal("10") type("10") version(1, 2, 3, 4) version(c(1, 2, 3, 4)) place(dx = pt_(50), "pasta") align(center + horizon, "hey") h(fr(3)) v(percent(3), weak = TRUE) block(breakable = FALSE, width = percent(50), height = auto, fill = aqua, "cookies") box_(clip = FALSE, width = percent(50), height = auto, fill = red, "ice cream") colbreak(weak = TRUE) stack(dir = ttb, "hey", "you", "!") grid_(columns = 2, rows = 2, gutter = pt_(3), "hey", "cookies", "ice", "cream") hide("this is hidden") pagebreak("this is hidden") move(dx = pt_(3), dy = pt_(5), "pasta") pad(x = percent(0) + pt_(5), y = percent(10) + pt_(0), image_("file.svg")) page( flipped = TRUE, columns = 2, fill = red, place( top + left, dx = pt_(-5), rect_(fill = blue, radius = pt_(2), "yooooo") ) ) scale_(x = percent(-100), "This is mirrored") skew(ax = deg(-12), "This is some fake italic text.") rotate(deg(-12), "What a weird feature!") bibliography(full = TRUE, "more cookies...") set_list(tight = TRUE) list_(tight = TRUE, "I", "need", "a cat") emph("please! more cookies...") figure(alt = "This is an alternative text", "more cookies...") footnote(numbering = "*", "Cheese") heading(level = 3, "Intro", "More text") enum(tight = FALSE, "I wonder", "if", "people", "will", "see", "this text") outline(depth = 1) par_( `first-line-indent` = em(1), spacing = em(0.65), justify = TRUE, "more cookies..." ) parbreak() quote_(block = TRUE, "more cookies...") strong("strong coffee") table_(align = center, inset = pt_(10), "a", "b", "c", "d") data <- data.frame( name = c("Alice", "Bob"), score = c(12, 18) ) table_(data, align = center) text_(fill = silver, size = pt_(20), "The most basic function in Typst...") linebreak(justify = TRUE) overline(evade = FALSE, "not sure who even uses this function") smallcaps(all = TRUE, "Niche but useful func") smartquote(double = FALSE) strike(offset = em(2), "strike function is kind of cool tbh!") sub_(typographic = FALSE, "not typographic") super(typographic = FALSE, "not typographic") underline(stroke = pt_(3) + olive, "what a weird underline") raw_("print('hello world')", lang = "python", block = TRUE) highlight(extent = pt_(3), "hey") lower("hey") ## Not run: image_(width = percent(80), height = auto, "../docs/link.svg") circle(fill = blue) ellipse(fill = green) line_(length = percent(80), angle = deg(20)) rect_(fill = aqua, radius = pt_(3)) square(size = pt_(5), fill = olive)assert(1 < 2, message = "math broke") bytes("more cookies...") datetime(year = 2012, month = 8, day = 3) duration(days = 3, hours = 12) eval_("*Markup!*", mode = "markup") panic("this is wrong") regex("\\d+") repr("hello") str_("hello") symbol("10") decimal("10") type("10") version(1, 2, 3, 4) version(c(1, 2, 3, 4)) place(dx = pt_(50), "pasta") align(center + horizon, "hey") h(fr(3)) v(percent(3), weak = TRUE) block(breakable = FALSE, width = percent(50), height = auto, fill = aqua, "cookies") box_(clip = FALSE, width = percent(50), height = auto, fill = red, "ice cream") colbreak(weak = TRUE) stack(dir = ttb, "hey", "you", "!") grid_(columns = 2, rows = 2, gutter = pt_(3), "hey", "cookies", "ice", "cream") hide("this is hidden") pagebreak("this is hidden") move(dx = pt_(3), dy = pt_(5), "pasta") pad(x = percent(0) + pt_(5), y = percent(10) + pt_(0), image_("file.svg")) page( flipped = TRUE, columns = 2, fill = red, place( top + left, dx = pt_(-5), rect_(fill = blue, radius = pt_(2), "yooooo") ) ) scale_(x = percent(-100), "This is mirrored") skew(ax = deg(-12), "This is some fake italic text.") rotate(deg(-12), "What a weird feature!") bibliography(full = TRUE, "more cookies...") set_list(tight = TRUE) list_(tight = TRUE, "I", "need", "a cat") emph("please! more cookies...") figure(alt = "This is an alternative text", "more cookies...") footnote(numbering = "*", "Cheese") heading(level = 3, "Intro", "More text") enum(tight = FALSE, "I wonder", "if", "people", "will", "see", "this text") outline(depth = 1) par_( `first-line-indent` = em(1), spacing = em(0.65), justify = TRUE, "more cookies..." ) parbreak() quote_(block = TRUE, "more cookies...") strong("strong coffee") table_(align = center, inset = pt_(10), "a", "b", "c", "d") data <- data.frame( name = c("Alice", "Bob"), score = c(12, 18) ) table_(data, align = center) text_(fill = silver, size = pt_(20), "The most basic function in Typst...") linebreak(justify = TRUE) overline(evade = FALSE, "not sure who even uses this function") smallcaps(all = TRUE, "Niche but useful func") smartquote(double = FALSE) strike(offset = em(2), "strike function is kind of cool tbh!") sub_(typographic = FALSE, "not typographic") super(typographic = FALSE, "not typographic") underline(stroke = pt_(3) + olive, "what a weird underline") raw_("print('hello world')", lang = "python", block = TRUE) highlight(extent = pt_(3), "hey") lower("hey") ## Not run: image_(width = percent(80), height = auto, "../docs/link.svg") circle(fill = blue) ellipse(fill = green) line_(length = percent(80), angle = deg(20)) rect_(fill = aqua, radius = pt_(3)) square(size = pt_(5), fill = olive)
These functions generate special objects representing units in Typst code.
They can be used as arguments in functions like text_() or heading() to
produce properly formatted Typst code.
pt_(x) mm(x) cm_(x) em(x) percent(x) fr(x) deg(x) rad(x)pt_(x) mm(x) cm_(x) em(x) percent(x) fr(x) deg(x) rad(x)
x |
Numeric value of the unit. |
An object of class typst_unit with an associated unit attribute.
When passed to a Typst-generating function, it is converted to the
appropriate unit string (e.g., 12pt, 1.5em, 80%).
em(1.5) # Represents 1.5em percent(80) # Represents 80% fr(2) # Represents 2fr pt_(12) # Represents 12pt rad(3.14) # Represents 3.14rad text_(size = pt_(12), "Hello world")em(1.5) # Represents 1.5em percent(80) # Represents 80% fr(2) # Represents 2fr pt_(12) # Represents 12pt rad(3.14) # Represents 3.14rad text_(size = pt_(12), "Hello world")
Create a Typst file (.typ) from a character vector.
typst_write(x, ...)typst_write(x, ...)
x |
A character vector representing Typst code. |
... |
Additional arguments passed to |
The path to the written .typ file, invisibly.
## Not run: code <- c("= Hello World", "This is a Typst document.") typst_write(code, output = "hello.typ") ## End(Not run)## Not run: code <- c("= Hello World", "This is a Typst document.") typst_write(code, output = "hello.typ") ## End(Not run)