Code

commit patch for LaTeX equation render extension by Christoph Schmidt-Hieber
authorJohan Engelen <goejendaagh@zonnet.nl>
Sat, 10 Apr 2010 18:59:57 +0000 (20:59 +0200)
committerJohan Engelen <goejendaagh@zonnet.nl>
Sat, 10 Apr 2010 18:59:57 +0000 (20:59 +0200)
po/inkscape.pot
share/extensions/eqtexsvg.inx
share/extensions/eqtexsvg.py

index c88c30501c7a219b72714b1c85ea8fd29e641fe9..5b5857d7a5496366aba87c5baeb52b2afc1e2302 100644 (file)
@@ -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 ""
index e99dfeb1d2faff8433ea209cc32b734c55042104..70516b33f4cd339475b456ebcd78458d7b4cca98 100644 (file)
@@ -8,6 +8,7 @@
        <dependency type="executable" location="path">dvips</dependency>
        <dependency type="executable" location="path">pstoedit</dependency>
        <param name="formule" type="string" _gui-text="LaTeX formula: ">\(\displaystyle\frac{\pi^2}{6}=\lim_{n \to \infty}\sum_{k=1}^n \frac{1}{k^2}\)</param>
+       <param name="packages" type="string" _gui-text="Additional packages (comma-separated): "></param>
     <effect>
                <object-type>all</object-type>
                 <effects-menu>
index 563bf2c4cea5c98be87b5dd6b731f6b1a1bc9064..8e2e70a10336a6dd1ffa64cb6f590c028395c1db 100644 (file)
@@ -9,6 +9,9 @@ This extension need, to work properly:
 
 Copyright (C) 2006 Julien Vitard <julienvitard@gmail.com>
 
+2010-04-04: Added support for custom packages
+            Christoph Schmidt-Hieber <christsc@gmx.de>
+
 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: