Am Samstag, 28. Juli 2018 16:35:13 CEST schrieb Kornel Benko <kor...@lyx.org>: > Am Samstag, 28. Juli 2018 14:49:35 CEST schrieb Jürgen Spitzmüller > <sp...@lyx.org>: > > Am Samstag, den 28.07.2018, 14:33 +0200 schrieb Kornel Benko: > > > commit 3e92efd118aa66d90cee8e1cd5b305ead0849925 > > > Author: Kornel Benko <kor...@lyx.org> > > > Date: Sat Jul 28 14:30:25 2018 +0200 > > > > > > Replace styles '(Begin|End)Frontmatter' with environment in > > > elsarticle > > > > > > No change in tex or pdf output. > > > This does not help in compiling, but still feels more natural. > > > > This is a file format change. Please add the necessary change and > > lyx2lyx routines. > > > > Jürgen > > > > Will try. >
Attached something which works here. Could you comment please? Kornel
diff --git a/lib/lyx2lyx/lyx_2_4.py b/lib/lyx2lyx/lyx_2_4.py index c00e630..9c23dab 100644 --- a/lib/lyx2lyx/lyx_2_4.py +++ b/lib/lyx2lyx/lyx_2_4.py @@ -47,11 +47,91 @@ from lyx2lyx_tools import (put_cmd_in_ert, add_to_preamble) ### ### Conversion and reversion routines ### ############################################################################### - +def convert_frontmatter(document): + " Convert Style Begin/EndFromatter to Insetlayout" + + i = 0 + while True: + i = find_token(document.body, '\\begin_layout BeginFrontmatter', 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 command inset at line %d" % i) + i += 1 + continue + while i <= j: + del document.body[i] + j -= 1 + document.body.insert(i, '\\begin_layout Standard') + document.body.insert(i + 1, '\\begin_inset Flex Frontmatter') + document.body.insert(i + 2, 'status open') + k = find_token(document.body, '\\begin_layout EndFrontmatter', i+3) + if k == -1: + document.warning("Malformed LyX document: Can't find command inset EndFrontmatter at line %d" % k) + continue + i = k + j = find_end_of_layout(document.body, i) + if j == -1: + document.warning("Malformed LyX document: Can't find end of command inset at line %d" % i) + i += 1 + continue + while i < j: + del document.body[i] + j -= 1 + document.body.insert(i, '\\end_inset') + document.body.insert(i + 1, '') + document.body.insert(i + 2, '') + i += 3 + +def revert_frontmatter(document): + " ..." + + i = 0 + while True: + i = find_token(document.body, '\\begin_inset Flex Frontmatter', i) + if i == -1: + break + e = find_end_of_inset(document.body, i) + if e == -1: + document.warning("Malformed LyX document: Can't find end of command inset at line %d" % i) + break + document.body.insert(e, '\\begin_layout EndFrontmatter') + document.body.insert(e + 1, '\\begin_inset Note Note') + document.body.insert(e + 2, 'status open') + document.body.insert(e + 3, '') + document.body.insert(e + 4, '\\begin_layout Plain Layout') + document.body.insert(e + 5, 'Keep this empty!') + document.body.insert(e + 6, '\\end_layout') + document.body.insert(e + 7, '') + s = find_token(document.body, '\\begin_layout Standard', i-2) + if s == -1: + document.warning("Malformed LyX document: Can't find Standard layout at line %d" % (i-1)) + break + if s != i-1: + document.warning("Malformed LyX document: Standard layout at wrong line %d" % s) + break + del document.body[s] + del document.body[s] + del document.body[s] + document.body.insert(s, '\\begin_layout BeginFrontmatter') + document.body.insert(s + 1, '\\begin_inset Note Note') + document.body.insert(s + 2, 'status open') + document.body.insert(s + 3, '') + document.body.insert(s + 4, '\\begin_layout Plain Layout') + document.body.insert(s + 5, 'Keep this empty!') + document.body.insert(s + 6, '\\end_layout') + document.body.insert(s + 7, '') + document.body.insert(s + 8, '\\end_inset') + document.body.insert(s + 9, '') + document.body.insert(s + 9, '') + document.body.insert(s + 11, '\\end_layout') + i = s + 11 + def convert_lst_literalparam(document): " Add param literal to include inset " i = 0 while True: @@ -552,14 +632,15 @@ convert = [ [551, []], [552, []], [553, []], [554, []], [555, []], - [556, []] + [557, [convert_frontmatter]] ] revert = [ + [556, [revert_frontmatter]], [555, [revert_bibencoding]], [554, [revert_vcolumns]], [553, [revert_stretchcolumn]], [552, [revert_tuftecite]], [551, [revert_floatpclass, revert_floatalignment]],
signature.asc
Description: This is a digitally signed message part.