TikzPictures.jl Save

Creating PGF/TikZ pictures and saving them in various formats

Project README

TikzPictures

Build Status codecov

This library allows one to create Tikz pictures and save in various formats. It integrates with IJulia, outputting SVG images to the notebook.

This library will try to use the lualatex package already installed on the system. If the library cannot run lualatex, it will fall back to trying to use tectonic for the compilation.

Lualatex may be installed through the texlive and miktex distributions. You should have dvisvgm installed. On Ubuntu, you can get the required packages, if not already present, by running sudo apt-get install pdf2svg texlive-latex-base texlive-binaries texlive-pictures texlive-latex-extra texlive-luatex.

Note: this package will attempt to turn off interpolation in the generated SVG, but this currently only works in Chrome.

Example

using TikzPictures
tp = TikzPicture("\\draw (0,0) -- (10,10);\n\\draw (10,0) -- (0,10);\n\\node at (5,5) {tikz \$\\sqrt{\\pi}\$};", options="scale=0.25", preamble="")
save(PDF("test"), tp)
save(SVG("test"), tp)
save(TEX("test"), tp)
save(TIKZ("test"), tp)

As you can see above, you have to escape backslashes and dollar signs in LaTeX. To simplify things, this package provides the LaTeXString type, which can be constructed via L"...." without escaping backslashes or dollar signs.

tp = TikzPicture(L"""
\draw (0,0) -- (10,10);
\draw (10,0) -- (0,10);
\node at (5,5) {tikz $\sqrt{\pi}$};"""
, options="scale=0.25", preamble="")

Embedding TEX files in external documents

Compiling a standalone LaTeX file requires the Tikz code to be wrapped in a tikzpicture environment, which again is wrapped in a document environment. You can omit these wrappers if you intend to embed the output in a larger document, instead of compiling it as a standalone file.

save(TEX("test"; limit_to=:all), tp) # the default, save a complete file
save(TEX("test"; limit_to=:picture), tp) # only wrap in a tikzpicture environment
save(TEX("test"; limit_to=:data), tp) # do not wrap the Tikz code, at all
Open Source Agenda is not affiliated with "TikzPictures.jl" Project. README Source: JuliaTeX/TikzPictures.jl
Stars
88
Open Issues
4
Last Commit
6 months ago
Tags

Open Source Agenda Badge

Open Source Agenda Rating