include_tikz | R Documentation |
Include figures from TikZ code in an exercise after
compiling it with tex2image
.
include_tikz(tikz, name = "tikzpicture", format = NULL, library = NULL, width = NULL, markup = "tex", ...)
tikz |
character vector with the TikZ code. |
name |
character. Name prefix of the graphics file to be produced. |
format |
character. The graphics format requested from
|
library |
character. Names of TikZ libraries required
for compiling the |
width |
character. The width with which the resulting graphic should be included in LaTeX. |
markup |
character. Which type of markup should be written?
Can be |
... |
arguments passed to |
The function include_tikz
takes a character vector with tikz
code, if necessary adds a {tikzpicture}
environment, renders it
into a graphics file via tex2image
, and returns
LaTeX or Markdown code that embeds the graphics into an exercise.
If format = "tex"
and markup = "tex"
the TikZ code
is included directly (possibly adding library
and {tikzpicture}
,
if necessary).
A character vector is returned. This contains just the name of the graphics
file produced (i.e., name.format
) except for format = "tex"
where the TikZ code is returned. For markup = "tex"
or "markdown"
the value is returned invisibly.
## TikZ code for a logic gate tz <- " \\node[left,draw, logic gate inputs=nn, xor gate US,fill=white,,scale=2.5] (G1) at (0,0) {}; \\draw (G1.output) --++ (0.5,0) node[right] (y) {$y$}; \\draw (G1.input 1) --++ (-0.5,0) node[left] {$a$}; \\draw (G1.input 2) --++ (-0.5,0) node[left] {$b$}; " ## switch to temporary directory wd <- getwd() td <- tempfile() dir.create(td) setwd(td) dir() ## produce PDF figure and produce includegraphics statement include_tikz(tz, name = "logicgate", format = "pdf", library = c("arrows", "shapes.gates.logic.US", "calc"), width = "2.5cm") dir() ## alternatively produce just the complete TikZ code include_tikz(tz, name = "logicgate", format = "tex", library = c("arrows", "shapes.gates.logic.US", "calc")) ## switch back to original working directory setwd(wd)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.