Changeset 124

Show
Ignore:
Timestamp:
10/03/05 12:38:39 (3 years ago)
Author:
vgough
Message:

LatexFormulaMacro:

Make image format selectable via 'image_format' configuration option (defaults
to 'jpg').

Allow paths to executables to be specified in configuration by setting
'latex_path', 'dvips_path', 'convert_path' to point to executable. Based on
code by Reed Cartwright.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • latexformulamacro/0.8/formula.py

    r123 r124  
    44 
    55Changes: 
     6    2005-10-03: 
     7        * make image format selectable via 'image_format' configuration option 
     8          (defaults to 'jpg') 
     9        * allow paths to executables to be specified in configuration by 
     10          setting 'latex_path', 'dvips_path', 'convert_path' to point to 
     11          executable. Based on code by Reed Cartwright. 
    612    2005-10-01: 
    713        * add #display and #fleqn options to add html formatting around image 
     
    106112    displayPath = env.get_config('latex', 'display_path') 
    107113    fleqnIndent = env.get_config('latex', 'fleqn_indent') 
     114    latexPath = env.get_config('latex', 'latex_path') 
     115    dvipsPath = env.get_config('latex', 'dvips_path') 
     116    convertPath = env.get_config('latex', 'convert_path') 
     117    texMag = env.get_config('latex', 'mag') 
     118    imageFormat = env.get_config('latex', 'image_format') 
    108119 
    109120    if not tmpdir or not imagePath or not displayPath: 
    110121        return "<b>Error: missing configuration settings in 'latex' macro</b><br>" 
    111122 
     123    # set defaults 
    112124    if not fleqnIndent: 
    113125        fleqnIndent = '5%' 
     126    if not latexPath: 
     127        latexPath = 'latex' 
     128    if not dvipsPath: 
     129        dvipsPath = 'dvips' 
     130    if not convertPath: 
     131        convertPath = 'convert' 
     132    if not texMag: 
     133        texMag = '1' # TODO: need a reasonable default here.. 
     134    if not imageFormat: 
     135        imageFormat = 'jpg' 
    114136 
    115137    path = tmpdir # + hdf.getValue("project.name.encoded", "default") 
     
    127149    hash.update( outputVersion ) 
    128150    name = hash.hexdigest() 
    129     jpgFile = "%s/%s.jpg" % (imagePath, name
     151    imageFile = "%s/%s.%s" % (imagePath, name, imageFormat
    130152 
    131153    log = "<br>" 
    132     if not os.path.exists(jpgFile): 
     154    if not os.path.exists(imageFile): 
    133155        # latex writes out lots of stuff to the current directory, so we have 
    134156        # to run it from there. 
     
    137159 
    138160        texFile = name + ".tex" 
    139         makeTexFile(texFile, texData, mathMode
     161        makeTexFile(texFile, texData, mathMode, texMag
    140162 
    141163        # the output from latex on stdout seems to cause problems, so sent it 
    142164        # to /dev/null 
    143         cmd = "latex %s > /dev/null" % texFile 
     165        cmd = "%s %s > /dev/null" % (latexPath, texFile) 
    144166        log += execprog( cmd ) 
    145167        os.chdir(cwd) 
     
    148170        dviFile = "%s/%s.dvi" % (path, name) 
    149171        epsFile = "%s/%s.eps" % (path, name) 
    150         cmd = "dvips -q -D 600 -E -n 1 -p 1 -o %s %s" % (epsFile, dviFile) 
     172        cmd = "%s -q -D 600 -E -n 1 -p 1 -o %s %s" % (dvipsPath, epsFile, dviFile) 
    151173        log += execprog( cmd ) 
    152174 
    153         # and finally, ImageMagick to convert from eps to jpg 
    154         cmd = "convert -antialias -density %ix%i %s %s" % (density, density, epsFile, jpgFile) 
     175        # and finally, ImageMagick to convert from eps to [imageFormat] type 
     176        cmd = "%s -antialias -density %ix%i %s %s" % (convertPath, density, density, epsFile, imageFile) 
    155177        log += execprog( cmd ) 
    156178 
     
    160182        margin = "" 
    161183         
    162     html = "<img src='%s/%s.jpg' border='0' style='vertical-align: middle;%s' alt='formula' />" % (displayPath, name, margin) 
     184    html = "<img src='%s/%s.%s' border='0' style='vertical-align: middle;%s' alt='formula' />" % (displayPath, name, imageFormat, margin) 
    163185    return html 
    164186 
     
    167189    return cmd + "<br>" 
    168190 
    169 def makeTexFile(texFile, texData, mathMode): 
     191def makeTexFile(texFile, texData, mathMode, texMag): 
    170192    tex = "\\batchmode\n" 
    171193    tex += "\\documentclass{article}\n" 
     
    174196    tex += "\\usepackage{epsfig}\n" 
    175197    tex += "\\pagestyle{empty}\n" 
     198# TODO: magnification doesn't work correctly.. 
     199    #tex += "\\mag=%s\n" % texMag 
    176200    # matrix macro 
    177201    tex += "\\newcommand{\\mat}[2][rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr]{\n"