PGFPlotsX.jl icon indicating copy to clipboard operation
PGFPlotsX.jl copied to clipboard

Use only custom Preamble

Open judober opened this issue 6 years ago • 13 comments

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.

judober avatar Oct 08 '19 10:10 judober

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

KristofferC avatar Oct 08 '19 10:10 KristofferC

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

judober avatar Oct 08 '19 10:10 judober

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?

KristofferC avatar Oct 08 '19 10:10 KristofferC

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

judober avatar Oct 08 '19 10:10 judober

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

tpapp avatar Oct 08 '19 11:10 tpapp

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

KristofferC avatar Oct 08 '19 11:10 KristofferC

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

judober avatar Oct 08 '19 11:10 judober

For now:

td = TikzDocument(; use_default_preamble = false, preamble = PGFPlotsX.CUSTOM_PREAMBLE)

KristofferC avatar Oct 08 '19 11:10 KristofferC

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.

tpapp avatar Oct 08 '19 11:10 tpapp

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?

judober avatar Oct 08 '19 11:10 judober

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.

tpapp avatar Oct 08 '19 11:10 tpapp

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

My usecase:

  • I want to specify magical comments in texstudio at the beginning of the file (included in Pre)
  • I also want to use standalone and my custom.sty file so that I can change the settings for my figures globally (also in 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!

judober avatar Oct 08 '19 11:10 judober

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

CiaranOMara avatar Sep 18 '22 00:09 CiaranOMara

I think this one can be closed. Thanks again!

judober avatar Oct 12 '23 19:10 judober