Index: Support/bin/latex_watch.pl
===================================================================
--- Support/bin/latex_watch.pl	(revision 8782)
+++ Support/bin/latex_watch.pl	(working copy)
@@ -1,8 +1,8 @@
 #! /usr/bin/perl
 
 # LaTeX Watch,
-	our $VERSION = "2.7";
-#	- by Robin Houston, March-August 2007.
+	our $VERSION = "2.8";
+#	- by Robin Houston, March-August 2007, January 2008.
 
 # Usage: latex_watch.pl [ options ] file.tex
 #
@@ -299,7 +299,12 @@
 		if (!defined($current_mtime)	# Error: probably input file moved or deleted
 		  || $current_mtime < $mtime)
 		{
-			$hash->{$file} = $current_mtime;
+			if (defined $current_mtime) {
+				$hash->{$file} = $current_mtime;
+			}
+			else {
+				delete $hash->{$file};
+			}
 			$callback->($file);
 		}
 	}
@@ -310,8 +315,19 @@
 		or fail ("Failed to open file",
 			"I couldn't open the file '$filepath' for reading: $!");
 
-	local $/ = "\\begin{document}";
-	my $new_preamble = <$f>;
+	my ($new_preamble, $body);
+	while (<$f>) {
+		if (/(.*)(\\begin\s*\{(?:document)\}.*)/) {
+			$new_preamble .= $1;
+			$body = $2;
+		}
+		elsif (defined $body) {
+			$body .= $_
+		}
+		else {
+			$new_preamble .= $_
+		}
+	}
 	chomp ($new_preamble)
 		or fail ("No \\begin{document} found",
 			"I couldn't find the command \\begin{document} in your file");
@@ -321,8 +337,7 @@
 		regenerate_format($new_preamble);
 	}
 
-	undef $/;
-	save_body(<$f>);
+	save_body($body);
 
 	close $f
 		or fail ("Failed to close file",
@@ -421,7 +436,7 @@
 		or fail("Failed to create file",
 			"I couldn't create the file '$wd/$dotname.tex': $!");
 
-	print $f ("\\begin{document}", $bogus_preamble, @_);
+	print $f ($bogus_preamble, @_);
 
 	close($f)
 		or fail("Failed to close file",
@@ -1010,3 +1025,8 @@
 	- Fix TeXniscope support.
 	- Deal more robustly with files that are written as well as read during processing
 	  (previously this could cause an infinite update loop)
+
+2.8:
+	- Locate '\begin{document}' in a more flexible way.
+	- If an input file disappears, remove it from the watch list (otherwise it will
+	  recompiling the document in an endless loop).
Index: Support/help.markdown
===================================================================
--- Support/help.markdown	(revision 8782)
+++ Support/help.markdown	(working copy)
@@ -40,7 +40,7 @@
 
 This allows, among other things, creating folder specific variables for scratch projects.
 
-When the `TM_LATEX_MASTER` variable is set, then all LaTeX commands use the master file pointed to by this variable as their basis. In particular, the `Typeset & View` command will typeset the master file, instead of whatever the currently active file is. So you can freely edit whatever chapter you are working on, and when you want to see the result you just press `⌘R` without having to worry about switching to the master file. The error window that may show up is arranged so that clicking any of the errors opens up the corresponding `\include`'d file where the error occurred, and places the caret at the appropriate location.
+When the `TM_LATEX_MASTER` variable is set, then all LaTeX commands use the master file pointed to by this variable as their basis. In particular, the `Typeset & View` and `Watch document` commands will typeset the master file, instead of whatever the currently active file is. So you can freely edit whatever chapter you are working on, and when you want to see the result you just press `⌘R` without having to worry about switching to the master file. The error window that may show up is arranged so that clicking any of the errors opens up the corresponding `\include`'d file where the error occurred, and places the caret at the appropriate location.
 
 There is a way to arrange it so that the individual chapters can be compiled by themselves, and still work fine when included via the `\include` command. If that is something that might interest you, then [this thread from the mailing list][included-chapters] might interest you. 
 
@@ -53,6 +53,23 @@
 
 TextMate also supports embedded directives in your TeX file by placing a line at the beginning of your document that looks like the following `%!TEX root = my_root`  This allows you to specify a master file without using the `TM_LATEX_MASTER` environment variable.  The files you specify using the `root = ` directive can be either absolute or relative.
 
+## Watching a document
+
+### Introduction
+
+When you watch a LaTeX document, it is continually monitored for changes.
+When you save a change, the document will be typeset again, and the preview updated. The preamble (i.e. everything before the `\begin{document}` command) is recompiled only when you change it; the rest of the time, only the main body of the document is recompiled. So the update cycle is substantially faster than typesetting the whole document from scratch.
+
+### Usage
+
+Press ⌃⌘W to start watching a document. If the document is already being watched, you will instead be given the option to stop watching it. You can watch several documents simultaneously.
+
+When you close the previewer, the associated watcher will automatically quit.
+
+### Troubleshooting
+
+In case of trouble, you may find some useful information in the system console. If you set the shell variable `TM_LATEX_WATCH_DEBUG=1` then additional diagnostic information is printed to the console, which may be helpful.
+
 # Previewing a LaTeX File
 
 The `Typeset & View` command has a second component, the `View` one. After a successful build, TextMate proceeds to show you the PDF file created if you have checked the `Show pdf automatically` checkbox in the preferences.  This preference is on by default.  If the preference is not checked, you can still view the file on demand by clicking the View button at the bottom of the `Typeset & View` window.  There are a number of possibilities at this point which will be explained in the following sections.
