From 2909e6450b81eb1c2420674cd12ce58e4b766033 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Tue, 6 Jul 2010 13:50:23 +0000 Subject: [PATCH] Return here unless the doc class is correct. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34783 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/lyx2lyx/lyx_2_0.py | 95 +++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 47 deletions(-) diff --git a/lib/lyx2lyx/lyx_2_0.py b/lib/lyx2lyx/lyx_2_0.py index 6c1d1bda5b..6c1a470dff 100644 --- a/lib/lyx2lyx/lyx_2_0.py +++ b/lib/lyx2lyx/lyx_2_0.py @@ -350,25 +350,24 @@ def revert_layout_command(document, name, LaTeXname, position): i = find_token(document.body, '\\begin_layout ' + name, i) if i == -1: return - else: - k = -1 - # find the next layout - j = i + 1 - while k == -1: - j = find_token(document.body, '\\begin_layout', j) - l = len(document.body) - # if nothing was found it was the last layout of the document - if j == -1: - document.body[l - 4:l - 4] = put_cmd_in_ert("}") - k = 0 - # exclude plain layout because this can be TeX code or another inset - elif document.body[j] != '\\begin_layout Plain Layout': - document.body[j - 2:j - 2] = put_cmd_in_ert("}") - k = 0 - else: - j += 1 - document.body[i] = '\\begin_layout Standard' - document.body[i + 1:i + 1] = put_cmd_in_ert(LaTeXname + "{") + k = -1 + # find the next layout + j = i + 1 + while k == -1: + j = find_token(document.body, '\\begin_layout', j) + l = len(document.body) + # if nothing was found it was the last layout of the document + if j == -1: + document.body[l - 4:l - 4] = put_cmd_in_ert("}") + k = 0 + # exclude plain layout because this can be TeX code or another inset + elif document.body[j] != '\\begin_layout Plain Layout': + document.body[j - 2:j - 2] = put_cmd_in_ert("}") + k = 0 + else: + j += 1 + document.body[i] = '\\begin_layout Standard' + document.body[i + 1:i + 1] = put_cmd_in_ert(LaTeXname + "{") i += 1 @@ -1848,6 +1847,9 @@ def revert_makebox(document): def revert_IEEEtran(document): " Convert IEEEtran layouts and styles to TeX code " + if document.textclass != "IEEEtran": + return + revert_flex_inset(document, "IEEE membership", "\\IEEEmembership", 0) revert_flex_inset(document, "Lowercase", "\\MakeLowercase", 0) revert_layout_command(document, "Special Paper Notice", "\\IEEEspecialpapernotice", 0) @@ -1870,34 +1872,33 @@ def revert_IEEEtran(document): + '\\end_layout\n\n' \ + '\\end_inset\n\n\n' \ + '\\end_layout\n\n' - if document.textclass == "IEEEtran": - # insert a note that title and author must be given in TeX code - document.body.insert(0, note) - # we need to revert title and author to TeX code to set \maketitle correctly - revert_layout_command(document, "Title", "\\title", 0) - revert_layout_command(document, "Author", "\\author", 0) - # write \markboth code to the preamble - insert_to_preamble(0, document, - '% Commands inserted by lyx2lyx\n' - + '% protect \\markboth against an old bug reintroduced in babel >= 3.8g\n' - + '\\let\\oldforeign@language\\foreign@language\n' - + '\\DeclareRobustCommand{\\foreign@language}[1]{%\n' - + ' \\lowercase{\\oldforeign@language{#1}}}\n') - # set maketitle - y = find_token(document.body, '\\begin_layout Abstract', 0) - if y == -1: - document.warning("Malformed LyX document: Can't find abstract of IEEEtran paper.") - else: - maketitle = ['\\begin_layout Standard\n', \ - '\\begin_inset ERT\n', \ - 'status collapsed\n', \ - '\\begin_layout Plain Layout\n', \ - '\\backslash\n', \ - 'maketitle \n', \ - '\\end_layout\n', \ - '\\end_inset\n', \ - '\\end_layout\n'] - document.body[y:y] = maketitle + # insert a note that title and author must be given in TeX code + document.body.insert(0, note) + # we need to revert title and author to TeX code to set \maketitle correctly + revert_layout_command(document, "Title", "\\title", 0) + revert_layout_command(document, "Author", "\\author", 0) + # write \markboth code to the preamble + insert_to_preamble(0, document, + '% Commands inserted by lyx2lyx\n' + + '% protect \\markboth against an old bug reintroduced in babel >= 3.8g\n' + + '\\let\\oldforeign@language\\foreign@language\n' + + '\\DeclareRobustCommand{\\foreign@language}[1]{%\n' + + ' \\lowercase{\\oldforeign@language{#1}}}\n') + # set maketitle + y = find_token(document.body, '\\begin_layout Abstract', 0) + if y == -1: + document.warning("Malformed LyX document: Can't find abstract of IEEEtran paper.") + return + maketitle = ['\\begin_layout Standard\n', \ + '\\begin_inset ERT\n', \ + 'status collapsed\n', \ + '\\begin_layout Plain Layout\n', \ + '\\backslash\n', \ + 'maketitle \n', \ + '\\end_layout\n', \ + '\\end_inset\n', \ + '\\end_layout\n'] + document.body[y:y] = maketitle ## -- 2.39.2