Closed judober closed 11 months ago
I think you should be able to pass use_default_preamble = false
and preamble = ["\\usepackage{foo}", ...]
to the TikzDocument
constructor.
Yes, this disables the predefined preamble but the PGFPlotsX.CUSTOM_PREAMBLE is not used as well.
I guess you could pass preamble = PGFPlotsX.CUSTOM_PREAMBLE
. But it is perhaps a bit odd that use_default_preamble = false
also removes the custom additions. @tpapp, opinions?
Sorry, I didn't read your comment clearly. I used the option include_preamble=false
for pgfsave.
I will try your suggestion.
@KristofferC: are you sure it does? My reading of the code is that when !use_default_preamble
, the only thing that happens is that the default preamble is not prepended. The preamble
field is still used.
The full preamble is built using four global sources and then the preamble
in a TikzDocument
. This is a bit baroque and I am not sure if all of it is used, but at the same time it is innocuous so I would just leave it as is.
But your second link is for the function called _default_preamble
which you describe as "building the full preamble" is exactly what is being disabled if one uses !use_default_preamble
(the first link)?
Ok, I tried the following:
Pre = "My preamble"
push!(PGFPlotsX.CUSTOM_PREAMBLE, Pre)
td = TikzDocument(; use_default_preamble = false)
push!(td, ax) #ax is the axis object
pgfsave("name.tex", td)
The result is the name.tex file which still includes
\RequirePackage{luatex85}
\documentclass[tikz]{standalone}
before \begin{document}
but without My preamble
For now:
td = TikzDocument(; use_default_preamble = false, preamble = PGFPlotsX.CUSTOM_PREAMBLE)
Yes: when !use_default_preamble
, the only preamble is that in the preamble
slot. Like in your example above.
I agree that the naming of these functions is a bit misleading. use_default_preamble
toggles not only DEFAULT_PREAMBLE
, but all four global sources (in a sense, the default preamble build process).
We could introduce a flag for toggling CUSTOM_PREAMBLE
separately, which would toggle CUSTOM_PREAMBLE_PATH
and PGFPLOTSX_PREAMBLE_PATH
too.
Ok, now I'm doing:
td = TikzDocument(; use_default_preamble = false, preamble = [Pre])
which is almost what I want except for
\RequirePackage{luatex85}
\documentclass[tikz]{standalone}
at the beginning of the document. Can I disable them as well?
It looks like you don't want to save a document, just standalone TikZ code. I wonder what your use case is, and whether you would be better served with
open("some_path.tex", "w") do io
println(io, "some preamble I need")
print_tex(io, td)
end
or something similar wrapped in a function. Also look at saving with a .tikz
extension.
Well actually you are right, this is probably the easiest solution. I somehow thought that using build in methods would be beneficial.
My usecase:
Pre
)Pre
with \usepackage{custom)
)What I did in the end:
open("document.tex", "w") do io
println(io, Pre)
println(io, "\\begin{document}")
println(io, "\\begin{tikzpicture}")
print_tex(io, ax)
println(io, "\\end{tikzpicture}")
println(io, "\\end{document}")
end
And thank you very much for the help!
\RequirePackage{luatex85} \documentclass[tikz]{standalone}
at the beginning of the document. Can I disable them as well?
Executing the following removes the \RequirePackage{luatex85}
from the output.
Base.eval(PGFPlotsX, :(_OLD_LUALATEX = true))
It seems that \RequirePackage{luatex85}
stopped being a requirement for the newer LaTeX - not sure when.
I think this one can be closed. Thanks again!
I was wondering if the option exists to include only the custom preamble and not the predefined. I would like to include my own options and not the predefined.