| 581 | | |
| | 581 | exitcode = 0 |
| | 582 | |
| | 583 | # some latex commands are really bad |
| | 584 | blacklist = ["\\def", "\\let", "\\futurelet", |
| | 585 | "\\newcommand", "\\renewcomment", "\\else", "\\fi", "\\write", |
| | 586 | "\\input", "\\include", "\\chardef", "\\catcode", "\\makeatletter", |
| | 587 | "\\noexpand", "\\toksdef", "\\every", "\\errhelp", "\\errorstopmode", |
| | 588 | "\\scrollmode", "\\nonstopmode", "\\batchmode", "\\read", "\\csname", |
| | 589 | "\\newhelp", "\\relax", "\\afterground", "\\afterassignment", |
| | 590 | "\\expandafter", "\\noexpand", "\\special", "\\command", "\\loop", |
| | 591 | "\\repeat", "\\toks", "\\output", "\\line", "\\mathcode", "\\name", |
| | 592 | "\\item", "\\section", "\\mbox", "\\DeclareRobustCommand", "\\[", |
| | 593 | "\\]"] |
| | 594 | |
| 583 | | |
| 584 | | random.seed() |
| 585 | | tmpfile = os.path.join(gettempdir(), "gajimtex_" + random.randint(0, 100).__str__()) |
| 586 | | |
| 587 | | # build latex string |
| 588 | | texstr = "\\documentclass[12pt]{article}\\usepackage[dvips]{graphicx}\\usepackage{amsmath}\\usepackage{amssymb}\\pagestyle{empty}" |
| 589 | | texstr += "\\begin{document}\\begin{large}\\begin{gather*}" |
| 590 | | texstr += str |
| 591 | | texstr += "\\end{gather*}\\end{large}\\end{document}" |
| 592 | | |
| 593 | | file = open(os.path.join(tmpfile + ".tex"), "w+") |
| 594 | | file.write(texstr) |
| 595 | | file.flush() |
| 596 | | file.close() |
| 597 | | |
| 598 | | p = Popen(['latex', '--interaction=nonstopmode', tmpfile + '.tex'], cwd=gettempdir()) |
| 599 | | exitcode = p.wait() |
| | 596 | |
| | 597 | # filter latex code with bad commands |
| | 598 | for word in blacklist: |
| | 599 | if word in str: |
| | 600 | exitcode = 1 |
| | 601 | break |
| | 602 | |
| | 603 | if exitcode == 0: |
| | 604 | random.seed() |
| | 605 | tmpfile = os.path.join(gettempdir(), "gajimtex_" + random.randint(0, |
| | 606 | 100).__str__()) |
| | 607 | |
| | 608 | # build latex string |
| | 609 | texstr = "\\documentclass[12pt]{article}\\usepackage[dvips]{graphicx}\\usepackage{amsmath}\\usepackage{amssymb}\\pagestyle{empty}" |
| | 610 | texstr += "\\begin{document}\\begin{large}\\begin{gather*}" |
| | 611 | texstr += str |
| | 612 | texstr += "\\end{gather*}\\end{large}\\end{document}" |
| | 613 | |
| | 614 | file = open(os.path.join(tmpfile + ".tex"), "w+") |
| | 615 | file.write(texstr) |
| | 616 | file.flush() |
| | 617 | file.close() |
| | 618 | |
| | 619 | p = Popen(['latex', '--interaction=nonstopmode', tmpfile + '.tex'], |
| | 620 | cwd=gettempdir()) |
| | 621 | exitcode = p.wait() |