Working version with TeX output