On a Mac, you can of course just open up a terminal, cd
to the directory where you keep the TeX file, and issue
while true; do sleep 5; latex -halt-on-error filename.tex; done
and have the DVI file open in a viewer that watches for (and reloads on) changes. The one-liner runs latex
continuously with 5 second break between runs (the -halt-on-error
options prevents the incantation from getting stuck if you saved a file with errors). You can also swap in pdflatex
instead.
This solves half of your problem. The other half has to be dealt with by your editor of choice. You need to set it up to automatically save the file every x seconds, and how to do that depends on the editor at hand.
Now, that one-liner I gave above is quite ugly and resource wasting, since it makes no sense to re-compile if no changes are made (Edit: See this comment below for a much better way to avoid this problem). So you can do something like
while true; do sleep 2; if [ filename.tex -nt filename.log ]; then latex -halt-on-error filename.tex; fi; done
which watches for changes to the TeX file (signaled by the fact that filename.tex
is more recently modified than filename.log
) and compile when necessary (with a possible two seconds delay).
Short of a WYSIWYG, I am not quite sure how you can achieve full real-time solution. Compiling the code takes usually a short amount of time (1 or 2 seconds, or more if the file is large). So if you are looking for a solution that calls the LaTeX compiler, it probably shouldn't try to do it more often than once every 5 or 10 seconds. So you won't be able to immediately see what you typed in the DVI window. Also, if the editor autosaves the file in a spot where you are halfway typing a command, then the source won't compile.
With LaTeX I feel that the better idea is "compile-on-saves", where the human initiates the saving of the file (as compared to "automatically saving and compiling in the background). For that, modern editors can generally support hot-keys where saving and compiling is mapped to one keystroke. In vim
I map F2 to compile and F4 to call XDVI.
According to their website it can do this because it only formats one page at a time.
Long documents -- TeX Word Performance
I would like to clarify one
misinformation that 'BaKoMa TeX Word is efficient only for short
documents, because it runs TeX on background'.
In one side it is true that BaKoMa TeX Word runs TeX to display
document. This approach provides True WYSWIWYG Preview (100 %
compatibility with output of native LaTeX). However, BaKoMa TeX Word
has no degradation of performance at editing long documents. Our users
edit books of 500 and more pages and enjoy that speed is even better
then at editing one-page document !!!
The reason of this scalability
is that only one page of document is reformatted at editing document.
How it does this, I don't know. They do claim what is shown on the screen is equivalent to what will be printed on the pages. I doubt that that is entirely true. Perhaps the look (fonts, kerning etc.) of the document is exactly the same, but the exact location on the page is influenced by more than only the content of the current page.
Best Answer
The main difference is that Java is a language with a fixed grammar and a compiler separate from execution.
TeX has neither of those things, there is no fixed grammar, even the lexical analysis and tokenisation depends on the run time behaviour.
So a Java editor can use a java compiler, or (more likely) its own inbuilt implementation of the Java syntax grammar and report errors but that is not possible with TeX.
An editor can (and usually does) report simple things like mis-matched brackets but even that results in false error reports
is perfectly legal as is
For bracket matching the simple check is probably right often enough that it is worth doing but if you try to do more then you will get false reports of syntax errors more often than not so it is not helpful.
What you can do, and some systems do, is run tex in the background and update the preview whenever there is a result to be previewed.