Learning Tracery: Part 1: Example and Definitions

Learning Tracery

Tracery is a “story-grammar generation library” written in JavaScript. It was created by Kate Compton and has risen in popularity for its easy-to-follow functions for taking a set of options and creating a grammar that can produce different texts.


Screenshot 2018-10-04 21.54.13

Play with the example on Repl.It!


While Tracery may seem complicated at first, it works on two things: symbols and rules.


Think of symbols as possible outcomes. These can be words, numbers, or phrases. They are simply possible output.


Rules are just that: rules. The rules define how the symbols relate to each other.

Symbols + Rules = Grammar

In Tracery, symbols are given to it through the createGrammar() function. They define what the symbols are and possible values for those symbols to create a grammar.

Screenshot 2018-10-04 22.27.51

Then, with the rules and symbols, the grammar is flattened into one possible outcome through filtering the symbols, their possibilities, and the rules.