#!/usr/bin/perl
#
# the LATEX assistant, mark 1, 27 april 1998
# Copyright (C) 1998 by B.W. van Schooten
#
# Obvious limitations:
#     * You have to write your own Makefile
#     * it assumes the generated DVI file(s) are in the current directory.
#     * Only LaTeX errors are recognised. Other errors are ignored.
#     * no support of optional multipass compiles. For now, just keep saving
#       your document without changes until LaTeX stops complaining.


print "LATEX ASSISTANT READY.\n";

while (1) {

	if (system("make -q")) {
		# targets are not up to date -> make them
		open (MAKEOUT, "make|");

		# parse all output from make and the commands make executes.
		$latexerr=0;
		while ($str=<MAKEOUT>) {
			if ($str =~ /! /) {
				print"\n###LATEX ERROR###\n";
				$latexerr=1;
			}
			print $str;
		}
		close(MAKEOUT);
		if ($latexerr) {
			print"###END OF ERROR###\n"
		} else {
			print "DVI UPDATED\n";
		}

		# Make sure documents are not recompiled every time
		# in case there were errors last time and the dvi file was not updated.
		system("touch *.dvi");

	}

	sleep (5);
}




