Re: Prolog -> Tex




gipsy boy wrote:
> Hello,
>
> I'd like to convert my Prolog code to some fancy looking
> Tex/PDF/HTML/whatever (preferably Tex).
> Any idea how to do that?

A file of Prolog code is just a sequence of Prolog terms. Therefore you
could just read each term in turn, determine whether the term is a
clause or declaration (ie is principal functor :-/1) then recursively
traverse each term writing out the appropriate markup at each step.

I can't rembember any Tex off hand but in HTML, assuming you have a
style *** with the styles for the various elements, you could produce
output like:

<div class="clause">
<div class="functor">member</div>
<div class = "punctuation">(</div>
<div class = "variable">E</div>
<div class = "punctuation">,</div>
....
</div>

to format "member(X, ..."

with code such as:

format_clause(Clause) :-
write_div_begin(clause),
(
Clause = (Head :- Body)
->
format_head(Head),
write_punctuation(':-'),
format_body(Body)
;
format_head(Clause)
),
write_div_end.

write_div_begin(X) :-
write('<div class = \"'),write(X),write('\">').

write_div_end :- write('</div>').

etc

Regards, Brian.

.