Esempio n. 1
0
def escape_latex_all(o):
    if isinstance(o, list):
        return map(escape_latex_all, o)
    elif isinstance(o, dict):
        return dict(map(lambda x: (x[0], escape_latex_all(x[1])), o.items()))
    else:
        # TODO: HACK HACK HACK. Use Cheetah custom types.
        return tex.escape_latex(str(o)).replace('LaTeX', r'\LaTeX').replace('\\textbackslash{}', '\\').replace('\\{', '{').replace('\\}', '}')
Esempio n. 2
0
def escape_tex(s):
    s = HYPERLINK_REGEX.sub(r'\href{\2}{\1}', s)
    s = tex.escape_latex(s)
    s = s.replace('LaTeX', r'\LaTeX')

    # A bit of a hack... have to reverse some of tex.escape_latex escapes
    s = s.replace('\\textbackslash{}', '\\')
    s = s.replace('\\{', '{').replace('\\}', '}')
    return s
Esempio n. 3
0
def escape_tex(s):
    s = HYPERLINK_REGEX.sub(r'\href{\2}{\1}', s)
    s = tex.escape_latex(s)
    s = s.replace('LaTeX', r'\LaTeX')

    # A bit of a hack... have to reverse some of tex.escape_latex escapes
    s = s.replace('\\textbackslash{}', '\\')
    s = s.replace('\\{', '{').replace('\\}', '}')
    return s
Esempio n. 4
0
def escape_latex_all(o):
    if isinstance(o, list):
        return map(escape_latex_all, o)
    elif isinstance(o, dict):
        return dict(map(lambda x: (x[0], escape_latex_all(x[1])), o.items()))
    else:
        # TODO: HACK HACK HACK. Use Cheetah custom types.
        return tex.escape_latex(str(o)).replace('LaTeX', r'\LaTeX').replace(
            '\\textbackslash{}', '\\').replace('\\{', '{').replace('\\}', '}')
Esempio n. 5
0
    def run(self):
        """
        Actual fetcher. Could this be threaded?
        """
        url = view_text_json % self.url
        logger.debug("Fetching URL: " + url)
        raw_content = urllib2.urlopen(url)
        json_content = json.loads(raw_content.read())
        test_content = json_content['content']
        test_content = unicodedata.normalize('NFKD',
                test_content).encode('ascii', 'ignore')

        # Here, we begin constructing the syntax tree
        parser = MyHTMLParser()
        parser.feed(test_content)

        string = """
\\documentclass[12pt]{article}
\\begin{document}
{\\Large %s}
            """ % clean(json_content['title'])

        for line in parser.lines:
            line = escape_latex(line)
            string += line
        
        string += """
\\end{document}
        """

        with open('temp.latex', 'wb+') as f:
            f.write(string)

        pdf = latex2pdf(string)
        with open('temp.pdf', 'wb+') as f:
            f.write(pdf)