Exemple #1
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], []
def _raw_HTML_role(
      # _`roleName`: the local name of the interpreted role, the role name actually used in the document.
      roleName,
      # _`rawtext` is a string containing the enitre interpreted text input, including the role and markup. Return it as a problematic node linked to a system message if a problem is encountered.
      rawtext,
      # The interpreted _`text` content.
      text,
      # The line number (_`lineno`) where the interpreted text begins.
      lineno,
      # _`inliner` is the docutils.parsers.rst.states.Inliner object that called this function. It contains the several attributes useful for error reporting and document tree access.
      inliner,
      # A dictionary of directive _`options` for customization (from the "role" directive), to be interpreted by this function. Used for additional attributes for the generated elements and other functionality.
      options={},
      # A list of strings, the directive _`content` for customization (from the "role" directive). To be interpreted by the role function.
      content=[]):

    return roles.raw_role(roleName, rawtext, text, lineno, inliner, {'format': 'html'}, content)
Exemple #3
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], []
Exemple #4
0
def raw_html_role(*args, options={}, **kw):
    options["format"] = "html"
    from docutils.parsers.rst.roles import raw_role
    return raw_role(*args, options=options, **kw)