From 83f8cea529bd5efe8c41ee9322de02e1a352223c Mon Sep 17 00:00:00 2001 From: Johan Engelen Date: Sat, 10 Apr 2010 20:59:57 +0200 Subject: [PATCH] commit patch for LaTeX equation render extension by Christoph Schmidt-Hieber --- po/inkscape.pot | 8 ++++++++ share/extensions/eqtexsvg.inx | 1 + share/extensions/eqtexsvg.py | 27 ++++++++++++++++++++++----- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/po/inkscape.pot b/po/inkscape.pot index c88c30501..5b5857d7a 100644 --- a/po/inkscape.pot +++ b/po/inkscape.pot @@ -705,6 +705,14 @@ msgstr "" msgid "LaTeX formula: " msgstr "" +#: ../share/extensions/eqtexsvg.inx.h:3 +msgid "Additional packages" +msgstr "" + +#: ../share/extensions/eqtexsvg.inx.h:4 +msgid "Additional packages (comma-separated): " +msgstr "" + #: ../share/extensions/export_gimp_palette.inx.h:1 msgid "Export as GIMP Palette" msgstr "" diff --git a/share/extensions/eqtexsvg.inx b/share/extensions/eqtexsvg.inx index e99dfeb1d..70516b33f 100644 --- a/share/extensions/eqtexsvg.inx +++ b/share/extensions/eqtexsvg.inx @@ -8,6 +8,7 @@ dvips pstoedit \(\displaystyle\frac{\pi^2}{6}=\lim_{n \to \infty}\sum_{k=1}^n \frac{1}{k^2}\) + all diff --git a/share/extensions/eqtexsvg.py b/share/extensions/eqtexsvg.py index 563bf2c4c..8e2e70a10 100644 --- a/share/extensions/eqtexsvg.py +++ b/share/extensions/eqtexsvg.py @@ -9,6 +9,9 @@ This extension need, to work properly: Copyright (C) 2006 Julien Vitard +2010-04-04: Added support for custom packages + Christoph Schmidt-Hieber + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or @@ -27,15 +30,24 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA import inkex, os, tempfile, sys, xml.dom.minidom -def create_equation_tex(filename, equation): +def parse_pkgs(pkgstring): + pkglist = pkgstring.replace(" ","").split(",") + header = "" + for pkg in pkglist: + header += "\\usepackage{%s}\n" % pkg + + return header + +def create_equation_tex(filename, equation, add_header=""): tex = open(filename, 'w') tex.write("""%% processed with eqtexsvg.py \\documentclass{article} \\usepackage{amsmath} \\usepackage{amssymb} \\usepackage{amsfonts} - -\\thispagestyle{empty} +""") + tex.write(add_header) + tex.write("""\\thispagestyle{empty} \\begin{document} """) tex.write(equation) @@ -76,8 +88,12 @@ class EQTEXSVG(inkex.Effect): inkex.Effect.__init__(self) self.OptionParser.add_option("-f", "--formule", action="store", type="string", - dest="formula", default=10.0, + dest="formula", default="", help="LaTeX formula") + self.OptionParser.add_option("-p", "--packages", + action="store", type="string", + dest="packages", default="", + help="Additional packages") def effect(self): base_dir = tempfile.mkdtemp("", "inkscape-"); @@ -102,7 +118,8 @@ class EQTEXSVG(inkex.Effect): os.remove(err_file) os.rmdir(base_dir) - create_equation_tex(latex_file, self.options.formula) + add_header = parse_pkgs(self.options.packages) + create_equation_tex(latex_file, self.options.formula, add_header) os.system('latex "-output-directory=%s" -halt-on-error "%s" > "%s"' \ % (base_dir, latex_file, out_file)) try: -- 2.30.2