Пример #1
0
def test_latexformula():
    png = datadir.join("test.png")
    formula = r'$$Entropy(T) = - \sum^{m}_{j=1}  \frac{|T_j|}{|T|} \log \frac{|T_j|}{|T|}$$'
    #does not crash
    latexformula2png(formula, png)
    assert png.check()
    png.remove()
Пример #2
0
def latexformula_role(name,
                      rawtext,
                      text,
                      lineno,
                      inliner,
                      options={},
                      content=[]):
    if _backend == 'latex':
        options['format'] = 'latex'
        return roles.raw_role(name, rawtext, text, lineno, inliner, options,
                              content)
    else:
        # XXX: make the place of the image directory configurable
        sourcedir = py.path.local(inliner.document.settings._source).dirpath()
        imagedir = sourcedir.join("img")
        if not imagedir.check():
            imagedir.mkdir()
        # create halfway senseful imagename:
        # use hash of formula + alphanumeric characters of it
        # could
        imagename = "%s_%s.png" % (hash(text), "".join(
            [c for c in text if c.isalnum()]))
        image = imagedir.join(imagename)
        latexformula2png(unescape(text, True), image)
        imagenode = nodes.image(image.relto(sourcedir),
                                uri=image.relto(sourcedir))
        return [imagenode], []
Пример #3
0
def test_latexformula():
    png = datadir.join("test.png")
    formula = r'$$Entropy(T) = - \sum^{m}_{j=1}  \frac{|T_j|}{|T|} \log \frac{|T_j|}{|T|}$$'
    #does not crash
    latexformula2png(formula, png)
    assert png.check()
    png.remove()
Пример #4
0
def latexformula_role(name, rawtext, text, lineno, inliner,
                      options={}, content=[]):
    if _backend == 'latex':
        options['format'] = 'latex'
        return roles.raw_role(name, rawtext, text, lineno, inliner,
                              options, content)
    else:
        # XXX: make the place of the image directory configurable
        sourcedir = py.path.local(inliner.document.settings._source).dirpath()
        imagedir = sourcedir.join("img")
        if not imagedir.check():
            imagedir.mkdir()
        # create halfway senseful imagename:
        # use hash of formula + alphanumeric characters of it
        # could
        imagename = "%s_%s.png" % (
            hash(text), "".join([c for c in text if c.isalnum()]))
        image = imagedir.join(imagename)
        latexformula2png(unescape(text, True), image)
        imagenode = nodes.image(image.relto(sourcedir), uri=image.relto(sourcedir))
        return [imagenode], []