File: mimetex.py

package info (click to toggle)
nodebox-web 1.9.2-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,724 kB
  • ctags: 1,254
  • sloc: python: 6,161; sh: 602; xml: 239; makefile: 33
file content (29 lines) | stat: -rw-r--r-- 785 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from url import URLAccumulator
from urllib import quote
from cache import Cache

def clear_cache():
    Cache("mimetex").clear()

class mimeTeX(URLAccumulator):
    
    """ The mimeTeX server returns a GIF-image for a LaTeX math expression.
    http://www.forkosh.com/mimetex.html
    """
    
    def __init__(self, eq, wait=10, asynchronous=False):
        
        url = "http://www.forkosh.dreamhost.com/mimetex.cgi?"+quote(eq)
        URLAccumulator.__init__(self, url, wait, asynchronous, "mimetex", type=".gif", throttle=1)

    def load(self, data):
        
        # Provide the path to the GIF stored in cache.
        self.image = self._cache.hash(self.url)

def gif(eq):
    
    return mimeTeX(eq).image

#eq = "E = hf = \frac{hc}{\lambda} \,\! "
#image(gif(eq), 10, 10)