Converting rendering system to use the separate tex2pix library (which itself is based on the slhaplot rendering experience). Test for presence of the mathpazo package before including it in the default preamble. Version 1.3.0 pyslha-1.3.0

Sat, 03 Mar 2012 00:28:48 +0100

author
Andy Buckley <andy@insectnation.org>
date
Sat, 03 Mar 2012 00:28:48 +0100
changeset 162
e5b76d1917c0
parent 161
9306d1ad087f
child 163
e154d26765ab

Converting rendering system to use the separate tex2pix library (which itself is based on the slhaplot rendering experience). Test for presence of the mathpazo package before including it in the default preamble. Version 1.3.0

ChangeLog file | annotate | diff | comparison | revisions
pyslha.py file | annotate | diff | comparison | revisions
setup.py file | annotate | diff | comparison | revisions
slhaplot file | annotate | diff | comparison | revisions
     1.1 --- a/ChangeLog	Thu Oct 13 17:10:35 2011 +0200
     1.2 +++ b/ChangeLog	Sat Mar 03 00:28:48 2012 +0100
     1.3 @@ -1,3 +1,14 @@
     1.4 +2012-03-03  Andy Buckley  <andy.buckley@cern.ch>
     1.5 +
     1.6 +	* Version 1.3.0
     1.7 +
     1.8 +	* Test for presence of the mathpazo package before including it in
     1.9 +	the default preamble.
    1.10 +
    1.11 +	* Converting rendering system to use the separate tex2pix
    1.12 +	library (which itself is based on the slhaplot rendering
    1.13 +	experience).
    1.14 +
    1.15  2011-10-12  Andy Buckley  <andy@insectnation.org>
    1.16  
    1.17  	* Version 1.2.9
     2.1 --- a/pyslha.py	Thu Oct 13 17:10:35 2011 +0200
     2.2 +++ b/pyslha.py	Sat Mar 03 00:28:48 2012 +0100
     2.3 @@ -24,7 +24,7 @@
     2.4  """
     2.5  
     2.6  __author__ = "Andy Buckley <andy.buckley@cern.ch"
     2.7 -__version__ = "1.2.9"
     2.8 +__version__ = "1.3.0"
     2.9  
    2.10  
    2.11  def _autotype(var):
     3.1 --- a/setup.py	Thu Oct 13 17:10:35 2011 +0200
     3.2 +++ b/setup.py	Sat Mar 03 00:28:48 2012 +0100
     3.3 @@ -10,11 +10,11 @@
     3.4        version = pyslha.__version__,
     3.5        py_modules = ["pyslha"],
     3.6        scripts = ["slhaplot", "slha2isawig", "isawig2slha"],
     3.7 +      requires = ["tex2pix (>=0.1.5)"],
     3.8        author = 'Andy Buckley',
     3.9        author_email = 'andy@insectnation.org',
    3.10        url = 'http://www.insectnation.org/projects/pyslha',
    3.11        description = 'Parsing, manipulating, and visualising SUSY Les Houches Accord data',
    3.12        long_description = __doc__,
    3.13        keywords = 'supersymmetry susy slha simulation mass decay hep physics particle',
    3.14 -      license = 'GPL',
    3.15 -      )
    3.16 +      license = 'GPL')
     4.1 --- a/slhaplot	Thu Oct 13 17:10:35 2011 +0200
     4.2 +++ b/slhaplot	Sat Mar 03 00:28:48 2012 +0100
     4.3 @@ -127,33 +127,8 @@
     4.4      def make_png(self):
     4.5          return ("png" in self.format_string)
     4.6  
     4.7 -
     4.8 -    def need_tikz(self):
     4.9 -        for f in ["pdf", "eps", "png"]:
    4.10 -            if f in self.format_string:
    4.11 -                return True
    4.12 -        return False
    4.13 -
    4.14 -    def need_epslatex(self):
    4.15 -        for f in ["eps"]:
    4.16 -            if f in self.format_string:
    4.17 -                return True
    4.18 -        return False
    4.19 -
    4.20 -    def need_pdflatex(self):
    4.21 -        for f in ["pdf", "png"]:
    4.22 -            if f in self.format_string:
    4.23 -                return True
    4.24 -        return False
    4.25 -
    4.26 -    def need_convert(self):
    4.27 -        for f in ["png"]:
    4.28 -            if f in self.format_string:
    4.29 -                return True
    4.30 -        return False
    4.31 -
    4.32 -    def need_compilation(self):
    4.33 -        return self.need_epslatex() or self.need_pdflatex()
    4.34 +    def needs_compilation(self):
    4.35 +        return any(f in self.format_string for f in ["pdf", "eps", "png"])
    4.36  
    4.37      def file_extensions(self):
    4.38          return [f for f in ["tex", "pdf", "eps", "png"] if f in self.format_string]
    4.39 @@ -245,54 +220,11 @@
    4.40  
    4.41  
    4.42  ## Test for external packages
    4.43 -import subprocess
    4.44 -
    4.45 -## Test for tikz package if rendering the LaTeX source
    4.46 -if opts.FORMAT.need_tikz():
    4.47 -    p = subprocess.Popen(["which", "kpsewhich"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    4.48 -    rtn = p.wait()
    4.49 -    if rtn != 0:
    4.50 -        logging.warning("WARNING: kpsewhich could not be found: check for tikz package cannot be run")
    4.51 -    else:
    4.52 -        p = subprocess.Popen(["kpsewhich", "tikz.sty"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    4.53 -        rtn = p.wait()
    4.54 -        if rtn != 0:
    4.55 -            logging.error("LaTeX tikz.sty could not be found: graphical format modes cannot work")
    4.56 -            sys.exit(3)
    4.57 -
    4.58 -## Test for pdflatex if we need to make a PDF
    4.59 -if opts.FORMAT.need_pdflatex():
    4.60 -    p = subprocess.Popen(["which", "pdflatex"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    4.61 -    rtn = p.wait()
    4.62 -    if rtn != 0:
    4.63 -        logging.error("pdflatex could not be found: PDF format mode (and dependent ones like PNG) cannot work")
    4.64 -        sys.exit(3)
    4.65 -
    4.66 -    ## Test for convert if we need to make a bitmap format
    4.67 -    if opts.FORMAT.need_convert():
    4.68 -        p = subprocess.Popen(["which", "convert"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    4.69 -        rtn = p.wait()
    4.70 -        if rtn != 0:
    4.71 -            logging.error("convert could not be found: PNG format mode cannot work")
    4.72 -            sys.exit(3)
    4.73 -
    4.74 -## Test for latex, dvips and ps2eps if making an EPS
    4.75 -if opts.FORMAT.need_epslatex():
    4.76 -    p = subprocess.Popen(["which", "latex"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    4.77 -    rtn = p.wait()
    4.78 -    if rtn != 0:
    4.79 -        logging.error("latex could not be found: EPS format mode cannot work")
    4.80 -        sys.exit(3)
    4.81 -    p = subprocess.Popen(["which", "dvips"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    4.82 -    rtn = p.wait()
    4.83 -    if rtn != 0:
    4.84 -        logging.error("dvips could not be found: EPS format mode cannot work")
    4.85 -        sys.exit(3)
    4.86 -    p = subprocess.Popen(["which", "ps2eps"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    4.87 -    rtn = p.wait()
    4.88 -    if rtn != 0:
    4.89 -        logging.error("ps2eps could not be found: EPS format mode cannot work")
    4.90 -        sys.exit(3)
    4.91 +import tex2pix
    4.92 +if opts.FORMAT.needs_compilation():
    4.93 +    if not tex2pix.check_latex_pkg("tikz"):
    4.94 +        logging.error("LaTeX tikz.sty could not be found: graphical format modes cannot work")
    4.95 +        sys.exit(1)
    4.96  
    4.97  
    4.98  ## Loop over input spectrum files
    4.99 @@ -532,7 +464,8 @@
   4.100                  out += c + "\\input{%s}\n" % opts.PREAMBLE.replace(".tex", "")
   4.101          else:
   4.102              out += c + "%% Default preamble\n"
   4.103 -            out += c + "\\usepackage[osf]{mathpazo}\n"
   4.104 +            if tex2pix.check_latex_pkg("mathpazo"):
   4.105 +                out += c + "\\usepackage[osf]{mathpazo}\n"
   4.106          #
   4.107          out += c + "\n"
   4.108          out += c + "\\begin{document}\n"
   4.109 @@ -650,73 +583,18 @@
   4.110          ## Write LaTeX footer
   4.111          out += c + "\\end{document}\n"
   4.112  
   4.113 -
   4.114          ## Write output
   4.115          if opts.FORMAT.make_tex():
   4.116              writeout(out, outname+".tex")
   4.117 -
   4.118 -        if opts.FORMAT.need_compilation():
   4.119 -            ## Run LaTeX
   4.120 -            import tempfile, shutil, subprocess
   4.121 -            tmpdir = tempfile.mkdtemp()
   4.122 -            writeout(out, os.path.join(tmpdir, "mytmp.tex"))
   4.123 -
   4.124 -            def mktmpprocess(cmdlist):
   4.125 -                "Convenience method to reduce repeated subprocess.Popen call noise in what follows."
   4.126 -                return subprocess.Popen(cmdlist, cwd=tmpdir,
   4.127 -                                        stdout=subprocess.PIPE, stderr=subprocess.PIPE)
   4.128 -
   4.129 -            ## Processing via PDF
   4.130 -            if opts.FORMAT.need_pdflatex():
   4.131 -                try:
   4.132 -                    p = mktmpprocess(["pdflatex", r"\scrollmode\input", "mytmp.tex"])
   4.133 -                    p.wait()
   4.134 -                    if opts.FORMAT.make_pdf():
   4.135 -                        shutil.copyfile(os.path.join(tmpdir, "mytmp.pdf"), outname+".pdf")
   4.136 -                except Exception, e:
   4.137 -                    logging.error("pdflatex could not be run: PDF and/or PNG format mode cannot work")
   4.138 -                    shutil.rmtree(tmpdir)
   4.139 -                    sys.exit(3)
   4.140 -                    # TODO: Can we use a finally block to make sure that the tmpdir is cleared up, despite the 'sys.exit's?
   4.141 -
   4.142 -                ## Turning the PDF into a PNG if required
   4.143 -                if opts.FORMAT.make_png():
   4.144 -                    try:
   4.145 -                        p = mktmpprocess(["convert", "-density", "150", "-flatten", "mytmp.pdf", "mytmp.png"])
   4.146 -                        p.wait()
   4.147 -                        shutil.copyfile(os.path.join(tmpdir, "mytmp.png"), outname+".png")
   4.148 -                    except Exception, e:
   4.149 -                        logging.error("convert could not be run: PNG format mode cannot work")
   4.150 -                        shutil.rmtree(tmpdir)
   4.151 -                        sys.exit(3)
   4.152 -
   4.153 -            ## Making a PS or EPS
   4.154 +        if opts.FORMAT.needs_compilation():
   4.155 +            import tex2pix
   4.156 +            r = tex2pix.Renderer(out)
   4.157 +            if opts.FORMAT.make_pdf():
   4.158 +                r.mkpdf(outname+".pdf")
   4.159 +            if opts.FORMAT.make_png():
   4.160 +                r.mkpng(outname+".png")
   4.161              if opts.FORMAT.make_eps():
   4.162 -                try:
   4.163 -                    p = mktmpprocess(["latex", r"\scrollmode\input", "mytmp.tex"])
   4.164 -                    p.wait()
   4.165 -                except Exception, e:
   4.166 -                    logging.error("latex could not be run: EPS format mode cannot work")
   4.167 -                    shutil.rmtree(tmpdir)
   4.168 -                    sys.exit(3)
   4.169 -                try:
   4.170 -                    p = mktmpprocess(["dvips", "mytmp.dvi", "-o", "mytmp.ps"])
   4.171 -                    p.wait()
   4.172 -                except Exception, e:
   4.173 -                    logging.error("dvips could not be run: EPS format mode cannot work")
   4.174 -                    shutil.rmtree(tmpdir)
   4.175 -                    sys.exit(3)
   4.176 -                try:
   4.177 -                    p = mktmpprocess(["ps2eps", "mytmp.ps"])
   4.178 -                    p.wait()
   4.179 -                    shutil.copyfile(os.path.join(tmpdir, "mytmp.eps"), outname+".eps")
   4.180 -                except Exception, e:
   4.181 -                    logging.error("ps2eps could not be run: EPS format mode cannot work")
   4.182 -                    shutil.rmtree(tmpdir)
   4.183 -                    sys.exit(3)
   4.184 -
   4.185 -            shutil.rmtree(tmpdir)
   4.186 -
   4.187 +                r.mkeps(outname+".eps")
   4.188  
   4.189      ## UNRECOGNISED FORMAT!
   4.190      else:

mercurial