Attachment 'latex.1.2.1.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     Modified:
   7     2004-03-22 R.Bauer replaced config. by config_ and imported AttachFile
   8     @license: GNU GPL, see COPYING for details.
   9     2004-04-09 imported patch from Daniel Hottinger (pagestyle{empty}, -E switch of dvips, input of latex text replaced)
  10     2004-04-09 R.Bauer improvement in speed, because only if the image name is different a new image must be created
  11 
  12 """
  13 
  14 Dependencies = []
  15 
  16 import sys, os, re, sha
  17 from MoinMoin.Page import Page
  18 from MoinMoin.action import AttachFile
  19 
  20 config_external_latex = "/usr/bin/latex"
  21 config_external_convert = "/usr/bin/convert"
  22 config_external_dvips = "/usr/bin/dvips"
  23 config_umask = 022
  24 
  25 config_latex_cache_dir = "./data"
  26 config_latex_cache_url = "./data"
  27 config_latex_header = "\documentclass[a4paper,12pt]{article}\n\pagestyle{empty}"
  28 config_latex_vartmp_dir = "./data/tmp"
  29 
  30 def process(request, formatter, lines):
  31     if not config_latex_cache_dir:
  32     	return
  33     if lines[0].strip() == "#!latex":
  34         del lines[0]
  35 
  36     texstr = '\n'.join(lines).strip()
  37 
  38     imgname = re.sub('\s+', ' ', texstr)
  39     imgname = sha.new(imgname).hexdigest()
  40 
  41     attdir = config_latex_cache_dir + "/LaTex/attachments"
  42     atturl = config_latex_cache_url + "/LaTex/attachments"
  43     outpath = "%s/%s.png" % (attdir, imgname)
  44     outurl = "%s/%s.png" % (atturl, imgname)
  45     if not os.path.isdir(attdir):
  46         os.makedirs(attdir, 0775)
  47 
  48     pagename=formatter.page.page_name
  49 
  50     url=AttachFile.getAttachUrl(pagename,imgname+'.png',request)
  51     attach_dir=AttachFile.getAttachDir(pagename,create=1)
  52 
  53     if not os.path.isfile(attach_dir+'/'+imgname+'.png'):
  54      if not os.path.exists(outpath):
  55         vartmp = config_latex_vartmp_dir
  56         data = open("%s/%s.tex" % (vartmp, imgname), "w")
  57         data.write('%s\n\\begin{document}\n%s\n\\end{document}' % (config_latex_header, texstr))
  58         data.close()
  59 
  60         cmd = "cd %(vartmp)s;%(latex)s %(options)s %(tex)s >/dev/null" % {
  61            "latex": config_external_latex,
  62            "vartmp": vartmp,
  63            "options": '-interaction=batchmode',
  64            "tex": imgname
  65         }
  66 	os.umask(config_umask)
  67         os.system(cmd)
  68         os.system("cd %(vartmp)s; %(dvips)s -E %(imgname)s.dvi -o %(imgname)s.ps >/dev/null" % {
  69             "dvips": config_external_dvips,
  70             "vartmp": vartmp,
  71             "imgname": imgname,
  72         })
  73 
  74 
  75 
  76         os.system("%(convert)s -crop 0x0 -density 120x120 %(vartmp)s/%(imgname)s.ps %(outpath)s" % {
  77             "convert": config_external_convert,
  78             "vartmp": vartmp,
  79             "outpath": attach_dir+'/'+imgname+'.png',
  80             "imgname": imgname,
  81         })
  82 
  83 
  84         os.system("rm -f %(vartmp)s/%(imgname)s.*" % {
  85             "vartmp": vartmp,
  86             "imgname": imgname,
  87         })
  88 
  89 
  90     request.write(formatter.image(src="%s" % url, alt=texstr, align='absmiddle'))

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.