]> git.lyx.org Git - features.git/commitdiff
Proper support for memoir epigraph (bug #8151)
authorJuergen Spitzmueller <spitz@lyx.org>
Fri, 28 Dec 2012 11:32:59 +0000 (12:32 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Fri, 28 Dec 2012 11:32:59 +0000 (12:32 +0100)
development/FORMAT
lib/layouts/memoir.layout
lib/lyx2lyx/lyx_2_1.py
src/tex2lyx/TODO.txt
src/version.h

index 1f8d9e158729bf1e48f4de03e7a45adb47808473..033e9be83b22cbf39abefb55c85db19179cfc17c 100644 (file)
@@ -11,6 +11,11 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx.
 
 -----------------------
 
+2012-12-28 Jürgen Spitzmüller <spitz@lyx.org>
+       * Format incremented to 456: Proper support for memoir \epigraph
+         \epigraph{text}{source} > begin_layout Epigraph, <source> as
+         InsetArgument post:1
+
 2012-12-22 Jürgen Spitzmüller <spitz@lyx.org>
        * Format incremented to 455: Support for beamer \frametitle
          \frametitle<overlay>[short]{title} > begin_layout FrameTitle
index 24de4e5ac2b9871a731a32f923099ff33e1e58f2..4e0a3fdf48e961e95462e9a84510f65da81241df 100644 (file)
@@ -171,7 +171,6 @@ Style Chapterprecis
        EndFont
 End
 
-#FIXME: this takes two parameters!!!
 Style Epigraph
        Category              Maintext
        Margin                Right_Address_Box
@@ -181,6 +180,12 @@ Style Epigraph
        BottomSep             1.5
        ParSep                1.5
        Align                 Left
+       Argument post:1
+               MenuString    "Epigraph Source|S"
+               LabelString   "Source"
+               Tooltip       "The source/author of ths epigraph"
+               Mandatory     1
+       EndArgument
 End
 
 Style Poemtitle
index 684f5c83b09ad21059c23c946e73ca45d580c490..3ee673f02ee258a6ce6ad3216537da54d2cd145f 100644 (file)
@@ -2897,6 +2897,82 @@ def revert_frametitle(document):
         i = endlay
 
 
+def convert_epigraph(document):
+    " Converts memoir epigraph to new syntax "
+    
+    if document.textclass != "memoir":
+        return
+
+    i = 0
+    while True:
+        i = find_token(document.body, "\\begin_layout Epigraph", i)
+        if i == -1:
+            return
+        j = find_end_of_layout(document.body, i)
+        if j == -1:
+            document.warning("Malformed lyx document: Can't find end of Epigraph layout")
+            i = i + 1
+            continue
+        endlay = j
+        subst = list()
+        ert = find_token(document.body, "\\begin_inset ERT", i, j)
+        if ert != -1:
+            endInset = find_end_of_inset(document.body, ert)
+            beginPlain = find_token(document.body, "\\begin_layout Plain Layout", ert)
+            endPlain = find_end_of_layout(document.body, beginPlain)
+            ertcont = beginPlain + 2
+            if document.body[ertcont] == "}{":
+                # strip off the <
+                # Convert to ArgInset
+                endlay = endlay - 2 * len(document.body[j])
+                begsubst = ['\\begin_inset Argument post:1', 'status collapsed', '',
+                            '\\begin_layout Plain Layout']
+                endsubst = ['\\end_layout', '', '\\end_inset', '', document.body[j]]
+                document.body[j : j] = endsubst
+                document.body[endInset + 1 : endInset + 1] = begsubst
+                # Adjust range end
+                endlay += len(begsubst) + len(endsubst)
+                endlay = endlay - len(document.body[ert : endInset + 1])
+                del document.body[ert : endInset + 1]
+                    
+        i = endlay
+
+
+def revert_epigraph(document):
+    " Reverts memoir epigraph argument to ERT "
+    
+    if document.textclass != "memoir":
+        return
+
+    i = 0
+    while True:
+        i = find_token(document.body, "\\begin_layout Epigraph", i)
+        if i == -1:
+            return
+        j = find_end_of_layout(document.body, i)
+        if j == -1:
+            document.warning("Malformed lyx document: Can't find end of Epigraph layout")
+            i = i + 1
+            continue
+        endlay = j
+        subst = list()
+        p = find_token(document.body, "\\begin_layout Argument post:1", i, j)
+        if p != -1:
+            beginPlain = find_token(document.body, "\\begin_layout Plain Layout", p)
+            endPlain = find_end_of_layout(document.body, beginPlain)
+            endInset = find_end_of_inset(document.body, p)
+            content = document.body[beginPlain + 1 : endPlain]
+            # Adjust range end
+            endlay = endlay - len(document.body[p : endInset + 1])
+            # Remove arg inset
+            del document.body[p : endInset + 1]
+            subst += put_cmd_in_ert("}{") + content
+        else:
+            subst += put_cmd_in_ert("}{")
+                    
+        document.body[j : j] = subst + document.body[j : j]
+        i = endlay
+
 
 ##
 # Conversion hub
@@ -2945,10 +3021,12 @@ convert = [
            [452, [convert_beamerblocks]],
            [453, [convert_use_stmaryrd]],
            [454, [convert_overprint]],
-           [455, []]
+           [455, []],
+           [456, [convert_epigraph]]
           ]
 
 revert =  [
+           [455, [revert_epigraph]],
            [454, [revert_frametitle]],
            [453, [revert_overprint]],
            [452, [revert_use_stmaryrd]],
index fec204a8ee132e7d5ee3a5f1e8327ee362c1742a..f2ae0efd7ee97f88de79d763afec8d48630cde14 100644 (file)
@@ -96,6 +96,7 @@ Format LaTeX feature                        LyX feature
        \end{overprint}
 455    beamer frametitle command            \begin_layout FrameTitle
        \frametitle<overlay>[short}{long}
+456    memoir: \epigraph{text}{source}      layout Epigraph, InsetArgument
 
 
 General
index 255c47e62352a44c8de1fc14d78e5658fc28d795..5cab79e8d58abc0b3ed4782e2ce263cb6de2e8cc 100644 (file)
@@ -30,8 +30,8 @@ extern char const * const lyx_version_info;
 
 // Do not remove the comment below, so we get merge conflict in
 // independent branches. Instead add your own.
-#define LYX_FORMAT_LYX 455 // spitz: support for beamer FrameTitle layout
-#define LYX_FORMAT_TEX2LYX 455 // spitz: support for beamer FrameTitle layout
+#define LYX_FORMAT_LYX 456 // spitz: proper support for memoir epigraph
+#define LYX_FORMAT_TEX2LYX 456 // spitz: proper support for memoir epigraph
 
 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
 #ifndef _MSC_VER