Attachment 'latex.py'

Download

   1 """
   2     MoinMoin - Processor for a LaTeX syntax
   3 
   4     @copyright: 2002 by Won-kyu Park <wkpark@kldp.org>
   5     @copyright: 2003 by Benny Siegert (added config.latex_header)
   6     @license: GNU GPL, see COPYING for details.
   7 """
   8 
   9 Dependencies = []
  10 
  11 import sys, os, re, sha
  12 from MoinMoin import config
  13 
  14 config_external_latex = "/usr/bin/latex"
  15 config_external_convert = "/usr/bin/convert"
  16 config_external_dvips = "/usr/bin/dvips"
  17 config_umask = 022
  18 
  19 def process(request, formatter, lines):
  20     if not config.latex_cache_dir:
  21     	return
  22     if lines[0].strip() == "#!latex":
  23         del lines[0]
  24 
  25     texstr = '\n'.join(lines).strip()
  26 
  27     imgname = re.sub('\s+', ' ', texstr)
  28     imgname = sha.new(imgname).hexdigest()
  29 
  30     attdir = config.latex_cache_dir + "/LaTex/attachments"
  31     atturl = config.latex_cache_url + "/LaTex/attachments"
  32     outpath = "%s/%s.png" % (attdir, imgname)
  33     outurl = "%s/%s.png" % (atturl, imgname)
  34     if not os.path.isdir(attdir):
  35         os.makedirs(attdir, 0775)
  36 
  37     if not os.path.exists(outpath):
  38         vartmp = config.latex_vartmp_dir
  39         data = open("%s/%s.tex" % (vartmp, imgname), "w")
  40         data.write('\\input %s\n%s\n\\end{document}' % (config.latex_header, texstr))
  41         data.close()
  42 
  43         cmd = "cd %(vartmp)s;%(latex)s %(options)s %(tex)s >/dev/null" % {
  44            "latex": config_external_latex,
  45            "vartmp": vartmp,
  46            "options": '-interaction=batchmode',
  47            "tex": imgname
  48         }
  49 	os.umask(config_umask)
  50         os.system(cmd)
  51 	os.system("cd %(vartmp)s; %(dvips)s %(imgname)s.dvi -o %(imgname)s.ps" % {
  52             "dvips": config_external_dvips,
  53             "vartmp": vartmp,
  54             "imgname": imgname,
  55         })
  56         os.system("%(convert)s -crop 0x0 -density 120x120 %(vartmp)s/%(imgname)s.ps %(outpath)s" % {
  57             "convert": config_external_convert,
  58             "vartmp": vartmp,
  59             "outpath": outpath,
  60         })
  61         os.system("rm -f %(vartmp)s/%(imgname)s.*" % {
  62             "vartmp": vartmp,
  63             "imgname": imgname,
  64         })
  65 
  66     request.write(formatter.image(src="%s" % outurl, alt=texstr, align='absmiddle'))
  67     

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2004-05-05 21:34:20, 10.3 KB) [[attachment:AbcMusic.py]]
  • [get | view] (2004-04-15 07:19:38, 3.4 KB) [[attachment:DataLanguage.py]]
  • [get | view] (2004-04-15 20:23:33, 2.5 KB) [[attachment:GANTT-1.2.1.py]]
  • [get | view] (2003-12-07 18:15:55, 2.4 KB) [[attachment:GANTT.py]]
  • [get | view] (2004-07-29 15:04:28, 12.1 KB) [[attachment:IndentTable.py]]
  • [get | view] (2004-10-05 13:12:16, 10.6 KB) [[attachment:MySQL.py]]
  • [get | view] (2004-03-27 18:55:57, 3.7 KB) [[attachment:SimpleTable.py]]
  • [get | view] (2003-12-07 18:15:55, 1.5 KB) [[attachment:TextOnRight.py]]
  • [get | view] (2004-09-17 06:53:46, 3.0 KB) [[attachment:awktable-1.2.3.py]]
  • [get | view] (2004-10-28 13:55:04, 1.0 KB) [[attachment:colorer.py]]
  • [get | view] (2004-11-04 00:26:37, 1.4 KB) [[attachment:csv_python_module.diff]]
  • [get | view] (2004-04-21 18:29:38, 0.2 KB) [[attachment:html.py]]
  • [get | view] (2004-08-16 10:59:24, 4.8 KB) [[attachment:latex-1.2.3.py]]
  • [get | view] (2004-08-07 07:36:59, 3.9 KB) [[attachment:latex-cygwin.py]]
  • [get | view] (2004-04-09 17:05:33, 2.9 KB) [[attachment:latex.1.2.1.py]]
  • [get | view] (2004-02-29 16:50:13, 2.1 KB) [[attachment:latex.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.