fix for pdf generation

functions that documented possible raised exceptions caused
latex too deeply nested errors.
fixed a lot of formatting issues.