0
votes

I wrote a Prolog predicate that generates a Latex file, and I am looking for a way to be able to compile such a file automatically, within Prolog, to return instead the associated PDF file. I have found the shell predicate (http://www.swi-prolog.org/pldoc/man?predicate=shell/2) but I can't figure out how to properly make it work.

In case it is of any relevance, I am using SWI-Prolog 7.1.33 in a Mac.

Thanks in advance!

1
What command you use in a Bash shell (e.g. in Terminal.app) to compile and generate the PDF from the LaTeX file? What error you get if you use the same command as the first argument to the shell/2 predicate? - Paulo Moura
I use "pdflatex file.tex". When I type shell('pdflatex file.tex', E). it returns E=127 (whose meaning I don't understand), and it generates neither the pdf file nor the log file. - Daniel Girela
Error 127, assuming a Bash shell, means "command not found". Likely the pdflatex command can not be found on the PATH for the shell started by the shell/2 predicate. Try calling the pdflatex command using its full, absolute, path. - Paulo Moura
That worked perfectly, thanks! - Daniel Girela

1 Answers

-1
votes

The traditional predicate to execute shell commands is system/1 that works in Unix-like and MS-Windows systems. For instance

?- system('echo a').

writes a a in a Unix-like system.