| Title: | Create Nice Code Images |
|---|---|
| Description: | Render typeset code snippets using 'Typst'. Supports syntax highlighting for many languages, multiple output formats, and theming via 'tmTheme' files. Designed for documentation, teaching materials, and reproducible code presentation. |
| Authors: | Christopher T. Kenny [aut, cre] (ORCID: <https://orcid.org/0000-0002-9386-6860>) |
| Maintainer: | Christopher T. Kenny <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.1 |
| Built: | 2026-05-09 21:42:38 UTC |
| Source: | https://github.com/christopherkenny/snippet |
This function renders a static code snippet using a Typst template and the typr package. It is purely visual and does not evaluate code. Styling, syntax highlighting, and window style are all configurable.
snippet( code, lang = NULL, title = "", style = c("windows", "mac", "none"), background, theme = "auto", width = 5, line_numbers = FALSE, format = c("png", "pdf", "svg"), output_file = NULL )snippet( code, lang = NULL, title = "", style = c("windows", "mac", "none"), background, theme = "auto", width = 5, line_numbers = FALSE, format = c("png", "pdf", "svg"), output_file = NULL )
code |
Character vector, string, or file path. Code to render. If nothing is supplied, it defaults to reading your current clipboard contents. |
lang |
Language name for syntax highlighting. Inferred from file
extension if |
title |
Optional title for the code snippet. |
style |
Window style: one of |
background |
Background color as a hex string. If not provided,
defaults to the background color of the selected theme, or |
theme |
Theme name from |
width |
Width of the rendered output in inches. Defaults to |
line_numbers |
Whether to show line numbers. Defaults to |
format |
Output format, one of |
output_file |
File path to write the rendered result. If |
Invisibly, the path to the rendered file.
## Not run: snippet('x <- 1:10\nmean(x)') ## End(Not run)## Not run: snippet('x <- 1:10\nmean(x)') ## End(Not run)
Downloads or copies a .tmTheme file to the user's snippet cache directory,
making it available to snippet() and snippet_themes().
snippet_install_theme(theme, overwrite = FALSE)snippet_install_theme(theme, overwrite = FALSE)
theme |
One of:
|
overwrite |
Whether to overwrite an existing installed theme.
Defaults to |
Invisibly, the path to the installed theme file.
## Not run: snippet_install_theme('Dracula') snippet_install_theme('https://example.com/my-theme.tmTheme') snippet_install_theme('/path/to/my-theme.tmTheme') ## End(Not run)## Not run: snippet_install_theme('Dracula') snippet_install_theme('https://example.com/my-theme.tmTheme') snippet_install_theme('/path/to/my-theme.tmTheme') ## End(Not run)
Returns a named character vector of URLs for themes that can be installed
by name via snippet_install_theme().
snippet_known_themes()snippet_known_themes()
A named character vector where names are theme names and values are download URLs.
snippet_known_themes()snippet_known_themes()
Returns paths to both bundled themes and any themes previously installed
with snippet_install_theme().
snippet_themes()snippet_themes()
A named character vector of file paths to available themes. Names are human-readable theme names derived from file names.
snippet_themes()snippet_themes()