Have Emacs teach you Chinese

or English or Math or whatever

automatically using org-drill and org-capture

Josh Moller-Mara
This presentation: jmm.io/emacs1


  1. Using the spaced repetition package org‑drill
    1. Don't waste time studying cards you already know
  2. Automatically creating flashcards using org‑capture templates
    1. Don't waste time making new cards

Spaced repetition?

  • If you've ever used flashcards, the idea of spaced repetition may be somewhat familiar to you.
    • If you're good at a particular flashcard, you don't need to review it as frequently.
    • If you're not so good, you may need to review a card more frequently.

(Source: Wikimedia Commons)

How it works

  • You get a flashcard
  • You think about what the answer to the flashcard is
  • You flip over the flashcard
  • Depending on how well you answered it, you categorize it from 0 to 5.
    1. Totally forgot
    2. Took a while to remember
    3. You remembered after seeing it

    4. It took a while, but you remembered
    5. You remembered after a little thought
    6. You remembered the item easily
"Hello in Chinese"

nǐ hǎo

There's a bunch of Spaced Repetition Software

One of the most popular spaced repetition software is Anki.
Fun historical fact is that it used to be an Emacs package called "flashcard.el"
But the one we'll be talking about today is org-drill

Enter org-drill

org-drill.el does flashcards and spaced-repetition, all within org‑mode
It comes with Org mode in the contrib directory!
(Or install org-plus-contrib)

My Org-drill configuration

(add-to-list 'load-path "~/elisp/org-mode/contrib/lisp/")
(use-package org-drill
             :config (progn
                       (add-to-list 'org-modules 'org-drill)
                       (setq org-drill-add-random-noise-to-intervals-p t)
                       (setq org-drill-hint-separator "||")
                       (setq org-drill-left-cloze-delimiter "<[")
                       (setq org-drill-right-cloze-delimiter "]>")
                       (setq org-drill-learn-fraction 0.25)))
Important thing here is to add it to org-modules

How to use org-drill

Add a "drill" tag in org-mode to whatever you want drilled.
Use clozes or subheadings to determine what's on the "back of the flashcard".
Use one of the following org-drill commands:
  1. org-drill - Drills the current buffer
  2. org-drill-tree - Drills the current org-mode heading
  3. org-drill-directory - Drills all files in the current directory

org-drill makes organizing your flashcards easy

You can organize things hierarchically and by file.
org-drill has support for:
Two-sided cards
User-defined style cards using Elisp
(e.g. card types for conjugation of verbs)


replaceSrc("latex", "img/latex-example-2.png") replaceSrc("latex", "img/latex-example-1.png") Running org-drill
replaceSrc("latex", "img/latex-example-3.png") Displaying the answer


Clozes are basically "fill in the blank" parts of flash cards.
They're easily added, by default using brackets like [this]
You can also have hints to be displayed.
(e.g. There are [number66|number] ferromagnetic elements)

(Note: I change the delimiters I use.
You can set org‑drill‑left‑cloze‑delimiter, org‑drill‑right‑cloze‑delimiter, org‑drill‑hint‑separator)

Cloze examples

replaceSrc("clozeimg", "img/cloze-example-1.png") Here's an example of a card with clozes, one of which has a hint
replaceSrc("clozeimg", "img/cloze-example-2.png") Here's the card as it's displayed
replaceSrc("clozeimg", "img/cloze-example-3.png") And revealing the answers

Two-sided cards

replaceSrc("twosidedimg", "img/word-example-1.png") Two-sided cards have the DRILL_CARD_TYPE set to "twosided"
replaceSrc("twosidedimg", "img/word-example-2.png") Here it displays the word, quizzing us on the definition.
replaceSrc("twosidedimg", "img/word-example-3.png") And now it reveals the definition/examples.
replaceSrc("twosidedimg", "img/word-example-4.png") Or here it displays the definition, quizzing us on the word.
replaceSrc("twosidedimg", "img/word-example-5.png") And now it reveals the word/examples.

Our goals

  1. Don't waste time studying cards you already know
  2. Don't waste time making new cards
    org-capture templates + Elisp


  • Jonathan Magen already gave a great talk on org-capture
  • Org capture templates allow for quick ways to add information
  • Modify the variable org-capture-templates


scrollBinder.bind() scrollBinder.unbind()

Anatomy of an org-capture template

'(keys description type target template)
  • You tell it the key to bind to
  • You tell where you want your captured information stored
  • You prompt for "fill-in-the-blank" strings with %^{prompt}
  • Importantly, org-capture templates can contain a %(sexp)
    org-mode wants you to hack it
scrollBinder2.bind() scrollBinder2.unbind()

My Chinese character capture template



cedict_ts.u8 is ~8MB and contains Chinese to English translations

Chinese capture template in action

capture1.currentTime = 0 capture1.play()
capture1.currentTime = 15.5 capture1.pause()

Chinese capture template in action 2

capture2.currentTime = 0 capture2.play()
capture2.currentTime = 15 capture2.pause()

Example 2: English vocabulary

Utilities for fetching definitions/examples

Here we use a modified wordnik.el to fetch word definitions and examples from wordnik.

English Wordnik capture template in action

capture3.currentTime = 0 capture3.play()
capture3.currentTime = 23.2 capture3.pause()

Wrapping up

  • org-drill provides a great way for learning/refreshing Chinese vocabulary, English vocabulary, math, etc.
  • By using org-drill we can learn more efficiently
  • org-capture provides a quick mechanism for adding new flashcards
  • By using custom lisp, we can capture new flashcards extremely quickly