trying to fix pdf generation, attempt 10

the function diff had a return followed by rtype and raises
this may be the cause of the nested too deeply error.

fixed a lot of formatting issues by this point