Changeset 123
- Timestamp:
- 10/03/05 12:17:54 (3 years ago)
- Files:
-
- latexformulamacro/0.8/formula.py (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
latexformulamacro/0.8/formula.py
r122 r123 4 4 5 5 Changes: 6 2005-10-01: 7 * add #display and #fleqn options to add html formatting around image 8 (Christian Marquardt). 6 9 2005-09-21: 7 10 * add #center and #indent options to add html formatting around image. … … 28 31 # display_path is URL where formula images can be accessed 29 32 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%' 30 37 31 38 Usage: … … 48 55 #nomode 49 56 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. 51 61 #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. 53 66 #indent [=class name] 54 67 places image link in a paragraph <p>...</p> … … 87 100 88 101 89 def render(hdf, env, texData, density, mathMode):102 def render(hdf, env, texData, density, fleqnMode, mathMode): 90 103 # gets paths from configuration 91 104 tmpdir = env.get_config('latex', 'temp_dir') 92 105 imagePath = env.get_config('latex', 'image_path') 93 106 displayPath = env.get_config('latex', 'display_path') 107 fleqnIndent = env.get_config('latex', 'fleqn_indent') 94 108 95 109 if not tmpdir or not imagePath or not displayPath: 96 110 return "<b>Error: missing configuration settings in 'latex' macro</b><br>" 111 112 if not fleqnIndent: 113 fleqnIndent = '5%' 97 114 98 115 path = tmpdir # + hdf.getValue("project.name.encoded", "default") … … 138 155 log += execprog( cmd ) 139 156 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) 141 163 return html 142 164 … … 148 170 tex = "\\batchmode\n" 149 171 tex += "\\documentclass{article}\n" 172 tex += "\\usepackage{amsmath}\n" 173 tex += "\\usepackage{amssymb}\n" 150 174 tex += "\\usepackage{epsfig}\n" 151 175 tex += "\\pagestyle{empty}\n" … … 177 201 # defaults 178 202 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') 180 206 centerImage = 0 181 207 indentImage = 0 … … 183 209 184 210 # find some number of arguments, followed by the formula 185 command = re.compile('^ #([^=]+)=?(.*)')211 command = re.compile('^\s*#([^=]+)=?(.*)') 186 212 formula = "" 187 213 errors = "" … … 195 221 elif m.group(1) == "center": 196 222 centerImage = 1 223 fleqnMode = 0 197 224 elif m.group(1) == "indent": 198 225 indentImage = 1 199 226 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 200 232 else: 201 233 errors = '<br>Unknown <i>formula</i> command "%s"<br>' % m.group(1) … … 203 235 formula += line + "\n" 204 236 237 # Set display and fleqn defaults 238 if displayMode: 239 if fleqnMode: 240 centerImage = 0 241 else: 242 centerImage = 1 243 244 # Render formula 205 245 format = '%s' 206 246 if centerImage: … … 212 252 format = '<p>%s</p>' % format 213 253 214 result = errors + render(hdf, env, formula, density, mathMode)254 result = errors + render(hdf, env, formula, density, fleqnMode, mathMode) 215 255 return format % result 216 256
