commit f8f9eec358c5dcd45665defed13d51c0b304fb8e
Author: Kornel Benko <[email protected]>
Date:   Mon Jul 30 13:44:01 2018 +0200

    Amend 3e92efd: Remove (Begin|End)Frontmatter in elsarticle
    
    1.) Revert changes in elsarticle.lyx
    2.) upgrade format to 558
    3.) added missing lyx2lyx routines
---
 development/FORMAT            |    3 ++
 lib/layouts/elsarticle.layout |   35 +++++++--------------
 lib/lyx2lyx/lyx_2_4.py        |   67 +++++++++++++++++++++++++++++++++++++++-
 lib/templates/elsarticle.lyx  |   29 +++++++++++++----
 4 files changed, 102 insertions(+), 32 deletions(-)

diff --git a/development/FORMAT b/development/FORMAT
index 3c77ed4..2125f43 100644
--- a/development/FORMAT
+++ b/development/FORMAT
@@ -7,6 +7,9 @@ changes happened in particular if possible. A good example 
would be
 
 -----------------------
 
+2018-07-30  Kornel Benko <[email protected]>
+       * format incremented to 558: Remove Begin/EndFrontmatter styles from 
elsarticle layout.
+
 2018-07-29  Jürgen Spitzmüller <[email protected]>
        * format incremented to 557: Separate vcs Info inset from buffer Info 
inset.
 
diff --git a/lib/layouts/elsarticle.layout b/lib/layouts/elsarticle.layout
index d2cef14..943962c 100644
--- a/lib/layouts/elsarticle.layout
+++ b/lib/layouts/elsarticle.layout
@@ -18,6 +18,8 @@ ClassOptions
        FontSize                10|11|12
 end
 
+TitleLatexType Environment
+TitleLatexName frontmatter
 
 # This is just to show how to declare the default font.
 # The defaults are exactly those shown here.
@@ -53,28 +55,12 @@ NoStyle                             Chapter
 NoCounter                      chapter
 NoStyle                                Chapter*
 
-InsetLayout "Flex:Frontmatter"
-       LyXType                 custom
-       LabelString             "Frontmatter"
-       LatexType               Environment
-       LatexName               frontmatter
-       Display                 true
-       Decoration              Classic
-       KeepEmpty               true
-       MultiPar                true
-       ResetsFont              true
-       LabelFont
-         Series                Bold
-         Color                 Green
-       EndFont
-End
-
 Style Title
        Margin                  Static
        LatexType               Command
        LatexName               title
        Category                FrontMatter
-       InTitle                 0
+       InTitle                 1
        ResetArgs               1
        ParSkip                 0.4
        ItemSep                 0
@@ -117,9 +103,9 @@ Style "Title footnote"
        LatexType               Command
        LatexName               tnotetext
        Category                FrontMatter
-       InTitle                 0
+       InTitle                 1
        Argument 1
-         LabelString   "Footnote Label"
+         LabelString           "Footnote Label"
          Tooltip               "Label you refer to in the title"
        EndArgument
        ParSkip                 0.4
@@ -139,7 +125,7 @@ Style Author
        Margin                  Static
        LatexType               Command
        Category                FrontMatter
-       InTitle                 0
+       InTitle                 1
        Argument 1
          LabelString   "Author Label"
          Tooltip               "Label you will reference in the address"
@@ -184,6 +170,7 @@ End
 Style "Author footnote"
        CopyStyle               "Title footnote"
        LatexName               fntext
+       InTitle                 1
        LabelString             "Author footnote:"
        Argument 1
          LabelString   "Author Footnote Label"
@@ -205,6 +192,7 @@ End
 Style "Corresponding author"
        CopyStyle               "Author footnote"
        LatexName               cortext
+       InTitle                 1
        LabelString             "Corresponding author text:"
 End
 
@@ -214,7 +202,7 @@ Style Address
        LatexType               Command
        Category                FrontMatter
        LatexName               address
-       InTitle                 0
+       InTitle                 1
        Argument 1
          LabelString   "Address Label"
          Tooltip               "Label of the author you refer to"
@@ -232,6 +220,7 @@ End
 Style Email
        CopyStyle               Address
        LatexName               ead
+       InTitle                 1
        AlignPossible   Block
        Argument 1
          LabelString   "Internet"
@@ -248,7 +237,7 @@ Style Abstract
        LatexType               Environment
        LatexName               abstract
        Category                FrontMatter
-       InTitle                 0
+       InTitle                 1
        NextNoIndent    1
        LeftMargin              MMM
        RightMargin             MMM
@@ -277,7 +266,7 @@ Style Keywords
        LatexType               Environment
        LatexName               keyword
        Category                FrontMatter
-       InTitle                 0
+       InTitle                 1
        NextNoIndent    1
        BottomSep               0.5
        ParSkip                 0.4
