An open source scientific article created using the showyourwork workflow.
Fork this repo to easily use Julia in showyourwork
. The following modifications were made to the default template
(You can also see this from the Git diff)
- Defined
src/scripts/paths.jl
, replacingsrc/scripts/paths.py
(just a convenience file which defines paths when youinclude()
it). - Created a
Project.toml
to define Julia dependencies. - Created two example scripts in
src/scripts/
:-
data.jl
, to create a dataset and save it tomydata.csv
, and -
plot.jl
, to plot the dataset and save it tomyplot.png
.
-
- Created three Snakemake rules:
-
julia_manifest
createsManifest.toml
from theProject.toml
. -
data
callsdata.jl
, and depends onManifest.toml
. -
plot
callsplot.jl
, and depends onmydata.csv
andManifest.toml
.
-
- Configured
showyourwork.yml
to map.jl
tojulia
.
The Snakefile
also defines the JULIA_PROJECT
as "."
.
These three Julia jobs are dependencies of the final rule, which compiles the LaTeX document using tectonic
.
The generated PDF and arXiv tarball will contain myplot.png
.
For example, the rule plot
:
rule plot:
input:
"Manifest.toml",
data="src/data/mydata.csv",
output: "src/tex/figures/myplot.png"
script: "src/scripts/plot.jl"
This Julia script is then able to reference the variable snakemake
:
using Gadfly
using Cairo
using CSV
using DataFrames
input_fname = snakemake.input["data"]
output_fname = snakemake.output[1]
data = open(input_fname, "r") do io
CSV.read(io, DataFrame)
end
# Plot x vs y:
p = plot(data, x=:x, y=:y, Geom.line)
# Save:
draw(PNG(output_fname, 10cm, 7.5cm), p)
In ms.tex
, we can define the corresponding figure as:
\begin{figure}[h!]
\centering
\includegraphics[width=0.5\textwidth]{figures/myplot.png}
\caption{A figure.}
\label{fig:fig1}
\script{../scripts/plot.jl}
\end{figure}
Which will add a hyperlink to the script used to generate the figure: