Fix for latex svg generation
Improved refopen behaviour