Changeset 123

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

LatexFormulaMacro:

add #display and #fleqn options to add html formatting around image.
patch by Christian Marquardt

Files:

Legend:

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

    r122 r123  
    44 
    55Changes: 
     6    2005-10-01: 
     7        * add #display and #fleqn options to add html formatting around image 
     8          (Christian Marquardt). 
    69    2005-09-21: 
    710        * add #center and #indent options to add html formatting around image. 
     
    2831        # display_path is URL where formula images can be accessed 
    2932        display_path = http://foo.net/formula 
     33        # Set to 1 for fleqn style equations (default is centered) 
     34        fleqn = 0 
     35        # Indentation width for fleqn style equations 
     36        fleqn_width = '5%' 
    3037 
    3138Usage: 
     
    4855    #nomode 
    4956        Disable the default display mode setting.  Use this if you want to 
    50         include things outside of tex's display mode.    
     57        include things outside of tex's display mode. 
     58    #display 
     59        Create a displayed equation (either centered or fleqn style, 
     60        depending on the fleqn variable in the config file. 
    5161    #center 
    52         Center image on the page. 
     62        Center the equation on the page. 
     63    #fleqn 
     64        fleqn style equation; indentation is controlled by fleqn_witdh in 
     65        conf/trac.ini. 
    5366    #indent [=class name] 
    5467        places image link in a paragraph <p>...</p> 
     
    87100 
    88101 
    89 def render(hdf, env, texData, density, mathMode): 
     102def render(hdf, env, texData, density, fleqnMode, mathMode): 
    90103    # gets paths from configuration 
    91104    tmpdir = env.get_config('latex', 'temp_dir') 
    92105    imagePath = env.get_config('latex', 'image_path') 
    93106    displayPath = env.get_config('latex', 'display_path') 
     107    fleqnIndent = env.get_config('latex', 'fleqn_indent') 
    94108 
    95109    if not tmpdir or not imagePath or not displayPath: 
    96110        return "<b>Error: missing configuration settings in 'latex' macro</b><br>" 
     111 
     112    if not fleqnIndent: 
     113        fleqnIndent = '5%' 
    97114 
    98115    path = tmpdir # + hdf.getValue("project.name.encoded", "default") 
     
    138155        log += execprog( cmd ) 
    139156 
    140     html = "<img src='%s/%s.jpg' border='0' style='vertical-align: middle;' alt='formula' />" % (displayPath, name) 
     157    if fleqnMode: 
     158        margin = " margin-left: %s" % fleqnIndent 
     159    else: 
     160        margin = "" 
     161         
     162    html = "<img src='%s/%s.jpg' border='0' style='vertical-align: middle;%s' alt='formula' />" % (displayPath, name, margin) 
    141163    return html 
    142164 
     
    148170    tex = "\\batchmode\n" 
    149171    tex += "\\documentclass{article}\n" 
     172    tex += "\\usepackage{amsmath}\n" 
     173    tex += "\\usepackage{amssymb}\n" 
    150174    tex += "\\usepackage{epsfig}\n" 
    151175    tex += "\\pagestyle{empty}\n" 
     
    177201    # defaults 
    178202    density = 100 
    179     mathMode = 1 #default to using display-math mode 
     203    mathMode = 1    # default to using display-math mode for LaTeX processing 
     204    displayMode = 0 # default to generating inline formula 
     205    fleqnMode   = env.get_config('latex', 'fleqn') 
    180206    centerImage = 0 
    181207    indentImage = 0 
     
    183209 
    184210    # find some number of arguments, followed by the formula 
    185     command = re.compile('^#([^=]+)=?(.*)') 
     211    command = re.compile('^\s*#([^=]+)=?(.*)') 
    186212    formula = "" 
    187213    errors = "" 
     
    195221            elif m.group(1) == "center": 
    196222                centerImage = 1 
     223                fleqnMode   = 0 
    197224            elif m.group(1) == "indent": 
    198225                indentImage = 1 
    199226                indentClass = m.group(2) 
     227            elif m.group(1) == "display": 
     228                displayMode = 1 
     229            elif m.group(1) == "fleqn": 
     230                displayMode = 1 
     231                fleqnMode   = 1 
    200232            else: 
    201233                errors = '<br>Unknown <i>formula</i> command "%s"<br>' % m.group(1) 
     
    203235            formula += line + "\n" 
    204236 
     237    # Set display and fleqn defaults 
     238    if displayMode: 
     239        if fleqnMode: 
     240            centerImage = 0 
     241        else: 
     242            centerImage = 1 
     243 
     244    # Render formula 
    205245    format = '%s' 
    206246    if centerImage: 
     
    212252            format = '<p>%s</p>' % format 
    213253     
    214     result = errors + render(hdf, env, formula, density, mathMode)  
     254    result = errors + render(hdf, env, formula, density, fleqnMode, mathMode)  
    215255    return format % result 
    216256