Changeset 122

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

LatexFormulaMacro:

add #center and #indent options to add html formatting around image

Files:

Legend:

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

    r91 r122  
    44 
    55Changes: 
     6    2005-09-21: 
     7        * add #center and #indent options to add html formatting around image. 
    68    2005-08-02: 
    79        * remove hard-coded paths, read from configuration. Fixes #26 
     
    3436}}} 
    3537 
    36 or, a density can be specified
     38or, additional keywords can be specified before the latex code
    3739{{{ 
    3840#!formula 
     
    4143}}} 
    4244 
    43 Options: 
    44     Density defaults to 100.  Larger values produces larger images. 
    45     Density is optional, but if it is include, it must be included first. 
     45Optional keywords (must be specified before the latex code): 
     46    #density=100 
     47        Density defaults to 100.  Larger values produces larger images. 
     48    #nomode 
     49        Disable the default display mode setting.  Use this if you want to 
     50        include things outside of tex's display mode.    
     51    #center 
     52        Center image on the page. 
     53    #indent [=class name] 
     54        places image link in a paragraph <p>...</p> 
     55        If class name is specified, then it is used to specify a CSS class for 
     56        the paragraph. 
    4657 
    4758Notes: 
     
    7889def render(hdf, env, texData, density, mathMode): 
    7990    # 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'); 
     91    tmpdir = env.get_config('latex', 'temp_dir') 
     92    imagePath = env.get_config('latex', 'image_path') 
     93    displayPath = env.get_config('latex', 'display_path') 
    8394 
    8495    if not tmpdir or not imagePath or not displayPath: 
    85         return "<b>Error: missing configuration settings in 'latex' macro</b><br>"; 
     96        return "<b>Error: missing configuration settings in 'latex' macro</b><br>" 
    8697 
    8798    path = tmpdir # + hdf.getValue("project.name.encoded", "default") 
     
    95106    # generate final image name.  Use a hash of the parameters which affect 
    96107    # the image, so we don't have to recreate it unless they change. 
    97     hash = sha.new(texData); 
     108    hash = sha.new(texData) 
    98109    hash.update( "%d" % density ) 
    99110    hash.update( outputVersion ) 
     
    101112    jpgFile = "%s/%s.jpg" % (imagePath, name) 
    102113 
    103     log = "<br>"; 
     114    log = "<br>" 
    104115    if not os.path.exists(jpgFile): 
    105116        # latex writes out lots of stuff to the current directory, so we have 
     
    129140    html = "<img src='%s/%s.jpg' border='0' style='vertical-align: middle;' alt='formula' />" % (displayPath, name) 
    130141    return html 
    131     #return log; 
    132142 
    133143def execprog(cmd): 
     
    168178    density = 100 
    169179    mathMode = 1 #default to using display-math mode 
     180    centerImage = 0 
     181    indentImage = 0 
     182    indentClass = "" 
    170183 
    171184    # find some number of arguments, followed by the formula 
     
    180193            elif m.group(1) == "nomode": 
    181194                mathMode = 0 
     195            elif m.group(1) == "center": 
     196                centerImage = 1 
     197            elif m.group(1) == "indent": 
     198                indentImage = 1 
     199                indentClass = m.group(2) 
    182200            else: 
    183201                errors = '<br>Unknown <i>formula</i> command "%s"<br>' % m.group(1) 
     
    185203            formula += line + "\n" 
    186204 
     205    format = '%s' 
     206    if centerImage: 
     207        format = '<center>%s</center>' % format 
     208    if indentImage: 
     209        if indentClass: 
     210            format = '<p class="%s">%s</p>' % (indentClass, format) 
     211        else: 
     212            format = '<p>%s</p>' % format 
     213     
    187214    result = errors + render(hdf, env, formula, density, mathMode)  
    188     #result += "<br> density = %d" % density 
    189     #result += "<br>text: %s" % formula 
    190     return result; 
    191  
    192  
     215    return format % result 
     216