check for Document class being present.

Fix from Dan Stowell I think, received via quarks svn