-
Notifications
You must be signed in to change notification settings - Fork 7
/
juliaplots.sty
89 lines (75 loc) · 2.27 KB
/
juliaplots.sty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{juliaplots}
\RequirePackage[usefamily={jl,julia,juliacon}]{pythontex}
\RequirePackage{pgfplots}
\RequirePackage{graphicx}
\RequirePackage{newfile}
\pgfplotsset{compat=newest}
\newoutputstream{juliaplot}
\begin{jlcode}
cur_plot = nothing
function plot_plots_pgfplots(args...; kwags...)
global cur_plot
cur_plot = Plots.plot(args...; kwags...)
end
function plot_pgfplots(args...; kwags...)
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...)
end
\end{jlcode}
\DeclareOption{plots_pgfplots}{
\DeclareRobustCommand{\plot}[1]{
\IfFileExists{#1.tex}{}{
\immediate\openoutputfile{#1.tex}{juliaplot}
\immediate\closeoutputstream{juliaplot}
}
\jlc{savefig(cur_plot, "#1.tex")}\input{#1}}
\jlc{using Plots;pgfplots()}
\jlc{plot(args...; kwags...) = plot_plots_pgfplots(args...; kwags...)}
}
\DeclareOption{pgfplots}{
\DeclareRobustCommand{\plot}[1]{
\IfFileExists{#1.tex}{}{
\immediate\openoutputfile{#1.tex}{juliaplot}
\immediate\closeoutputstream{juliaplot}
}
\jlc{save("#1.tex", cur_plot, include_preamble=false)}\input{#1}}
\jlc{using PGFPlots}
\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}}{
}
\jlc{using PyPlot; savefig("#1.pdf")}}
\jlc{using PyPlot}
}
\DeclareOption{gadfly}{
\newcommand{\plot}[4]{\jlc{draw(PDF("#1.pdf", #2, #3), cur_plot)}\includegraphics[#4]{#1.pdf}}
\jlc{using Gadfly}
\jlc{plot(args...; kwags...) = plot_gadfly(args...; kwags...)}
}
\ProcessOptions\relax