Explicitly close read and write of Popen process (latex)

This suppresses the final unclosed buffer/file warning in the test suite on python3.4 inside the 
pgf backend.

When reading and writing from directly from stdout and stdin of the popen process they
should be explicitly closed afterwards.

These are similar to the ones fixed in #3235