KristofferC / PGFPlotsX.jl

Plots in Julia using the PGFPlots LaTeX package
Other
301 stars 40 forks source link

Use only custom Preamble #179

Closed judober closed 11 months ago

judober commented 4 years ago

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.

KristofferC commented 4 years ago

I think you should be able to pass use_default_preamble = false and preamble = ["\\usepackage{foo}", ...] to the TikzDocument constructor.

judober commented 4 years ago

Yes, this disables the predefined preamble but the PGFPlotsX.CUSTOM_PREAMBLE is not used as well.

KristofferC commented 4 years ago

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?

judober commented 4 years ago

Sorry, I didn't read your comment clearly. I used the option include_preamble=false for pgfsave. I will try your suggestion.

tpapp commented 4 years ago

@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.

KristofferC commented 4 years ago

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)?

judober commented 4 years ago

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

KristofferC commented 4 years ago

For now:

td = TikzDocument(; use_default_preamble = false, preamble = PGFPlotsX.CUSTOM_PREAMBLE)
tpapp commented 4 years ago

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.

judober commented 4 years ago

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?

tpapp commented 4 years ago

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.

judober commented 4 years ago

Well actually you are right, this is probably the easiest solution. I somehow thought that using build in methods would be beneficial.

My usecase:

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!

CiaranOMara commented 1 year ago
\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.

judober commented 11 months ago

I think this one can be closed. Thanks again!