Here's a patch which makes your wonderful formula macro work under the latest version of trac:
--- formula.py-0.8 2005-10-07 15:05:20.000000000 -0500
+++ formula.py-0.9 2005-10-21 18:49:42.023380773 -0500
@@ -3,6 +3,9 @@
by Valient Gough <vgough@pobox.com>
Changes:
+ 2005-10-21 Ken McIvor <mcivor@iit.edu>:
+ * Updated to support trac 0.9b2.
+ * Improved the error messages for missing configuration elements.
2005-10-03:
* make image format selectable via 'image_format' configuration option
(defaults to 'jpg')
@@ -107,32 +110,32 @@
def render(hdf, env, texData, density, fleqnMode, mathMode):
# gets paths from configuration
- tmpdir = env.get_config('latex', 'temp_dir')
- imagePath = env.get_config('latex', 'image_path')
- displayPath = env.get_config('latex', 'display_path')
- fleqnIndent = env.get_config('latex', 'fleqn_indent')
- latexPath = env.get_config('latex', 'latex_path')
- dvipsPath = env.get_config('latex', 'dvips_path')
- convertPath = env.get_config('latex', 'convert_path')
- texMag = env.get_config('latex', 'text_mag')
- imageFormat = env.get_config('latex', 'image_format')
-
- if not tmpdir or not imagePath or not displayPath:
- return "<b>Error: missing configuration settings in 'latex' macro</b><br>"
-
- # set defaults
- if not fleqnIndent:
- fleqnIndent = '5%'
- if not latexPath:
- latexPath = 'latex'
- if not dvipsPath:
- dvipsPath = 'dvips'
- if not convertPath:
- convertPath = 'convert'
- if not texMag:
- texMag = 1000 # I'm told this is latex's default value
- if not imageFormat:
- imageFormat = 'jpg'
+ cfg = env.config
+ tmpdir = cfg.get('latex', 'temp_dir')
+ imagePath = cfg.get('latex', 'image_path')
+ displayPath = cfg.get('latex', 'display_path')
+ fleqnIndent = cfg.get('latex', 'fleqn_indent', '5%')
+ latexPath = cfg.get('latex', 'latex_path', 'latex')
+ dvipsPath = cfg.get('latex', 'dvips_path', 'dvips')
+ convertPath = cfg.get('latex', 'convert_path', 'convert')
+ texMag = cfg.get('latex', 'text_mag', 1000)
+ imageFormat = cfg.get('latex', 'image_format', 'jpg')
+
+
+ def make_cfg_error(element):
+ msg = """\
+<div class="system-message">
+ <strong>Error: the <code>formula</code> macro requires the setting <code>%s</code> in the configuration section <code>latex</code></strong>
+</div>
+"""
+ return msg % element
+
+ if not tmpdir:
+ return make_cfg_error('temp_dir')
+ elif not imagePath:
+ return make_cfg_error('image_path')
+ elif not displayPath:
+ return make_cfg_error('display_path')
path = tmpdir # + hdf.getValue("project.name.encoded", "default")
# create temporary directory if necessary
@@ -219,6 +222,8 @@
# arguments start with "#" on the beginning of a line
def execute(hdf, text, env):
+ cfg = env.config
+
# TODO: unescape all html escape codes
text = text.replace("&", "&")
@@ -226,7 +231,7 @@
density = 100
mathMode = 1 # default to using display-math mode for LaTeX processing
displayMode = 0 # default to generating inline formula
- fleqnMode = env.get_config('latex', 'fleqn')
+ fleqnMode = cfg.get('latex', 'fleqn')
centerImage = 0
indentImage = 0
indentClass = ""