Am Mittwoch, 29. April 2015 um 12:33:00, schrieb Enrico Forestieri 
<for...@lyx.org>
> lib/scripts/lyxpreview2bitmap.py b/lib/scripts/lyxpreview2bitmap.py

What was wrong with my patch?

I posted it on the bug tracker

        Kornel

Attachment: signature.asc
Description: This is a digitally signed message part.

diff --git a/lib/scripts/lyxpreview2bitmap.py b/lib/scripts/lyxpreview2bitmap.py
index b387529..7db197a 100755
--- a/lib/scripts/lyxpreview2bitmap.py
+++ b/lib/scripts/lyxpreview2bitmap.py
@@ -159,11 +159,22 @@ def extract_metrics_info(dvipng_stdout):
 
 def fix_latex_file(latex_file):
     documentclass_re = re.compile("(\\\\documentclass\[)(1[012]pt,?)(.+)")
+    macrodef_re = re.compile("\\\\newcommandx\\\\([a-zA-Z]+)(.+)")
 
     tmp = mkstemp()
+    macros = {}
 
     changed = 0
     for line in open(latex_file, 'r').readlines():
+        match = macrodef_re.match(line)
+        if match != None:
+            if macros.get(match.group(1), False):
+                tmp.write("\\renewcommandx\\%s%s\n" % (match.group(1),match.group(2)))
+                changed = 1
+            else:
+                macros[match.group(1)] = True
+                tmp.write(line)
+            continue
         match = documentclass_re.match(line)
         if match == None:
             tmp.write(line)

Reply via email to