Using SWI-Prolog pack gvterm

gvterm - This library translates complex Prolog terms into Graphviz (dot) output for graphical rendering.

While gvterm works for a quick and fast way see: SWISH - The term render plugin
Thanks Jan W. (ref)

This example is done using Windows 10.

Directory: C:/Users/Groot/Documents - Change as needed.

Using your favorite editor
a. Create file:

:- module(example_001,

:- use_module(library(gvterm)).

:-op(500, yfx, [bool1, bool2, bool3]).
:-op(700, xfx, [my_and]). % my_and == logic and

eq(a bool1 b my_and c bool2 d).

test :-

Using SWI-Prolog
a. Install pack gvterm

?- pack_install(gvterm).
% Contacting server at ... ok
Install gvterm@1.1 from Y/n? 
% Contacting server at ... ok
% "gvterm-1.1.tgz" was downloaded 122 times
Package:                gvterm
Title:                  Show Prolog terms using graphviz
Installed version:      1.1
Author:                 Jan Wielemaker <>
Download URL: *.tgz
Install "gvterm-1.1.tgz" (22,333 bytes) Y/n? 

b. Change to directory with

?- working_directory(_,'C:/Groot/Groot/Documents').

c. Load Prolog code

?- ['example_001'].

d. Create dot file:

?- tell('./'),test,told.
  1. Using command line

a. Ensure GraphViz installed and dot command can run
Note: For this to work the location of the dot command needs to be known. An easy way to just set the path, e.g. C:\Users\Groot>SET PATH="C:\Program Files (x86)\Graphviz2.38\bin"

C:\Users\Groot>dot -V
dot - graphviz version 2.38.0 (20140413.2041)

b. Change to directory with file

C:\Users\Groot>cd "C:\Users\Groot\Documents"

c. Convert dot file to SVG

C:\Users\Groot\Documents>dot -Tsvg -o test.svg

d. View SVG file
Note: This should start up your preferred SVG viewer, probably an Internet browser, and show the file test.svg

C:\Users\Groot\Documents>start test.svg



This is a derivative work of Operands and equation questions

xdot is a Python application included in gvterm for displaying the output; it was not used for this demonstration, see gvterm

GitHub repository: gvterm

The gvterm pack is designed to use the xdot program to directly see the result interactively. This is a Python script in the scripts directory of the pack. Seems this script does no longer work on recent Linux versions. My Ubuntu 20.04 has xdot as a standard package though, so simply do

sudo apt install xdot

And after that from Prolog

?- [library(gvterm)].
?- dotty_term(a(b,c)).

For most platforms I guess there is some interactive dot viewer. Install it and adjust to find it and you should be fine.

Finally, you can use gvterm from SWISH. See

1 Like