Otherwise we can get compile errors and other bugs when compiled with pdflatex. Closes #1007. Thanks to begemotv2718 for the fix.