The attached patch is the outcome of a discussion with Jean-Marc at
http://bugzilla.lyx.org/show_bug.cgi?id=2355. The problem is that I did 
not realize that TocLevel was a new keyword when I wrote layout2layout.

This patch adds this keyword for sectioning styles. Comments?


Georg
Index: lib/scripts/layout2layout.py
===================================================================
--- lib/scripts/layout2layout.py	(Revision 13467)
+++ lib/scripts/layout2layout.py	(Arbeitskopie)
@@ -60,7 +60,7 @@ def convert(lines):
     re_Format = re.compile(r'^(\s*)(Format)(\s+)(\S+)', re.IGNORECASE)
     re_Preamble = re.compile(r'^(\s*)Preamble', re.IGNORECASE)
     re_EndPreamble = re.compile(r'^(\s*)EndPreamble', re.IGNORECASE)
-    re_MaxCounter = re.compile(r'^\s*MaxCounter', re.IGNORECASE)
+    re_MaxCounter = re.compile(r'^(\s*)(MaxCounter)(\s+)(\S+)', re.IGNORECASE)
     re_LabelType = re.compile(r'^(\s*)(LabelType)(\s+)(\S+)', re.IGNORECASE)
     re_LatexType = re.compile(r'^(\s*)(LatexType)(\s+)(\S+)', re.IGNORECASE)
     re_Style = re.compile(r'^(\s*)(Style)(\s+)(\S+)', re.IGNORECASE)
@@ -72,6 +72,7 @@ def convert(lines):
     space1 = ""
     latextype_line = -1
     style = ""
+    maxcounter = 0
     while i < len(lines):
 
         # Skip comments and empty lines
@@ -101,7 +102,27 @@ def convert(lines):
             continue
 
         # Delete MaxCounter
-        if re_MaxCounter.match(lines[i]):
+        match = re_MaxCounter.match(lines[i])
+        if match:
+            level = match.group(4)
+            if string.lower(level) == "counter_chapter":
+                maxcounter = 0
+            elif string.lower(level) == "counter_section":
+                maxcounter = 1
+            elif string.lower(level) == "counter_subsection":
+                maxcounter = 2
+            elif string.lower(level) == "counter_subsubsection":
+                maxcounter = 3
+            elif string.lower(level) == "counter_paragraph":
+                maxcounter = 4
+            elif string.lower(level) == "counter_subparagraph":
+                maxcounter = 5
+            elif string.lower(level) == "counter_enumi":
+                maxcounter = 6
+            elif string.lower(level) == "counter_enumii":
+                maxcounter = 7
+            elif string.lower(level) == "counter_enumiii":
+                maxcounter = 8
             del lines[i]
             continue
 
@@ -126,6 +147,8 @@ def convert(lines):
 
         # Add a line "LatexType Bib_Environment" if LabelType is Bibliography
         # (or change the existing LatexType)
+        #
+        # Add the TocLevel setting for sectioning styles
         match = re_LatexType.match(lines[i])
         if match:
             latextype_line = i
@@ -135,12 +158,32 @@ def convert(lines):
             label = ""
             space1 = ""
             latextype_line = -1
-        if re_End.match(lines[i]) and string.lower(label) == "bibliography":
-            if (latextype_line < 0):
-                lines.insert(i, "%sLatexType Bib_Environment" % space1)
+        if re_End.match(lines[i]):
+            if string.lower(label) == "bibliography":
+                if (latextype_line < 0):
+                    lines.insert(i, "%sLatexType Bib_Environment" % space1)
+                    i = i + 1
+                else:
+                    lines[latextype_line] = re_LatexType.sub(r'\1\2\3Bib_Environment', lines[latextype_line])
+            if (maxcounter == 0 and
+                (string.lower(style) == "chapter" or string.lower(style) == "part")):
+                lines.insert(i, "%sTocLevel 0" % space1)
+                i = i + 1
+            elif maxcounter <= 1 and string.lower(style) == "section":
+                lines.insert(i, "%sTocLevel 1" % space1)
+                i = i + 1
+            elif maxcounter <= 2 and string.lower(style) == "subsection":
+                lines.insert(i, "%sTocLevel 2" % space1)
+                i = i + 1
+            elif maxcounter <= 3 and string.lower(style) == "subsubsection":
+                lines.insert(i, "%sTocLevel 3" % space1)
+                i = i + 1
+            elif maxcounter <= 4 and string.lower(style) == "paragraph":
+                lines.insert(i, "%sTocLevel 4" % space1)
+                i = i + 1
+            elif maxcounter <= 5 and string.lower(style) == "subparagraph":
+                lines.insert(i, "%sTocLevel 5" % space1)
                 i = i + 1
-            else:
-                lines[latextype_line] = re_LatexType.sub(r'\1\2\3Bib_Environment', lines[latextype_line])
 
         i = i + 1
 

Reply via email to