refactoring of preview function in sympy/printing/preview.py

Note that this PR makes the preview function not threadsafe (generated texname is same). To make it threadsafe again do you mind if I use the ```tempfile.mkdtemp()``` function instead of ```tempfile.gettempdir()``` and use the code from this SO answer http://stackoverflow.com/a/6886556/537149

edit: 
fixed thread safety problem