Julia and Quarto: a match made in heaven? 🌤

JuliaCon 2022

Patrick Altmeyer

A whistle-stop tour ⏳

Quarto – A New (Old) Way to Publish Science

  • Have used R Markdown for many years for essentially anything work-related.
  • Generate multiple different output formats with ease:
    • The old school: LaTeX and PDF (including Beamer); MS Office
    • The brave new world: beautiful HTML content
      • websites
      • e-books
      • apps
  • All of this starting from the same place …

A plain Markdown document blended with your favourite programming language of your choice and a YAML header defining your output.

Julia and Quarto: a perfect match 💙💜💚

Preferred setup: VSCode, Quarto and Julia

  • Can switch between Jupyter and .qmd with ease.
  • When working with .qmd, code chunks connect to REPL.

Documenter.jl and Quarto

  • Generally play nicely with each other (both Markdown based).
format: 
  commonmark:
    variant: -raw_html
  • You get some stuff for free, e.g. citation management.
  • Unfotunately lose support for cross-referencing …

Suggestion: Quarto for JuliaCon Proceedings

  • Quarto supports LaTex templates/classes …
  • … but why only publish proceedings in PDF form?
  • Quarto opens gateway to more innovative forms of publishing!
Code
using Javis, Animations, Colors
www_path = "www"

size = 600
radius_factor = 0.33

function ground(args...)
    background("transparent")
    sethue("white")
end

function rotate_anim(idx::Number, total::Number) 
    distance_circle = 0.875
    steps = collect(range(distance_circle,1-distance_circle,length=total))
    Animation(
        [0, 1], # must go from 0 to 1
        [0, steps[idx]*2π],
        [sineio()],
    )
end

translate_anim = Animation(
    [0, 1], # must go from 0 to 1
    [O, Point(size*radius_factor, 0)],
    [sineio()],
)

translate_back_anim = Animation(
    [0, 1], # must go from 0 to 1
    [O, Point(-(size*radius_factor), 0)],
    [sineio()],
)

julia_colours = Dict(
    :blue => "#4063D8",
    :green => "#389826",
    :purple => "#9558b2",
    :red => "#CB3C33"
)
colour_order = [:red, :purple, :green, :blue]
n_colours = length(julia_colours)
function color_anim(start_colour::String, quarto_col::String="#4b95d0")
    Animation(
        [0, 1], # must go from 0 to 1
        [Lab(color(start_colour)), Lab(color(quarto_col))],
        [sineio()],
    )
end

video = Video(size, size)

frame_starts = 1:10:40
n_total = 250
n_frames = 150
Background(1:n_total, ground)

# Blob:
function element(; radius = 1)
    circle(O, radius, :fill) # The 4 is to make the circle not so small
end

# Cross:
function cross(color="black";orientation=:horizontal)
    sethue(color)
    setline(10)
    if orientation==:horizontal
        out = line(Point(-size,0),Point(size,0), :stroke)
    else
        out = line(Point(0,-size),Point(0,size), :stroke)
    end
    return out
end

for (i, frame_start) in enumerate(1:10:40)

    # Julia circles:
    blob = Object(frame_start:n_total, (args...;radius=1) -> element(;radius=radius))
    act!(blob, Action(1:Int(round(n_frames*0.25)), change(:radius, 1 => 75))) # scale up
    act!(blob, Action(n_frames:(n_frames+50), change(:radius, 75 => 250))) # scale up further
    act!(blob, Action(1:30, translate_anim, translate()))
    act!(blob, Action(31:120, rotate_anim(i, n_colours), rotate_around(Point(-(size*radius_factor), 0))))
    act!(blob, Action(121:150, translate_back_anim, translate()))
    act!(blob, Action(1:150, color_anim(julia_colours[colour_order[i]]), sethue()))

    # Quarto cross:
    cross_h = Object((n_frames+50):n_total, (args...) -> cross(;orientation=:horizontal))
    cross_v = Object((n_frames+50):n_total, (args...) -> cross(;orientation=:vertical))
end

render(
    video;
    pathname = joinpath(www_path, "intro.gif"),
)
Figure 1: Julia and Quarto: a perfect match. Image by author (heavily borrowing from Javis.jl tutorial)

More Resources 📚

Read on …

  • Related blog post (hosted on a blog that itself is built with Quarto and involves lots of Julia content).
  • Examples of Julia package documentation I’ve built with Quarto + Documenter.jl:
    1. CounterfactualExplanations.jl
    2. LaplaceRedux.jl
  • Quarto’s own guide to using Quarto with Julia.