Changeset 122
- Timestamp:
- 10/03/05 12:07:03 (3 years ago)
- Files:
-
- latexformulamacro/0.8/formula.py (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
latexformulamacro/0.8/formula.py
r91 r122 4 4 5 5 Changes: 6 2005-09-21: 7 * add #center and #indent options to add html formatting around image. 6 8 2005-08-02: 7 9 * remove hard-coded paths, read from configuration. Fixes #26 … … 34 36 }}} 35 37 36 or, a density can be specified:38 or, additional keywords can be specified before the latex code: 37 39 {{{ 38 40 #!formula … … 41 43 }}} 42 44 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. 45 Optional 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. 46 57 47 58 Notes: … … 78 89 def render(hdf, env, texData, density, mathMode): 79 90 # 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') 83 94 84 95 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>" 86 97 87 98 path = tmpdir # + hdf.getValue("project.name.encoded", "default") … … 95 106 # generate final image name. Use a hash of the parameters which affect 96 107 # the image, so we don't have to recreate it unless they change. 97 hash = sha.new(texData) ;108 hash = sha.new(texData) 98 109 hash.update( "%d" % density ) 99 110 hash.update( outputVersion ) … … 101 112 jpgFile = "%s/%s.jpg" % (imagePath, name) 102 113 103 log = "<br>" ;114 log = "<br>" 104 115 if not os.path.exists(jpgFile): 105 116 # latex writes out lots of stuff to the current directory, so we have … … 129 140 html = "<img src='%s/%s.jpg' border='0' style='vertical-align: middle;' alt='formula' />" % (displayPath, name) 130 141 return html 131 #return log;132 142 133 143 def execprog(cmd): … … 168 178 density = 100 169 179 mathMode = 1 #default to using display-math mode 180 centerImage = 0 181 indentImage = 0 182 indentClass = "" 170 183 171 184 # find some number of arguments, followed by the formula … … 180 193 elif m.group(1) == "nomode": 181 194 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) 182 200 else: 183 201 errors = '<br>Unknown <i>formula</i> command "%s"<br>' % m.group(1) … … 185 203 formula += line + "\n" 186 204 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 187 214 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
