# Automatically start the necessary pdflatex runs if .tex has changed (MacOS X)?

I read about Latex Daemon, which seems to automatically start a new latex run, when the source document (.tex) has changed.

Can somebody recommend me a similar solution for MacOS X (as Latex daemon seems to be for Windows only)?

snip:
I've removed the 2nd part of my question about speeding things up and created a new question: How to speed up pdflatex for a very large document on MacOS X?

I use TexMakerX as editor and Skimas viewer. Skim can autoupdate the PDF file, as soon as it has changed, so that should be no problem. My current LaTeX project has several source files, combined with \include, so the solution should be able to "observe" the changes of at least one of those files.

edit:

I'll accept latexmk as the answer for automatically running pdflatex several times to update bibliography and references
and I'll ask the question of speeding up processing in a new question.

For those who want to set up latexmkon MacOS X, this page from Damien Pollet could be helpful.

• with the -pvc-option it seems to slow down my MacBook, as switching to another application got quite slow, especially when its windows were located in another Space
• so I turned that off and just now use latexmk via short key F1 to automatically compile "everything", while I use a single pdflatex-run with F2 to add small changes in the text.

While searching with google I also found the atchange program http://www.ccrnp.ncifcrf.gov/~toms/atchange.html which seems to do similar things, I did not test it yet.

-
MacOS X has Automator and Folder Actions which can be used to execute shell scripts when files have changes. However, I haven't tried this for pdflatex and can only suggest to look into this. – Christian Lindig Apr 8 '11 at 19:20
@Christian Lindig: interesting idea! – MostlyHarmless Apr 8 '11 at 19:54

latexmk can run in automatic-update mode using the -pvc option:

# latexmk -pdf -pvc file.tex

It is a Perl script, so it should run under any OS as long a Perl compiler is installed. I'm not sure, but I think TeXLive ships with one, at least under Windows I think.

-
@Martin Scharrer: Thank you, that answers part 1 of my question. latexmk was part of my TeXLive installation, I've already tried it and it works very well so far! Here are some useful tips for configuration on MacOS which helped me setting it up very quickly (also automatically using synctex): people.untyped.org/damien.pollet/notes/2010/… - so now there is only the speed issue left :-( – MostlyHarmless Apr 8 '11 at 19:52
@Martin Scharrer: the automatic-update mode with -pvc seemed very promising, but since then I had problem with the responsiveness when changing spaces (virtual desktops in OS X) - it took extremely long to change to another space or application. As soon as I quit latexmk this was gone, so I fear this might be a side effect :-( Nevertheless I can use latexmk as my primary command for typesetting not to have launch pdflatex several times. – MostlyHarmless Apr 9 '11 at 8:57

Claus Gerhardt's FlashMode does this, but for TeXShop.

-
Thanks, Alan. That looks very promising too, but unfortunately I don't want to switch back to TeXShop for some good reasons. :-( – MostlyHarmless Apr 9 '11 at 6:44

During searching in the internet, I also found atchange which seems to also be able to automatically detect changes in any specified text document and then run predefined shell scripts.

Taken from the homepage 1:

When the atchange program is running, it watches one or more files. When any of those files changes, the atchange program will wake up and do any actions you want. Tasks such as modifying and compiling a program, modifying a data file and using it, or editing a text and typesetting it can be automated with a single typed command such as: atchange myprogram "compile myprogram" By setting up atchange once before starting a repetitive task, one can avoid hundreds of mouse movements.

(I did not test it yet)

-
Thanks, I was actually looking for some general tool like this. – Martin Scharrer Apr 12 '11 at 10:51
@Martin Scharrer: freut mich, wenn ich auch mal helfen konnte. :-) – MostlyHarmless Apr 12 '11 at 12:09