| Title: | The 'pic' Graphics Language Rendered to SVG, PNG and PDF |
|---|---|
| Description: | Renders diagrams written in the 'pic' picture-drawing language (Kernighan, 1984) to SVG, PNG and PDF, using 'rpic' <https://github.com/milkway/rpic-lang>, a reimplementation of 'pic' in 'Rust' with no system dependencies. Includes a native circuit-element library in the spirit of 'circuit_macros', TeX math labels typeset natively, structured compile diagnostics, and a 'knitr' language engine for inline diagrams in 'R Markdown' and 'Quarto' documents. |
| Authors: | André Leite [aut, cre, cph], The authors of the dependency Rust crates [cph] (see inst/AUTHORS for details) |
| Maintainer: | André Leite <[email protected]> |
| License: | BSD_2_clause + file LICENSE |
| Version: | 0.6.2 |
| Built: | 2026-07-15 11:27:02 UTC |
| Source: | https://github.com/cran/rpic |
{rpic} chunksRegister with rpic_register_knitr(), then write pic code in a chunk:
```{rpic, circuits=TRUE}
A:(0,0); B:(2,0)
resistor(A,B)
```
Chunk options: circuits, texlabels, scale.
rpic_knitr_engine(options)rpic_knitr_engine(options)
options |
knitr chunk options. |
The chunk output produced by knitr::engine_output() (the rendered
diagram as an included figure).
Returns {svg, animations, diagnostics, warnings} — warnings carries
structured compiler warnings for accepted-but-ignored input (unknown
attribute words, unknown animate effects), each with the same fields as
the rpic_error diagnostic. On a pic error the JSON is
{error, error_info} instead (no condition is raised — the error travels
in-band).
rpic_manifest(src, circuits = FALSE, texlabels = FALSE)rpic_manifest(src, circuits = FALSE, texlabels = FALSE)
src |
pic source code. |
circuits |
load the native circuit-element library (or write
|
texlabels |
typeset fully |
a JSON string; parse with e.g. jsonlite::fromJSON().
rpic_manifest('box; animate last box with "pop"')rpic_manifest('box; animate last box with "pop"')
Render pic source to a PDF file
rpic_pdf(src, file, circuits = FALSE, texlabels = FALSE)rpic_pdf(src, file, circuits = FALSE, texlabels = FALSE)
src |
pic source code. |
file |
output path. |
circuits |
load the native circuit-element library. |
texlabels |
typeset |
the file path, invisibly.
Render pic source to a PNG file
rpic_png(src, file, scale = 2, circuits = FALSE, texlabels = FALSE)rpic_png(src, file, scale = 2, circuits = FALSE, texlabels = FALSE)
src |
pic source code. |
file |
output path. |
scale |
raster scale (1 = 96 dpi). |
circuits |
load the native circuit-element library. |
texlabels |
typeset |
the file path, invisibly.
Register the rpic knitr engine
rpic_register_knitr()rpic_register_knitr()
No return value; called for its side effect of registering the
rpic engine with knitr::knit_engines.
Render pic source to an SVG string
rpic_svg(src, circuits = FALSE, texlabels = FALSE)rpic_svg(src, circuits = FALSE, texlabels = FALSE)
src |
pic source code. |
circuits |
load the native circuit-element library (or write
|
texlabels |
typeset fully |
an SVG string.
Compile errors are raised as a classed rpic_error condition whose
info field holds the structured diagnostic (message, line, col,
end_col, file, kind, found, expected, hint; absent values are
NA, and file names a copy include — NA means your own input).
Positions are relative to your own source, even with circuits = TRUE:
tryCatch(
rpic_svg("bxo", circuits = TRUE),
rpic_error = function(e) e$info$hint # "did you mean `box`?"
)
rpic_svg('box "hi"; arrow; circle "x"') tryCatch(rpic_svg("bxo"), rpic_error = function(e) e$info$line)rpic_svg('box "hi"; arrow; circle "x"') tryCatch(rpic_svg("bxo"), rpic_error = function(e) e$info$line)