Changeset 678

Show
Ignore:
Timestamp:
04/21/06 00:33:50 (3 years ago)
Author:
vgough
Message:

LatexFormulaMacro:

Apply changes from Ken McIvor?
fixes #65

Files:

Legend:

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

    r677 r678  
    1010        * replaced every Tab by spaces 
    1111        * make tmp dir creation recursive  
     12    2005-10-21:  Ken McIvor <mcivor@iit.edu>: 
     13        * Updated to support trac 0.9b2. 
     14        * Improved the error messages for missing configuration elements. 
    1215    2005-10-03: 
    1316        * make image format selectable via 'image_format' configuration option 
     
    112115    tmpdir = env.config.get('latex', 'temp_dir') 
    113116 
    114     fleqnIndent = env.config.get('latex', 'fleqn_indent') 
    115     latexPath = env.config.get('latex', 'latex_path') 
    116     dvipsPath = env.config.get('latex', 'dvips_path') 
    117     convertPath = env.config.get('latex', 'convert_path') 
    118     texMag = env.config.get('latex', 'text_mag') 
    119     imageFormat = env.config.get('latex', 'image_format') 
     117    cfg = env.config 
     118    fleqnIndent = cfg.get('latex', 'fleqn_indent', '5%') 
     119    latexPath = cfg.get('latex', 'latex_path', 'latex') 
     120    dvipsPath = cfg.get('latex', 'dvips_path', 'dvips') 
     121    convertPath = cfg.get('latex', 'convert_path', 'convert') 
     122    texMag = cfg.get('latex', 'text_mag', 1000) 
     123    imageFormat = cfg.get('latex', 'image_format', 'png') 
    120124 
    121125    imagePath = os.path.normpath(os.path.join(env.get_htdocs_dir(), "formulas")) 
     
    126130            return "<b>Error: unable to create image directory</b><br>"         
    127131 
     132    def make_cfg_error(element): 
     133        msg = """\ 
     134<div class="system-message"> 
     135    <strong>Error: the <code>formula</code> macro requires the 
     136        setting <code>%s</code> in the configuration section 
     137        <code>latex</code> 
     138    </strong> 
     139</div> 
     140""" 
     141        return msg % element 
     142 
    128143    if not tmpdir: 
    129         return "<b>Error: missing configuration 'tmpdir' setting in 'latex' macro</b><br>" 
    130  
    131     # set defaults 
    132     if not fleqnIndent: 
    133         fleqnIndent = '5%' 
    134     if not latexPath: 
    135         latexPath = 'latex' 
    136     if not dvipsPath: 
    137         dvipsPath = 'dvips' 
    138     if not convertPath: 
    139         convertPath = 'convert' 
    140     if not texMag: 
    141         texMag = 1000 # I'm told this is latex's default value 
    142     if not imageFormat: 
    143         imageFormat = 'png' 
     144        return make_cfg_error('temp_dir') 
     145    if not imagePath: 
     146        return make_cfg_error('image_path') 
    144147 
    145148    path = tmpdir 
     
    236239# arguments start with "#" on the beginning of a line 
    237240def execute(hdf, text, env): 
     241    cfg = env.config 
     242 
    238243    # TODO: unescape all html escape codes 
    239  
    240244    text = text.replace("&amp;", "&") 
    241245         
     
    244248    mathMode = 1    # default to using display-math mode for LaTeX processing 
    245249    displayMode = 0 # default to generating inline formula 
    246     fleqnMode   = env.config.get('latex', 'fleqn') 
     250    fleqnMode   = cfg.get('latex', 'fleqn') 
    247251    centerImage = 0 
    248252    indentImage = 0