diff --git a/lib/lyx2lyx/lyx_2_4.py b/lib/lyx2lyx/lyx_2_4.py
index 8bf0dc1..58b5ea8 100644
--- a/lib/lyx2lyx/lyx_2_4.py
+++ b/lib/lyx2lyx/lyx_2_4.py
@@ -49,7 +49,68 @@ from lyx2lyx_tools import (put_cmd_in_ert, add_to_preamble)
 ###
 ###############################################################################
 
-  
+def removeFrontMatterStyles(document):
+    " Remove styles Begin/EndFromatter"
+
+    layouts = ['BeginFrontmatter', 'EndFrontmatter']
+    for layout in layouts:
+        i = 0
+        while True:
+            i = find_token(document.body, '\\begin_layout ' + layout, i)
+            if i == -1:
+                break
+            j = find_end_of_layout(document.body, i)
+            if j == -1:
+                document.warning("Malformed LyX document: Can't find end of 
layout at line %d" % i)
+                i += 1
+                continue
+            if document.body[j] == '':
+                j = j + 1
+            del document.body[i:j+1]
+
+def addFrontMatterStyles(document):
+    " Use styles Begin/EndFrontmatter for elsarticle"
+
+    def insertFrontmatter(prefix, line):
+        document.body[line:line] = ['\\begin_layout ' + prefix + 'Frontmatter',
+                                    '\\begin_inset Note Note',
+                                    'status open', '',
+                                    '\\begin_layout Plain Layout',
+                                    'Keep this empty!',
+                                    '\\end_layout', '',
+                                    '\\end_inset', '', '',
+                                    '\\end_layout']
+
+    if document.textclass == "elsarticle":
+        layouts = ['Title', 'Title footnote', 'Author', 'Author footnote',
+                   'Corresponding author', 'Address', 'Email', 'Abstract', 
'Keywords']
+        first = -1
+        last = -1
+        for layout in layouts:
+            i = 0
+            while True:
+                i = find_token(document.body, '\\begin_layout ' + layout, i)
+                if i == -1:
+                    break
+                k = find_end_of_layout(document.body, i)
+                if k == -1:
+                    document.warning("Malformed LyX document: Can't find end 
of layout at line %d" % i)
+                    i += 1;
+                    continue
+                if first == -1 or i < first:
+                    first = i
+                if last == -1 or last <= k:
+                    last = k+1
+                i = k
+        if first == -1:
+            return
+        if first > 0 and document.body[first-1] == '':
+            first -= 1
+        if document.body[last] == '':
+            last = last + 1
+        insertFrontmatter('End', last)
+        insertFrontmatter('Begin', first)
+
 def convert_lst_literalparam(document):
     " Add param literal to include inset "
 
@@ -621,10 +682,12 @@ convert = [
            [554, []],
            [555, []],
            [556, []],
-           [557, [convert_vcsinfo]]
+           [557, [convert_vcsinfo]],
+           [558, [removeFrontMatterStyles]]
           ]
 
 revert =  [
+          [557, [addFrontMatterStyles]],
            [556, [revert_vcsinfo]],
            [555, [revert_bibencoding]],
            [554, [revert_vcolumns]],
diff --git a/lib/templates/elsarticle.lyx b/lib/templates/elsarticle.lyx
index 1b8346e..9887cfd 100644
--- a/lib/templates/elsarticle.lyx
+++ b/lib/templates/elsarticle.lyx
@@ -1,5 +1,5 @@
-#LyX 2.4 created this file. For more info see https://www.lyx.org/
-\lyxformat 556
+#LyX 2.3 created this file. For more info see http://www.lyx.org/
+\lyxformat 544
 \begin_document
 \begin_header
 \save_transient_properties true
@@ -20,7 +20,7 @@ theorems-std
 \language english
 \language_package default
 \inputencoding auto
-\fontencoding auto
+\fontencoding global
 \font_roman "default" "default"
 \font_sans "default" "default"
 \font_typewriter "default" "default"
@@ -38,8 +38,6 @@ theorems-std
 \output_sync 0
 \bibtex_command bibtex
 \index_command default
-\float_placement class
-\float_alignment class
 \paperfontsize default
 \spacing single
 \use_hyperref false
@@ -142,10 +140,19 @@ 
http://www.ctan.org/get/macros/latex/contrib/elsarticle/elsdoc.pdf
 
 \end_layout
 
-\begin_layout Standard
-\begin_inset Flex Frontmatter
+\begin_layout BeginFrontmatter
+\begin_inset Note Note
 status open
 
+\begin_layout Plain Layout
+Keep this empty!
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
 \begin_layout Title
 This is a specimen title
 \begin_inset Flex Titlenotemark
@@ -682,6 +689,14 @@ MSC
 
 \end_layout
 
+\begin_layout EndFrontmatter
+\begin_inset Note Note
+status open
+
+\begin_layout Plain Layout
+Keep this empty!
+\end_layout
+
 \end_inset
 
 

Reply via email to