Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Make a course

A Canon Learning course is just a folder of text files. The lessons, the practice problems, and the slides are Markdown, and each interactive visual is one TypeScript file. A program called the engine reads that folder and turns it into a website.

The easiest way to see how it fits together is to build a tiny course from nothing, so that’s what this page does. The course has a single lesson about flipping a coin twice. You’ll get the lesson on screen first, then give it a practice problem, a visual, and a set of slides, and finish by putting it on the web.

The only thing you need installed is Node, version 24 or newer. If a terminal is new to you, read Set up your computer first. Start with an empty folder:

mkdir coin-course
cd coin-course
mkdir lessons

A course needs three files before the engine can build it. The first one tells your computer where to get the engine and gives you two commands, dev and build. You won’t need to touch it again.

package.json

{
  "private": true,
  "scripts": {
    "dev": "canon dev",
    "build": "canon build"
  },
  "dependencies": {
    "canon": "github:canonlearning/canon"
  }
}

The second file is the table of contents. It gives the course a title and lists the lessons in the order they should be read. Each lesson’s id is its file name without the .md, and the summary is the one sentence that shows up beside its title on the home page.

course.yaml

title: Coin Course
description: A course with one lesson.

lessons:
  - id: two-flips
    summary: the four outcomes of flipping a coin twice.

The third file is the lesson, and it’s ordinary Markdown. The first line is the title, a ## line starts a section, and math goes between dollar signs the way it does in LaTeX. The line starting with > at the end is a callout: the bold words become its label, and it’s how a lesson asks the reader to stop and do something on paper.

lessons/two-flips.md

# Two flips

A fair coin is flipped twice. Each flip is heads or tails, so there are
$2 \times 2 = 4$ outcomes, and each one is equally likely.

## Count the outcomes

Exactly one of the 4 outcomes has two heads, so

$$P(\text{two heads}) = \frac{1}{4}.$$

> **On paper** Write out all 4 outcomes.

That’s a complete course. Download the engine and start it:

npm install
npm run dev

Open http://localhost:4000 and the course is there, with the math typeset. Leave it running. Every time you save a file the page reloads, so you can write with the browser open next to your editor.

Add to it

Right now the lesson explains an idea and then gives the reader nothing to try it on. That’s what practice problems are for. A problem is its own file, in a folder called problems, and its worked solution lives in the same file. The block at the top holds the title and the answer. Everything above ## Solution is the question, and each ### line under it names one step of the solution.

problems/at-least-one-head.md

---
title: At least one head
answer: $3/4$
---

A fair coin is flipped twice. What is the probability of at least one head?

## Solution

### Count the outcomes with no head

Only one of the 4 outcomes, two tails, has no head.

### Subtract from the total

The other 3 outcomes have at least one head, so the probability is

$$\frac{3}{4}.$$

Write the answer exact, as 3/4 and not 0.75, because someone checking their work by hand can’t match it against a rounded number.

A problem only shows up once a lesson claims it, so add two lines to course.yaml:

course.yaml

lessons:
  - id: two-flips
    summary: the four outcomes of flipping a coin twice.
    problems:
      - at-least-one-head

Save, and the lesson now ends with the problem. The solution stays folded shut until the reader opens it. Nothing is hidden for teachers only: every solution in a Canon course is public.

So far this is a page of text and formulas, and that isn’t really the point of Canon. A lesson is supposed to be built around something the reader can watch and play with, with the text filling in only what the picture can’t say. Those are the visuals. Each one is a TypeScript file in a folder called visuals, holding a class with a build method that draws into the figure it’s handed. Here is about the smallest one that draws anything: a red ball on a floor, with a label, a readout underneath, and a caption.

visuals/one-ball.ts

import { ball, floor, palette, Stage, Visual, type Figure } from "canon";

export default class OneBall extends Visual {
  protected build(figure: Figure): void {
    const stage = new Stage(figure, { halfWidth: 4 });

    const redBall = ball(palette.red, 0.4);
    redBall.position.copy(floor(0, 0, 0.4));
    stage.scene.add(redBall);

    stage.label("a ball").position.copy(floor(0, 0, 0.9));
    figure.readout("<b>1</b> ball");
    figure.caption("One red ball on the floor.");
  }
}

Everything it uses comes from "canon": the Stage is a 3D scene, ball is one of a handful of ready-made shapes, and palette is the four colors all the visuals share. To put it in the lesson, add one line wherever you want it to appear, naming the file without the .ts:

lessons/two-flips.md

::visual{name="one-ball"}

You can drag it to turn the view, which is about all this one does. A real visual steps through a count or has a slider that changes a probability, and the quickest way to learn how is to read the ones in Probability 1 and copy from them.

The last piece is for teaching the lesson to a room. A slide deck is one more Markdown file, in a folder called lectures, written the same way as a lesson. A line of --- starts a new slide, and a callout labeled **Notes** holds what you plan to say, which the room never sees.

lectures/two-flips.md

# Two flips

> **Notes** Ask the room to guess before showing the next slide.

---

## How many outcomes?

- The first flip has 2 results
- The second flip has 2 results
- Together: 4 outcomes

---

## Which is most likely?

1. Two heads
2. Two tails
3. One of each
4. All three are equally likely

You don’t lay slides out. What you write on one decides how it looks: the bulleted list appears one point per key press, and the numbered list turns into choices A to D for the room to vote on. Like a problem, the deck gets listed under its lesson:

course.yaml

lessons:
  - id: two-flips
    summary: the four outcomes of flipping a coin twice.
    problems:
      - at-least-one-head
    lectures:
      - two-flips

The lesson page now links to its slides. The arrow keys move through them, N shows your notes, and F fills the screen.

Put it on the web

Everything so far lives on your computer. To get a real website out of it, run the other command:

npm run build

That writes the finished site into a folder called dist. It’s plain files that don’t care where they live, so you can upload the folder to any web host and it will work.

If you’d rather not upload anything by hand, GitHub will build and host the course for free. Put the course in a GitHub repository and add this one file, which tells GitHub to rebuild the site whenever you push a change.

.github/workflows/publish.yml

name: Publish

on:
  push:
    branches: [main]

permissions:
  contents: read
  pages: write
  id-token: write

jobs:
  publish:
    runs-on: ubuntu-latest
    environment:
      name: github-pages
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: 24
      - run: npm install
      - run: npm run build
      - uses: actions/upload-pages-artifact@v5
        with:
          path: dist
      - uses: actions/deploy-pages@v5

Then open the repository’s Settings, go to Pages, and set the source to “GitHub Actions”. After your next push the course is live at https://<your-name>.github.io/coin-course/, and it updates itself every time you push after that.