JuliaTeX / TikzPictures.jl

Creating PGF/TikZ pictures and saving them in various formats
Other
89 stars 28 forks source link

Optionally omit the tikzpicture and document environments. #56

Closed mirkobunse closed 4 years ago

mirkobunse commented 4 years ago

I usually export my TikzPictures two times: once as a pdf/svg, which I use for immediate inspection; and then as a TEX file.

The latter one is always meant to be embedded in a larger document, which has its own preamble. Sometimes, I also want to omit the tikzpicture environment, so that setting include_preamble=false does not suffice. Skipping the tikzpicture environment has the advantage that its options can be altered in the main document, without changing the included Tikz file.

Doing so is particularly nice when exporting Tikz code from PGFPlots.jl.

This PR provides an option to either i) save a complete TEX file that can be compiled as a standalone document; ii) omit the preamble, which is just identical to setting include_preamble=false; and iii) to print the Tikz code just as it is. The first option remains the default and the include_preamble argument is maintained for compatibility.

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"; include_preamble=false), tp) # equivalent to the above line
save(TEX("test"; limit_to=:data), tp) # do not wrap the Tikz code, at all

For those who do not use the new limit_to argument, nothing changes.

mykelk commented 4 years ago

Looks good to me. Can you add a couple tests?

mirkobunse commented 4 years ago

Sure, here you go :)