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.
You could build your timer with \pdfelapsedtime
:
\usepackage{atbegshi}
\newcommand\showtimer{%
\message{^^Jtimer: \the\numexpr\the\pdfelapsedtime*1000/65536\relax}%
\pdfresettimer}
\AtBeginDocument{\showtimer}
\AtBeginShipout {\showtimer}
would print the time it took (in milliseconds) for each page to be output
(here p. 231 took 103ms, p. 232 took 44ms):
timer: 103 [231]
timer: 44 [232]
Note that due to the asynchronous nature of tex's output routine, this isn't completely exact: firstly, the page breaker usually only kicks in after a paragraph break, so that material that will actually end up on the next page (or even pages for very long paragraphs) has already been processed; secondly, inserts (floats, footnotes) may have been processed already earlier -- for example, split footnotes or floats that didn't fit on the previous page(s). So the numbers may actually measure the processing time both of material from previous and from later pages.
For evaluation you can extract those lines:
grep '^timer:' filename.log > Compiletime.txt
Best Answer
BaKoMa TeX does what you are looking for and is the only such solution that I know of. It does real incremental LaTeX compiling in the background, so it works with practically all LaTeX packages (e.g. those for complex diagrams). The LaTeX system itself is also quite good (e.g., it had early support for SVG).
It was originally only available for Windows, but nowadays there are also versions for Linux and Mac.
It is unfortunate that it is not free or open source, but for me paying the license fee is worth it. It is so superior to any other solution that I just can't imagine going back. As far as I know it is written by a single russian physicist, so I think the price is well justified.
Btw, I am not in any way connected to BaKoMa, just a very happy user.