Jürgen Spitzmüller wrote:
> The script tries to convert my layouts at run-time, but it produces an
> invalid file.
The attached patch fixes the problem.
Jürgen
diff --git a/lib/scripts/layout2layout.py b/lib/scripts/layout2layout.py
index 1248c7f..02a698b 100644
--- a/lib/scripts/layout2layout.py
+++ b/lib/scripts/layout2layout.py
@@ -292,16 +292,18 @@ def convert(lines):
maxcounter = 0
format = 1
formatline = 0
+ declarationline = 0
usemodules = []
flexstyles = []
while i < len(lines):
# Skip comments and empty lines, but not if it's the declaration
# line (we'll deal with it below)
- if (re_Comment.match(lines[i]) or re_Empty.match(lines[i])) \
- and not re_Declaration.match(lines[i]):
- i += 1
- continue
+ if (re_Comment.match(lines[i]) or re_Empty.match(lines[i])):
+ if re_Declaration.match(lines[i]):
+ declarationline = i
+ i += 1
+ continue
# insert file format if not already there
if (only_comment):
@@ -339,20 +341,6 @@ def convert(lines):
i += 1
continue
- if format == 39:
- match = re_ExtractCategory.match(lines[i])
- if match:
- lpre = match.group(1)
- lcat = match.group(2)
- lnam = match.group(3)
- if lcat in ConvDict:
- lcat = ConvDict[lcat]
- lines[i] = lpre + "{" + lnam + "}"
- lines.insert(i+1, "# \\DeclareCategory{" + lcat + "}")
- i += 1
- i += 1
- continue
-
if format == 37 or format == 38:
i += 1
continue
@@ -814,6 +802,17 @@ def convert(lines):
for mod in usemodules:
lines.insert(i, "UseModule " + mod)
i += 1
+
+ if format == 39:
+ match = re_ExtractCategory.match(lines[declarationline])
+ if match:
+ lpre = match.group(1)
+ lcat = match.group(2)
+ lnam = match.group(3)
+ if lcat in ConvDict:
+ lcat = ConvDict[lcat]
+ lines[declarationline] = lpre + "{" + lnam + "}"
+ lines.insert(declarationline + 1, "# \\DeclareCategory{" + lcat + "}")
return format + 1