Code
using Plots
plot(sin,
x->sin(2x),
0,
2π,
=false,
leg=(0,:lavender)) fill
Darren Irwin
May 13, 2023
These are notes on how I set up Quarto for use with Julia. I am taking these notes both to try out Quarto and to record the steps involved. I hope this will be of use for myself, students, and maybe others.
I am assuming some basic familiarity with Julia and Visual Studio Code (i.e., VS Code). If you don’t yet have VS Code installed, you can download and install it from https://code.visualstudio.com . If you don’t yet have the Julia extension for VS Code, follow the instructions here: https://code.visualstudio.com/docs/languages/julia . (Another option is to use some other text editor, but I highly recommend VS Code and assume it below.)
The following is for MacOS:
First, I got set up with Juliaup and the newest version of Julia:
First, install Juliaup using this command in the Terminal:
curl -fsSL https://install.julialang.org | sh
Pay close attention, as Juliaup might ask you to run a command to add Juliaup to your Path. Do as it says. Then open a new terminal window. You can then check whether you have installed Julia versions using:
juliaup status
If you have no Julia version yet, or do have a version but want to upgrade to the latest, get the latest release version using:
juliaup update release
At the time of writing this (updated Sept. 2023), the latest version of Julia is 1.9.3. The version installed on my machine is 1.9.3+0.x64.apple.darwin14
.
If you also want an older version as an option, you can install it using something like juliaup add 1.8.5
. (Not needed for most users, since newer versions of Julia run older code.)
This is a somewhat lengthy process, because running Quarto relies on several other software packages, including Jupyter and iJulia. But the results are worth it! 😃
I learned much of the below from: https://quarto.org/docs/computations/julia.html
Download and install Quarto from this site: https://quarto.org/docs/get-started/ . The version I have installed is Quarto CLI 1.3.450 (Mac OS)
.
Install the Quarto extension for VS Code (using the standard way of choosing extensions in VS Code).
This is a Julia package that is needed to render your Quarto files. To install, start a Julia REPL either in VS Code (using View > Command Palette > Julia: Start REPL) or in a terminal window by typing Julia. Then type these commands:
This takes a couple minutes to install, with all the dependencies.
Jupyter notebooks can be used with Julia, Python, and R (and the name is sort of a combination of those). Quarto uses Jupyter as an intermediate step in processing the code into output. To install Jupyter, we simply need to call an IJulia command (see below) and this will trigger a prompt asking you whether to install Jupyter. Say yes (unless perhaps you already have Jupyter installed).
Then the computer will ask install Jupyter via Conda, y/n?
to which you can respond “y”.
After some processing, a Jupyter browser window will open. You then need to click the “Quit” button (in the upper right) to quit Jupyter, and the Julia prompt returns in the REPL (if you are having trouble with that, you can enter ctrl-C in the Julia REPL, and you should see the julia prompt). After this initializing of Jupyter, you don’t need to open Jupyter in this way again (Quarto will simply use Jupyter directly).
This package enables Quarto to interact more efficiently with Julia when you change code. In a Julia REPL, type:
To set up Revise to launch automatically within IJulia, create a text file containing the following:
Save the above file as .julia/config/startup_ijulia.jl
(the dot at the start means this directory is hidden–the computer will probably ask you to confirm that you want to do this). If you are new to creating text files in hidden folders, try this: In a terminal window, type cd ~
to make sure you are in your home directory, then type cd .julia
, then ls
and check if a config
folder is listed. If not, type mkdir config
. Then type cd config
. Then, type nano startup_ijulia.jl
. A text editor will open, then copy and paste the above code into the editor. Then type ctrl-X and then Y and then return. The file should be saved, which you can confirm by typing ls
and seeing it listed there.
This enables smart and efficient re-execution of parts of your code (only the parts dependent on changes you’ve made). In the Julia REPL, execute:
After the above, Quarto is essentially installed and should work well for rendering in HTML or DOCX. However, I found a few more things are needed for a satisfying experience rendering in PDF.
If you don’t have it yet, you will need to first install the Homebrew package manager for macOS or Linux (see https://brew.sh). Run this in a Terminal window:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
If that worked, take a break and grab a beverage of your choice.
Now, run the following in a Terminal window:
brew install librsvg homebrew/cask/basictex
This will ask for your Administrator password, and takes some time to download and install. If you get an error saying “No developer tools installed, then follow the instructions to do so (for me, it was running the command xcode-select --install
.)
curl -sL "https://yihui.org/tinytex/install-bin-unix.sh" | sh
This font works well with monocode symbols used in Julia (without it, many of these symbols were missing from PDF output).
brew tap homebrew/cask-fonts
brew install --cask font-juliamono
(If you want to set JuliaMono as your editor font in VS Code, then do this: click on the gear symbol in the lower left, choose Settings, then choose “Editor: Font Family” and replace what is there with “JuliaMono”. You might need to restart VS Code for the change to take effect. A good way to check is to see if the zero symbol now has a little dot in the middle.)
OK we are now ready to do a little prayer to the Quarto and Julia gods and try this all out. In VS Code make a new file called QuartoDemo.qmd
. The .qmd
ending is important as it tells VS Code this is a Quarto file. Put all of this in the file:
---
title: "Demo Quarto File"
author: "Darren Irwin"
date: "5/13/2023"
execute:
echo: true
format:
html:
code-fold: true
pdf:
keep-tex: true
monofont: "JuliaMono"
jupyter: julia-1.9
---
## Demo plot produced by Julia in Quarto
Plot function pair (x(u), y(u)).
See @fig-parametric for an example.
Unicode test: ` α β `
(To get those symbols in Julia REPL, type \\alpha then tab, or \\beta then tab)
```{julia}
#| label: fig-parametric
#| fig-cap: "Parametric Plots"
using Plots
plot(sin,
x->sin(2x),
0,
2π,
leg=false,
fill=(0,:lavender))
```
Now, click Preview
in the upper right of your VS Code window. The resulting html version of your document may appear as a preview to the right, and the html file is automatically saved. Then try the Render PDF
command (in the Command Pallette, which you open with shift-command-P) for a PDF. (Check the unicode symbols carefully to see if they are there. I think they should be if the above installations were done.)
The rendered document should display the output shown below.
Plot function pair (x(u), y(u)). See Figure 1 for an example.
Unicode test: α β
(To get those in Julia REPL, type \alpha then tab, or \beta then tab)
The code for the example plot above came from the Quarto website: https://quarto.org/docs/computations/julia.html
Comment added Sept. 9: After I updated some software, the render wasn’t working, saying it couldn’t find the Jupyter kernel for Julia-1.9. I fixed this by reinstalling Jupyter, using the terminal command pip3 install jupyter
.