Modify

Opened 19 years ago

Closed 18 years ago

#65 closed enhancement (wontfix)

Trac 0.9b2 compatability

Reported by: Ken McIvor <mcivor@…> Owned by: Valient Gough
Priority: normal Component: LatexFormulaMacro
Severity: normal Keywords: patch
Cc: Trac Release: 0.8

Description

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("&amp;", "&")

@@ -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 = ""

Attachments (0)

Change History (4)

comment:1 Changed 19 years ago by cryos@…

Applied this patch to my trac installation and I can now use the latex macros in my installation of 0.9 beta2. It seems to work well after applying the patch and realising that the htdocs directory is served up as $projectbaseurl/chrome/site.

comment:2 Changed 19 years ago by Valient Gough

Resolution: fixed
Status: newclosed

(In [678]) Apply changes from Ken McIvor fixes #65

comment:3 Changed 18 years ago by gdelfino

Resolution: fixed
Status: closedreopened
Trac Release: 0.8

Is this compatible with Trac 0.10?

comment:4 Changed 18 years ago by Ken McIvor <mcivken@…>

Resolution: wontfix
Status: reopenedclosed

I don't know if it's compatible with version 0.10. You should try and then open a new ticket if you discover problems.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Valient Gough.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.