RSyntaxTree is a graphical syntax tree generator for linguistic research.
Web App · Example Gallery · Documentation
Features
RSyntaxTree provides a rich set of features for creating publication-quality syntax trees:
Basic Syntax
Use bracket notation to define tree structures:
[S [NP the cat] [VP [V sleeps]]]
Text Decoration
Apply various text styles to node labels:
- Bold:
**text** - Italic:
*text* - Subscript:
_text_ - Superscript:
__text__ - Overline/Underline/Strikethrough:
=text=,-text-,~text~
Per-Node Coloring
Apply custom colors to individual nodes using @color: syntax:
[S [@red:NP the cat] [@blue:VP sleeps]]
Supports named colors (red, blue, green, etc.) and hex colors (@#FF5733:).
Enclosures and Triangles
- Brackets:
[#NP text]→ draws brackets around the node - Rectangle:
[##NP text]→ draws a rectangle around the node - Triangle:
[^NP the quick fox]→ draws a triangle connector
Combine with colors: [#@red:NP text], [^@blue:VP phrase]
Region Shade
Shade the whole subtree a node governs with a semi-transparent plane — useful for c-command/binding domains and cognitive grammar dominions. Prefix the node with %; the color reuses the @color: syntax (bare % is gray):
[TP [DP everyone] [%@lightblue:T' [T will] [VP praise it]]]
Path Drawing
Connect nodes with lines or arrows:
[S [NP+1 text] [VP [V+>1 connects]]]
Multiple Output Formats
Generate trees in PNG, SVG, PDF, or LSIF (JSON) format. (JPG and GIF are deprecated and will be removed in 2.0.)
Web Interface
A working web interface is available at https://yohasebe.com/rsyntaxtree.
You can also run RSyntaxTree's web interface on your local machine using Docker Desktop. See RSyntaxTree Web UI.
Examples
See RSyntaxTree Example Gallery for examples covering:
- Generative Grammar
- Combinatory Categorial Grammar
- Head-Driven Phrase Structure Grammar
- Cognitive Grammar
- Construction Grammar
- Pragmatics
- Phonology
- and more
Input text
[S
[NP |R|<>SyntaxTree]
[VP
[V generates]
[NP
[Adj #\+multilingual\
\+beautiful]
[NP syntax\
trees]
]
]
]
Output (PNG or SVG)
System Fonts
RSyntaxTree resolves fonts by family name through fontconfig (measurement via Pango, rendering via librsvg), so the fonts must be installed on the machine that generates the images. As of v1.8.0 the gem no longer bundles font files; they were not used at runtime.
- Debian/Ubuntu:
apt install fonts-noto-core fonts-noto-cjk - Alpine:
apk add font-noto font-noto-cjk font-noto-cjk-extra(the-extrapackage carries Noto Serif CJK) - macOS:
brew install --cask font-noto-sans font-noto-serif font-noto-sans-mono font-noto-sans-jp font-noto-serif-jp font-noto-sans-cjk font-noto-serif-cjk font-noto-sans-mono-cjk-jp(macOS itself ships Noto only for a few rare scripts)
Arabic, Hebrew, Devanagari, Thai and Khmer need their own packages, and emoji need the monochrome Noto Emoji — colour emoji fonts are not drawn by this pipeline:
- Debian/Ubuntu:
fonts-noto-corecovers the scripts; on minimal images addfonts-notofor the full set - Alpine:
apk add font-noto-arabic font-noto-naskh-arabic font-noto-hebrew font-noto-devanagari font-noto-thai font-noto-khmer - macOS: the same families are available as
font-noto-*casks
See Fonts in the documentation for which family is used for what, how to substitute your own, and the macOS caveats.
Installation
gem install rsyntaxtree
macOS Installation Notice
Important for macOS users: If you encounter build errors for native extensions (gobject-introspection, cairo-gobject, gio2), run the following commands before installing RSyntaxTree:
gem install gobject-introspection -- --with-ldflags="-Wl,-undefined,dynamic_lookup"
gem install cairo-gobject -- --with-ldflags="-Wl,-undefined,dynamic_lookup"
gem install gio2 -- --with-ldflags="-Wl,-undefined,dynamic_lookup"
Then install RSyntaxTree:
gem install rsyntaxtree
Alternatively, use the Docker image or the web interface.
Usage
Command Line
Usage:
1) rsyntaxtree [options] "[S [NP text] [VP here]]"
2) rsyntaxtree [options] "(S (NP text) (VP here))" # Penn Treebank format
3) rsyntaxtree [options] "/path/to/text/file"
4) echo "[S [NP text] [VP here]]" | rsyntaxtree [options]
Options
| Option | Description | Default |
|---|---|---|
-o, --outdir |
Output directory | ./ |
-f, --format |
Output format: png, svg, pdf, lsif, tikz (jpg and gif are deprecated) | png |
-l, --leafstyle |
Leaf style: auto, triangle, bar, nothing | auto |
-n, --fontstyle |
Font style: sans, serif, cjk, mono | sans |
-s, --fontsize |
Font size: 6-26 | 16 |
-i, --linewidth |
Line width relative to the font size: 0.5-3.0 (1 = 5% of the font size) |
1.0 |
-c, --color |
Color mode: modern, traditional, gray (black text, grey lines), off | modern |
-p, --polyline |
Polyline connectors: on, off | off |
-d, --direction |
Tree layout direction: ttb, ltr | ttb |
--tidy |
Layout scale: off, symmetric, low, medium, high | off |
--hspacing |
Horizontal spacing factor, all layout modes (0.5-3.0) | 1.0 |
--hyphen |
How a hyphen reads: markup (-underline-) or literal |
markup |
-m, --mirror |
Flip the tree horizontally (RTL convention): on, off | off |
--validate |
Check the input without drawing: a JSON diagnosis on stdout, the verdict in the exit code | |
--notation |
Print a short reference for the notation |
Run rsyntaxtree -h for the full list of options.
Input Formats
- Bracket notation:
[S [NP text] [VP here]] - Penn Treebank format:
(S (NP text) (VP here))- automatically converted - Standard input:
echo "[S [NP text]]" | rsyntaxtree
Configuration File
RSyntaxTree supports configuration files (.rsyntaxtreerc) in YAML format. Place the file in your home directory or current working directory.
# ~/.rsyntaxtreerc
format: svg
color: modern
fontsize: 18
CLI options override config file settings.
Using RSyntaxTree with an AI Model
The notation is small, but several characters in it already mean something, so a model writing it does better with the reference in front of it than without.
If the model only writes the notation and you draw it yourself — in the web interface or on your own machine — nothing needs installing. Give the model one of these to read:
- The brief reference, about a page, leading with the characters that already mean something.
- Everything in one file: the reference, the manual and all the gallery examples, 78 KB.
If the model can run a shell, it can draw and then look at what it drew, which is the part that lets it correct itself:
docker run --rm -v "$PWD:/work" -w /work ghcr.io/yohasebe/rsyntaxtree \
rsyntaxtree --notation # the reference, on stdout
docker run --rm -v "$PWD:/work" -w /work ghcr.io/yohasebe/rsyntaxtree \
rsyntaxtree -f png -o . "[S [NP a tree] [VP appears]]"
Then read syntree.png back. --examples prints every gallery example with
the settings it was drawn at, and --validate reports what is wrong with an
input as JSON — including whether rewriting it is worth trying — without
drawing anything:
{ "schema": "rsyntaxtree.error/1", "ok": false,
"errors": [ { "code": "unbalanced_brackets",
"message": "Error: open and close brackets do not match",
"hint": "Count the brackets: every '[' needs one ']'.",
"retryable": true } ],
"reference": "rsyntaxtree --notation, or https://yohasebe.github.io/rsyntaxtree/llms-full.txt" }
The exit code carries the verdict too, so a script can branch on it without reading the JSON. The Docker image is used above because this tool draws through Pango and librsvg, and a figure depends on which versions of those — and which fonts — are installed; the image fixes all of them. Installed as a gem it works the same, once those libraries are on the machine.
Documentation
For detailed documentation on syntax and markup:
How to Cite
If you use RSyntaxTree in your research, please cite it. You can use the "Cite this repository" button on GitHub (powered by CITATION.cff), or the following BibTeX entry (adjust version to the one you used):
@software{hasebe_rsyntaxtree,
author = {Hasebe, Yoichiro},
title = {RSyntaxTree: A graphical syntax tree image generator},
url = {https://yohasebe.com/rsyntaxtree},
doi = {10.5281/zenodo.21916150},
version = {1.8.0},
year = {2026}
}
Related Blog Posts
Author
Yoichiro Hasebe (yohasebe@gmail.com)
License
RSyntaxTree is distributed under the MIT License.