diff --git a/README.md b/README.md index 3828edf..9bdcdd2 100644 --- a/README.md +++ b/README.md @@ -7,13 +7,15 @@ To install this package, just download [juliaplots.sty](https://github.com/sisl/ The package currently supports the following Julia plotting packages: 1. [PGFPlots.jl](https://github.com/sisl/PGFPlots.jl) -2. [PyPlot.jl](https://github.com/stevengj/PyPlot.jl) -3. [Gadfly.jl](https://github.com/dcjones/Gadfly.jl) +2. [PGFPlotsX.jl](https://github.com/KristofferC/PGFPlotsX.jl) +3. [PyPlot.jl](https://github.com/stevengj/PyPlot.jl) +4. [Gadfly.jl](https://github.com/dcjones/Gadfly.jl) Before using any of these packages, they must be installed and usable from Julia. In the case of Gadfly, you must also have [Cairo.jl](https://github.com/JuliaGraphics/Cairo.jl) installed. Only one plotting package is permitted. You specify the package you want as a package option to `juliaplots`. For example: * `\usepackage[pgfplots]{juliaplots}` +* `\usepackage[pgfplotsx]{juliaplots}` * `\usepackage[pyplot]{juliaplots}` * `\usepackage[gadfly]{juliaplots}` @@ -26,6 +28,20 @@ As with pythontex, you can run code using `jlcode`: \end{jlcode} ``` +For `PGFPlotsX`, the equivalent code block is: +```latex +\begin{jlcode} + x = [1,2,3] + y = [2,4,1] + + p = @pgf TikzPicture( + Axis( + PlotInc({ no_marks }, + Table(; x = x, y = y)))) + plot(p) +\end{jlcode} +``` + You can run and typeset code using `jlblock` ```latex \begin{jlblock} @@ -38,7 +54,7 @@ You can run and typeset code using `jlblock` You can run a command with, for example, `\jlc{x=2}`. You can typeset code without running it with `\jlv{x=2}`. You can run a command and typeset it using `\jlb{x=2}`. The functionality that is added by juliaplots.jl is the `\plot` command, which will generate the plot and inject it into the document. The number of arguments depends on which plotting package you are using. Here are examples: -* PGFPlots: `\plot{myfile}`, where the sole argument is the name of the file (do not include the file extension) that will be used in the background for including the plot. +* PGFPlots and PGFPlotsX: `\plot{myfile}`, where the sole argument is the name of the file (do not include the file extension) that will be used in the background for including the plot. * PyPlot: `\plot{myfile}{width=3in}`, where the first argument is the name of the PDF file (without file extension) to store the image, and the second argument are the options to be passed to `\includegraphics` when the PDF is included. * Gadfly: `\plot{myfile}{3inch}{3inch}{width=3in}`, where the first argument is the name of the PDF file (without file extension) to store the image, the second is the width of the image to be exported by Gadfly, the third is the height of the image to be exported by Gadfly, and the fourth argument contains the options to be passed to `\includegraphics` when the PDF is included. diff --git a/juliaplots.sty b/juliaplots.sty index 434a9a8..66dcd64 100644 --- a/juliaplots.sty +++ b/juliaplots.sty @@ -20,6 +20,17 @@ global cur_plot cur_plot = PGFPlots.plot(args...; kwags...) end + + function plot_pgfplotsx(object, args...; kwags...) + println("test") + global cur_plot + cur_plot = object + if length(args) + length(kwags) > 0 + @warn "All additional arguments to plot() ignored! Please pass a TikZDocument or TikZFigure directly." + end + return cur_plot + end + function plot_gadfly(args...; kwags...) global cur_plot cur_plot = Gadfly.plot(args...; kwags...) @@ -49,6 +60,18 @@ \jlc{plot(args...; kwags...) = plot_pgfplots(args...; kwags...)} } +\DeclareOption{pgfplotsx}{ +\DeclareRobustCommand{\plot}[1]{ + \IfFileExists{#1.tex}{}{ + \immediate\openoutputfile{#1.tex}{juliaplot} + \immediate\closeoutputstream{juliaplot} + } + \jlc{pgfsave("#1.tex", cur_plot; include_preamble=false)}\input{#1}} +\jlc{using PGFPlotsX} +\jlc{plot(args...; kwags...) = plot_pgfplotsx(args...; kwags...)} +} + + \DeclareOption{pyplot}{ \DeclareRobustCommand{\plot}[2]{ \IfFileExists{#1.pdf}{\includegraphics[#2]{#1}}{ diff --git a/pgfplotsx_example.pdf b/pgfplotsx_example.pdf new file mode 100644 index 0000000..8c515bb Binary files /dev/null and b/pgfplotsx_example.pdf differ diff --git a/pgfplotsx_example.tex b/pgfplotsx_example.tex new file mode 100644 index 0000000..96433cf --- /dev/null +++ b/pgfplotsx_example.tex @@ -0,0 +1,19 @@ +\documentclass{article} +\usepackage[pgfplotsx]{juliaplots} + +\begin{document} + +\begin{jlblock} + x = [1,2,3] + y = [2,4,1] + + p = @pgf TikzPicture( + Axis( + PlotInc({ no_marks }, + Table(; x = x, y = y)))) + plot(p) +\end{jlblock} + +\plot{myfile} + +\end{document}