Changeset 124
- Timestamp:
- 10/03/05 12:38:39 (3 years ago)
- Files:
-
- latexformulamacro/0.8/formula.py (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
latexformulamacro/0.8/formula.py
r123 r124 4 4 5 5 Changes: 6 2005-10-03: 7 * make image format selectable via 'image_format' configuration option 8 (defaults to 'jpg') 9 * allow paths to executables to be specified in configuration by 10 setting 'latex_path', 'dvips_path', 'convert_path' to point to 11 executable. Based on code by Reed Cartwright. 6 12 2005-10-01: 7 13 * add #display and #fleqn options to add html formatting around image … … 106 112 displayPath = env.get_config('latex', 'display_path') 107 113 fleqnIndent = env.get_config('latex', 'fleqn_indent') 114 latexPath = env.get_config('latex', 'latex_path') 115 dvipsPath = env.get_config('latex', 'dvips_path') 116 convertPath = env.get_config('latex', 'convert_path') 117 texMag = env.get_config('latex', 'mag') 118 imageFormat = env.get_config('latex', 'image_format') 108 119 109 120 if not tmpdir or not imagePath or not displayPath: 110 121 return "<b>Error: missing configuration settings in 'latex' macro</b><br>" 111 122 123 # set defaults 112 124 if not fleqnIndent: 113 125 fleqnIndent = '5%' 126 if not latexPath: 127 latexPath = 'latex' 128 if not dvipsPath: 129 dvipsPath = 'dvips' 130 if not convertPath: 131 convertPath = 'convert' 132 if not texMag: 133 texMag = '1' # TODO: need a reasonable default here.. 134 if not imageFormat: 135 imageFormat = 'jpg' 114 136 115 137 path = tmpdir # + hdf.getValue("project.name.encoded", "default") … … 127 149 hash.update( outputVersion ) 128 150 name = hash.hexdigest() 129 jpgFile = "%s/%s.jpg" % (imagePath, name)151 imageFile = "%s/%s.%s" % (imagePath, name, imageFormat) 130 152 131 153 log = "<br>" 132 if not os.path.exists( jpgFile):154 if not os.path.exists(imageFile): 133 155 # latex writes out lots of stuff to the current directory, so we have 134 156 # to run it from there. … … 137 159 138 160 texFile = name + ".tex" 139 makeTexFile(texFile, texData, mathMode )161 makeTexFile(texFile, texData, mathMode, texMag) 140 162 141 163 # the output from latex on stdout seems to cause problems, so sent it 142 164 # to /dev/null 143 cmd = " latex %s > /dev/null" % texFile165 cmd = "%s %s > /dev/null" % (latexPath, texFile) 144 166 log += execprog( cmd ) 145 167 os.chdir(cwd) … … 148 170 dviFile = "%s/%s.dvi" % (path, name) 149 171 epsFile = "%s/%s.eps" % (path, name) 150 cmd = " dvips -q -D 600 -E -n 1 -p 1 -o %s %s" % (epsFile, dviFile)172 cmd = "%s -q -D 600 -E -n 1 -p 1 -o %s %s" % (dvipsPath, epsFile, dviFile) 151 173 log += execprog( cmd ) 152 174 153 # and finally, ImageMagick to convert from eps to jpg154 cmd = " convert -antialias -density %ix%i %s %s" % (density, density, epsFile, jpgFile)175 # and finally, ImageMagick to convert from eps to [imageFormat] type 176 cmd = "%s -antialias -density %ix%i %s %s" % (convertPath, density, density, epsFile, imageFile) 155 177 log += execprog( cmd ) 156 178 … … 160 182 margin = "" 161 183 162 html = "<img src='%s/%s. jpg' border='0' style='vertical-align: middle;%s' alt='formula' />" % (displayPath, name, margin)184 html = "<img src='%s/%s.%s' border='0' style='vertical-align: middle;%s' alt='formula' />" % (displayPath, name, imageFormat, margin) 163 185 return html 164 186 … … 167 189 return cmd + "<br>" 168 190 169 def makeTexFile(texFile, texData, mathMode ):191 def makeTexFile(texFile, texData, mathMode, texMag): 170 192 tex = "\\batchmode\n" 171 193 tex += "\\documentclass{article}\n" … … 174 196 tex += "\\usepackage{epsfig}\n" 175 197 tex += "\\pagestyle{empty}\n" 198 # TODO: magnification doesn't work correctly.. 199 #tex += "\\mag=%s\n" % texMag 176 200 # matrix macro 177 201 tex += "\\newcommand{\\mat}[2][rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr]{\n"
