SLDNF Draw is a Prolog program that draws SLDNF Trees in LaTeX


Marco Gavanelli SLDNF-Draw: Visualization of Prolog operational semantics in LaTeX, Intelligenza Artificiale, vol. 11, no. 1, pp. 81-92, 2017. DOI: 10.3233/IA-170108.

Post-print available at:


This is a SWI-Prolog ( pack.

It can be installed with pack_install/1

$ swipl
?- pack_install(sldnfdraw).

Example of use

$ cd <pack>/sldnfdraw/prolog/examples
$ swipl
?- [member].
?- draw_goal("tree.tex").


Prepare an input file that first loads the module sldnfdraw

:- use_module(library(sldnfdraw)).

Then initialize the library with

:- sldnf.

You can now write the program you want to query by including it within the directives :-begin_program. and :-end_program. as in


member(X ,[X|_T]).
member(X ,[_H|T]):-


You can now write the query by including it within the directives :-begin_query. and :-end_query. as in


member(X,[1,2]), \+ member(X,[1,3]).


You can now build the SLDNF tree with the predicate draw_goal/1. If you call it with a variable as in

?- draw_goal(T).

it will return in T a string with the LaTex code for drawing the tree, that you can then include in a LaTeX document.

If you call draw_goal/1 with a string as in

?- draw_goal("tree.tex").

it will write the LaTeX code in file tree.tex in the current folder. You can then include it in a LaTeX document. The minimal LaTeX file you could use is


If you are using your example in SWISH and want the output to be shown in SVG add the following code after laoding the library

:- if(current_predicate(use_rendering/1)).
:- use_rendering(sldnf).
:- endif.

and you need the following programs on the server

In Ubuntu you would need the packages


Full Manual


Developed by Marco Gavanelli <>

Ported to SWI-Prolog by Lorenzo Campioni <>

Transformed into a module and adapted to SWISH by Fabrizio Riguzzi <>

Prolog files

pack.plShow source
prolog/examples/member.plShow source
prolog/sldnfdraw.plShow source