Am Sonntag, 29. Juli 2018 17:09:10 CEST schrieb Kornel Benko <kor...@lyx.org>: > Am Sonntag, 29. Juli 2018 12:15:24 CEST schrieb Jürgen Spitzmüller > <sp...@lyx.org>: > > Am Sonntag, den 29.07.2018, 10:26 +0200 schrieb Kornel Benko: > > > I like it. But the existence of Begin/EndFrontmater in the lyx-file > > > is a problem. > > > With the new layout, we can omit it, but the conversion to old > > > (2.3.x) format would miss these styles. > > > > > > Attached the new version. Working without need of additional lyx2lyx > > > conversion. > > > > You need a file format change nevertheless. The lyx2lyx convert routine > > needs to remove existing Begin/EndFrontmatter styles, the revert > > routine needs to insert a BeginFrontmatter before the first and an > > EndFrotmatter after the last InTitle style. > > > > Jürgen > > > > Done. I am testing now, will report later. >
The tests are OK, attached. I have not tested the case, when the InTitle styles are somehow spread across the lyx-file. elsarticle.lyx is reverted to the original from lyx2.3.x Kornel
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 @@ -16,10 +16,12 @@ Provides refstyle 1 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. DefaultFont Family Roman @@ -51,32 +53,16 @@ Input stdlayouts.inc 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 TopSep 0 BottomSep 1 @@ -115,13 +101,13 @@ End Style "Title footnote" Margin Dynamic 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 BottomSep 0.5 Align Left @@ -137,11 +123,11 @@ End 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" EndArgument LatexName author @@ -182,10 +168,11 @@ End Style "Author footnote" CopyStyle "Title footnote" LatexName fntext + InTitle 1 LabelString "Author footnote:" Argument 1 LabelString "Author Footnote Label" Tooltip "Label you refer to for an author" EndArgument @@ -203,20 +190,21 @@ End Style "Corresponding author" CopyStyle "Author footnote" LatexName cortext + InTitle 1 LabelString "Corresponding author text:" End Style Address Margin Static LatexType Command Category FrontMatter LatexName address - InTitle 0 + InTitle 1 Argument 1 LabelString "Address Label" Tooltip "Label of the author you refer to" EndArgument ParSkip 0.4 @@ -230,10 +218,11 @@ End Style Email CopyStyle Address LatexName ead + InTitle 1 AlignPossible Block Argument 1 LabelString "Internet" Tooltip "If content is 'url', email becomes an Internet address" EndArgument @@ -246,11 +235,11 @@ End Style Abstract Margin Static LatexType Environment LatexName abstract Category FrontMatter - InTitle 0 + InTitle 1 NextNoIndent 1 LeftMargin MMM RightMargin MMM ParIndent MM ItemSep 0 @@ -275,11 +264,11 @@ End Style Keywords Margin Dynamic LatexType Environment LatexName keyword Category FrontMatter - InTitle 0 + InTitle 1 NextNoIndent 1 BottomSep 0.5 ParSkip 0.4 Align Block LabelSep xx diff --git a/lib/lyx2lyx/lyx_2_4.py b/lib/lyx2lyx/lyx_2_4.py index c00e630..92aacea 100644 --- a/lib/lyx2lyx/lyx_2_4.py +++ b/lib/lyx2lyx/lyx_2_4.py @@ -47,11 +47,76 @@ from lyx2lyx_tools import (put_cmd_in_ert, add_to_preamble) ### ### Conversion and reversion routines ### ############################################################################### - +def removeFrontMatterStyles(document): + "convert: Remove Style 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): + "revert: Use Styles Begin/EndFrontmatter for elsarticle" + + 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 + document.body[last:last] = ['\\begin_layout EndFrontmatter', + '\\begin_inset Note Note', + 'status open', '', + '\\begin_layout Plain Layout', + 'Keep this empty!', + '\\end_layout', '', + '\\end_inset', '', '', + '\\end_layout'] + document.body[first:first] = ['\\begin_layout BeginFrontmatter', + '\\begin_inset Note Note', + 'status open', '', + '\\begin_layout Plain Layout', + 'Keep this empty!', + '\\end_layout', '', + '\\end_inset', '', '', + '\\end_layout'] + def convert_lst_literalparam(document): " Add param literal to include inset " i = 0 while True: @@ -552,14 +617,15 @@ convert = [ [551, []], [552, []], [553, []], [554, []], [555, []], - [556, []] + [557, [removeFrontMatterStyles]] ] revert = [ + [556, [addFrontMatterStyles]], [555, [revert_bibencoding]], [554, [revert_vcolumns]], [553, [revert_stretchcolumn]], [552, [revert_tuftecite]], [551, [revert_floatpclass, revert_floatalignment]], 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,7 +1,7 @@ -#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 \origin /systemlyxdir/templates/ \textclass elsarticle @@ -18,11 +18,11 @@ theorems-std \end_modules \maintain_unincluded_children false \language english \language_package default \inputencoding auto -\fontencoding auto +\fontencoding global \font_roman "default" "default" \font_sans "default" "default" \font_typewriter "default" "default" \font_math "auto" "auto" \font_default_family default @@ -36,12 +36,10 @@ theorems-std \graphics default \default_output_format default \output_sync 0 \bibtex_command bibtex \index_command default -\float_placement class -\float_alignment class \paperfontsize default \spacing single \use_hyperref false \papersize default \use_geometry false @@ -140,14 +138,23 @@ http://www.ctan.org/get/macros/latex/contrib/elsarticle/elsdoc.pdf \end_inset \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 status open @@ -680,10 +687,18 @@ MSC \end_inset \end_layout +\begin_layout EndFrontmatter +\begin_inset Note Note +status open + +\begin_layout Plain Layout +Keep this empty! +\end_layout + \end_inset \end_layout
signature.asc
Description: This is a digitally signed message part.