Changeset 91

Show
Ignore:
Timestamp:
08/02/05 04:44:06 (3 years ago)
Author:
vgough
Message:

LatexFormulaMacro:

Get configurable values from trac.ini instead of hard coding them. Fixes #26

Files:

Legend:

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

    r90 r91  
    44 
    55Changes: 
     6    2005-08-02: 
     7        * remove hard-coded paths, read from configuration. Fixes #26 
    68    2005-07-27: 
    79        * figured out how to get rid of the annoying internal error after latex 
     
    1315          enclosure of commands in display-math mode ("$$ ... $$") 
    1416    2005-07-26: first release 
     17 
     18Installation: 
     19    1. Copy into wiki-macros directory. 
     20    2. Edit conf/trac.ini and add a [latex] group with three values: 
     21        [latex] 
     22        # temp_dir points to directory where temporary files are created 
     23        temp_dir = /var/tmp/trac 
     24        # image_path is directory where final images are written 
     25        image_path = /var/www/html/formula 
     26        # display_path is URL where formula images can be accessed 
     27        display_path = http://foo.net/formula 
    1528 
    1629Usage: 
     
    5366""" 
    5467 
    55 # TODO: Paths to change for your system: 
    56 # directory where temporary files are created 
    57 tmpdir = "/var/www/html/trac/tex/" 
    58 # directory where images are written 
    59 imagePath = "/var/www/html/formula/" 
    60 # URL base for accessing images 
    61 displayPath = "http://arg0.net/formula/" 
    62  
    63 # if the version string changes, then images will be regenerated 
    64 version = "0.1" 
     68# if the output version string changes, then images will be regenerated 
     69outputVersion = "0.1" 
    6570 
    6671 
     
    7277 
    7378def render(hdf, env, texData, density, mathMode): 
    74     path = tmpdir # + hdf.getValue("project.name.encoded", "default") + "/" 
     79    # gets paths from configuration 
     80    tmpdir = env.get_config('latex', 'temp_dir'); 
     81    imagePath = env.get_config('latex', 'image_path'); 
     82    displayPath = env.get_config('latex', 'display_path'); 
     83 
     84    if not tmpdir or not imagePath or not displayPath: 
     85        return "<b>Error: missing configuration settings in 'latex' macro</b><br>"; 
     86 
     87    path = tmpdir # + hdf.getValue("project.name.encoded", "default") 
    7588    # create temporary directory if necessary 
    7689    try: 
    77         if os.path.exists(path) is False
     90        if not os.path.exists(path)
    7891            mkdir(path) 
    7992    except: 
     
    8497    hash = sha.new(texData); 
    8598    hash.update( "%d" % density ) 
    86     hash.update( version ) 
     99    hash.update( outputVersion ) 
    87100    name = hash.hexdigest() 
    88     jpgFile = imagePath + name + ".jpg" 
     101    jpgFile = "%s/%s.jpg" % (imagePath, name) 
    89102 
    90103    log = "<br>"; 
    91     if os.path.exists(jpgFile) is False
     104    if not os.path.exists(jpgFile)
    92105        # latex writes out lots of stuff to the current directory, so we have 
    93106        # to run it from there. 
     
    105118 
    106119        # use dvips to convert to eps 
    107         dviFile = path + name + ".dvi" 
    108         epsFile = path + name + ".eps" 
     120        dviFile = "%s/%s.dvi" % (path, name) 
     121        epsFile = "%s/%s.eps" % (path, name) 
    109122        cmd = "dvips -q -D 600 -E -n 1 -p 1 -o %s %s" % (epsFile, dviFile) 
    110123        log += execprog( cmd ) 
     
    114127        log += execprog( cmd ) 
    115128 
    116     html = "<img src='%s%s.jpg' border='0' style='vertical-align: middle;' alt='formula' />" % (displayPath, name) 
     129    html = "<img src='%s/%s.jpg' border='0' style='vertical-align: middle;' alt='formula' />" % (displayPath, name) 
    117130    return html 
    118131    #return log;