# PGFPlotsX.jl to LaTeX

**URL:** <https://discourse.julialang.org/t/pgfplotsx-jl-to-latex/49449>\
**Category:** General Usage\
**Tags:** pgfplotsx\
**Created:** [November 2, 2020, 9:37am UTC](https://discourse.julialang.org/t/pgfplotsx-jl-to-latex/49449 "2020-11-02T09:37:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![IljaK91](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iljak91/32/44301_2.png) [@IljaK91](https://discourse.julialang.org/u/IljaK91)\
**Post date:** [November 2, 2020, 9:37am UTC](https://discourse.julialang.org/t/pgfplotsx-jl-to-latex/49449/1 "2020-11-02T09:37:55Z")

</div>

Hi everyone,

I am want to try using `PGFPlotsX.jl` via `Plots.jl` to export .tex files that are to be included in my `LyX` document. But if I try to use `\input{myplot.tex}` in my file, I get the following error messages:

![image](https://global.discourse-cdn.com/julialang/original/3X/8/1/81ffe18e3badff6cff88adcfe1929c03631d0b8a.png)

I have `\usepackage{tikz} \usepackage{pgfplots}` at the top of my LaTeX file. Is there something else I need to do? The beginning of `myplot.tex` is

```julia
\begin{tikzpicture}[/tikz/background rectangle/.style={fill={rgb,1:red,1.0;green,1.0;blue,1.0}, draw opacity={1.0}}, show background rectangle]

```

---

<div class="post-metadata">

**Author:** ![karlroyen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/karlroyen/32/9301_2.png) [@karlroyen](https://discourse.julialang.org/u/karlroyen)\
**Post date:** [November 2, 2020, 9:49am UTC](https://discourse.julialang.org/t/pgfplotsx-jl-to-latex/49449/2 "2020-11-02T09:49:32Z")

</div>

You can see the header necessary in the Variable `PGFPlotsX.DEFAULT_PREAMBLE`:

```julia
julia> PGFPlotsX.DEFAULT_PREAMBLE
7-element Array{String,1}:
 "\\usepackage{pgfplots}"
 "\\pgfplotsset{compat=newest}"
 "\\usepgfplotslibrary{groupplots}"
 "\\usepgfplotslibrary{polar}"
 "\\usepgfplotslibrary{smithchart}"
 "\\usepgfplotslibrary{statistics}"
 "\\usepgfplotslibrary{dateplot}"

```

---

<div class="post-metadata">

**Author:** ![IljaK91](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iljak91/32/44301_2.png) [@IljaK91](https://discourse.julialang.org/u/IljaK91)\
**Post date:** [November 2, 2020, 9:57am UTC](https://discourse.julialang.org/t/pgfplotsx-jl-to-latex/49449/3 "2020-11-02T09:57:53Z")

</div>

So I tried the following:

```julia
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{groupplots}
\usepgfplotslibrary{polar}
\usepgfplotslibrary{smithchart}
\usepgfplotslibrary{statistics}
\usepgfplotslibrary{dateplot}

\begin{document}
\input{myplot.tikz}
\end{document}

```

And it gives me the same error.

Ok, I have got it now. You need to import also

```julia
\usetikzlibrary{backgrounds}
\usepgfplotslibrary{fillbetween}

```

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [November 2, 2020, 10:06am UTC](https://discourse.julialang.org/t/pgfplotsx-jl-to-latex/49449/4 "2020-11-02T10:06:56Z")

</div>

[Tikz \path problem, command not found - TeX - LaTeX Stack Exchange](https://tex.stackexchange.com/a/6903) says `\usetikzlibrary{intersections}`

---

<div class="post-metadata">

**Author:** ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)\
**Post date:** [November 2, 2020, 11:31am UTC](https://discourse.julialang.org/t/pgfplotsx-jl-to-latex/49449/5 "2020-11-02T11:31:19Z")

</div>

You can query the preamble used by the Plots backend with `Plots.pgfx_preamble()`.  
[This](https://docs.juliaplots.org/latest/backends/#LaTeX-workflow) is the relevant section of the documentation for this.
