From 846dd9b99531b724c57a575db75d7282e2005803 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Mon, 31 Dec 2012 13:00:46 +0100 Subject: [PATCH] Introduce new beamer frame layouts The old layouts are still there (marked as deprecated). The new ones are more or less correctly reverted (polishment required), but the old ones not yet converted to the new. Once this is done, a further file format change should be made. --- development/FORMAT | 7 + lib/layouts/article-beamer.layout | 18 ++ lib/layouts/beamer.layout | 331 ++++++++++++++++++--------- lib/layouts/scrarticle-beamer.layout | 18 ++ lib/lyx2lyx/lyx_2_1.py | 195 +++++++++++++++- src/tex2lyx/TODO.txt | 3 + src/version.h | 4 +- 7 files changed, 469 insertions(+), 107 deletions(-) diff --git a/development/FORMAT b/development/FORMAT index e3d16a4037..84d9300928 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -12,6 +12,13 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx. ----------------------- +2012-12-31 Jürgen Spitzmüller + * Format incremented to 459: Introduce new beamer frames: + Frame, PlainFrame, FragileFrame (LaTeX: \begin{frame}, + \begin{frame}[plain], \begin{frame}[fragile]). These will + eventually replace the old BeginFrame, BeginPlainFrame, which + still exist. + 2012-12-30 Jürgen Spitzmüller * Format incremented to 458: Extended caption inset support. Former special caption layouts (e.g. of KOMA) are now proper caption diff --git a/lib/layouts/article-beamer.layout b/lib/layouts/article-beamer.layout index e718213f2c..f98747f0f6 100644 --- a/lib/layouts/article-beamer.layout +++ b/lib/layouts/article-beamer.layout @@ -25,6 +25,24 @@ Preamble } EndPreamble +########################################## +# OBSOLETE STUFF +# Everything below should be removed +# (but this is a file format change) +# +# TODO: +# * conversion of old frame +# and plain frame to new layout +########################################## + +# +# Backwards compatible definitions +# + +AddToPreamble +\providecommand\lyxframeend{} +EndPreamble + # Frame control definition Style BeginFrame # This redefinition is needed to make beamerarticle work diff --git a/lib/layouts/beamer.layout b/lib/layouts/beamer.layout index 60779518a1..c1578a27c9 100644 --- a/lib/layouts/beamer.layout +++ b/lib/layouts/beamer.layout @@ -233,7 +233,7 @@ Style Section Category Sectioning Margin First_Dynamic LatexType Command - LatexName lyxframeend{}\section + LatexName section NeedProtect 1 NextNoIndent 1 LabelSep xx @@ -273,7 +273,7 @@ Style Section* CopyStyle Section Category Unnumbered Margin Static - LatexName lyxframeend{}\section + LatexName section LabelType No_Label ResetArgs 1 Argument 1 @@ -290,7 +290,7 @@ Style Subsection Category Sectioning Margin First_Dynamic LatexType Command - LatexName lyxframeend{}\subsection + LatexName subsection NeedProtect 1 NextNoIndent 1 LabelSep xx @@ -330,7 +330,7 @@ Style Subsection* CopyStyle Subsection Category Unnumbered Margin Static - LatexName lyxframeend{}\subsection + LatexName subsection LabelType No_Label ResetArgs 1 Argument 1 @@ -347,7 +347,7 @@ Style Subsubsection Category Sectioning Margin First_Dynamic LatexType Command - LatexName lyxframeend{}\subsubsection + LatexName subsubsection NeedProtect 1 NextNoIndent 1 LabelSep xx @@ -387,7 +387,7 @@ Style Subsubsection* CopyStyle Subsubsection Category Unnumbered Margin Static - LatexName lyxframeend{}\subsubsection + LatexName subsubsection LabelType No_Label ResetArgs 1 Argument 1 @@ -405,90 +405,88 @@ End # FRAMES # -Style BeginFrame +Style Frame Category Frames + Margin Dynamic + LatexType Environment + LatexName frame + LabelString "Frame" TocLevel 4 KeepEmpty 1 - LatexType Command - LatexName lyxframeend{}\lyxframe - Argument 1 - LabelString "Frame Options" - Tooltip "Frame options (see beamer manual)" - EndArgument - Margin First_Dynamic NextNoIndent 1 - ParSkip 0 - TopSep 2.5 - BottomSep 0.5 - ParSep 0 - Align Center + Align Left LabelType Static - LabelBottomSep 0 - LeftMargin M LabelSep xx - LabelString "Frame" - Font - Series Bold - Size Largest - Color Blue - EndFont - LabelFont + ParSkip 0.5 + TopSep 1 + BottomSep 1 + ParSep 0 + LabelFont + Size largest Family Roman Color latex EndFont - Preamble - \long\def\lyxframe#1{\@lyxframe#1\@lyxframestop}% - \def\@lyxframe{\@ifnextchar<{\@@lyxframe}{\@@lyxframe<*>}}% - \def\@@lyxframe<#1>{\@ifnextchar[{\@@@lyxframe<#1>}{\@@@lyxframe<#1>[]}} - \def\@@@lyxframe<#1>[{\@ifnextchar<{\@@@@@lyxframe<#1>[}{\@@@@lyxframe<#1>[<*>][}} - \def\@@@@@lyxframe<#1>[#2]{\@ifnextchar[{\@@@@lyxframe<#1>[#2]}{\@@@@lyxframe<#1>[#2][]}} - \long\def\@@@@lyxframe<#1>[#2][#3]#4\@lyxframestop#5\lyxframeend{% - \frame<#1>[#2][#3]{\frametitle{#4}#5}} - EndPreamble + Argument 1 + LabelString "Action" + MenuString "Overlay Specifications|S" + Tooltip "Overlay specifications for this frame" + LeftDelim < + RightDelim > + EndArgument + Argument 2 + LabelString "Default Overlay Specifications" + Tooltip "Default overlay specifications within this frame" + LeftDelim [< + RightDelim >] + EndArgument + Argument 3 + MenuString "Frame Options" + LabelString "Options" + Tooltip "Frame options (see beamer manual)" + EndArgument + Argument 4 + LabelString "Frame Title" + Tooltip "Enter the block title here" + LeftDelim { + RightDelim } + Decoration conglomerate + Font + Color blue + Size largest + EndFont + AutoInsert 1 + EndArgument End -Style BeginPlainFrame - Category Frames - TocLevel 4 - KeepEmpty 1 - LatexType Command - LatexName lyxframeend{}\lyxplainframe - Margin First_Dynamic - NextNoIndent 1 - ParSkip 0 - TopSep 2.5 - BottomSep 0.5 - ParSep 0 - Align Center - LabelType Static - LabelBottomSep 0 - LeftMargin M - LabelSep xx - LabelString "Frame (no head/foot/sidebars)" - Font - Series Bold - Size Largest - Color Blue - EndFont - LabelFont - Family Roman - Color latex - EndFont - Preamble - \long\def\lyxplainframe#1{\@lyxplainframe#1\@lyxframestop}% - \def\@lyxplainframe{\@ifnextchar<{\@@lyxplainframe}{\@@lyxplainframe<*>}}% - \long\def\@@lyxplainframe<#1>#2\@lyxframestop#3\lyxframeend{% - \frame<#1>[plain]{\frametitle{#2}#3}} - EndPreamble +Style PlainFrame + CopyStyle Frame + LabelString "Frame (plain)" + Argument 3 + MenuString "Frame Options" + LabelString "Options" + Tooltip "Frame options (see beamer manual)" + PresetArg "plain" + EndArgument +End + +Style FragileFrame + CopyStyle Frame + LabelString "Frame (fragile)" + Argument 3 + MenuString "Frame Options" + LabelString "Options" + Tooltip "Frame options (see beamer manual)" + PresetArg "fragile" + EndArgument End Style AgainFrame Category Frames KeepEmpty 0 LatexType Command - LatexName lyxframeend{}\againframe + LatexName againframe Argument 1 - LabelString "On Slide" + LabelString "Slide" MenuString "Overlay Specifications|S" Tooltip "Overlay specifications for this frame" LeftDelim < @@ -511,7 +509,6 @@ Style AgainFrame TopSep 3 BottomSep 3 ParSep 0 - Align Center LabelType Static LabelBottomSep 0 LeftMargin M @@ -523,37 +520,10 @@ Style AgainFrame LabelFont Family Roman Color latex - Series Bold Size Largest EndFont End -Style EndFrame - Category Frames - KeepEmpty 1 - LatexType Command - LatexName lyxframeend - Margin First_Dynamic - ParSkip 0 - TopSep 0 - BottomSep 3 - ParSep 0 - Align Center - LabelType Static - LabelBottomSep 0 - LeftMargin MMMMM - LabelString "________________________________" - LabelFont - Family typewriter - Series Medium - Size Normal - Color latex - EndFont - Preamble - \def\lyxframeend{} % In case there is a superfluous frame end - EndPreamble -End - Style FrameTitle Category Frames Margin Static @@ -564,10 +534,9 @@ Style FrameTitle TopSep 0 BottomSep 1 ParSep 1 - Align Center + Align Block LabelType No_Label Font - Series Bold Color Blue Size Largest EndFont @@ -594,10 +563,9 @@ Style FrameSubtitle TopSep 0 BottomSep 1 ParSep 1 - Align Center + Align Block LabelType No_Label Font - Series Bold Color Blue EndFont Argument 1 @@ -1593,3 +1561,158 @@ End Input theorems-refprefix.inc + + +########################################## +# OBSOLETE STUFF +# Everything below should be removed +# (but this is a file format change) +# +# TODO: +# * conversion of old frame +# and plain frame to new layout +########################################## + +# +# Backwards compatible definitions +# + +AddToPreamble +\providecommand\lyxframeend{} +EndPreamble + +IfStyle Section + LatexName lyxframeend{}\section +End + +IfStyle Section* + LatexName lyxframeend{}\section +End + +IfStyle Subsection + LatexName lyxframeend{}\subsection +End + +IfStyle Subsection* + LatexName lyxframeend{}\subsection +End + +IfStyle Subsubsection + LatexName lyxframeend{}\subsubsection +End + +IfStyle Subsubsection* + LatexName lyxframeend{}\subsubsection +End + +IfStyle AgainFrame + LatexName lyxframeend{}\againframe +End + + +# +# Deprecated Styles +# + +Style BeginFrame + Category "Deprecated Styles" + TocLevel 4 + KeepEmpty 1 + LatexType Command + LatexName lyxframeend{}\lyxframe + Argument 1 + LabelString "Frame Options" + Tooltip "Frame options (see beamer manual)" + EndArgument + Margin First_Dynamic + NextNoIndent 1 + ParSkip 0 + TopSep 2.5 + BottomSep 0.5 + ParSep 0 + Align Center + LabelType Static + LabelBottomSep 0 + LeftMargin M + LabelSep xx + LabelString "Frame" + Font + Series Bold + Size Largest + Color Blue + EndFont + LabelFont + Family Roman + Color latex + EndFont + Preamble + \long\def\lyxframe#1{\@lyxframe#1\@lyxframestop}% + \def\@lyxframe{\@ifnextchar<{\@@lyxframe}{\@@lyxframe<*>}}% + \def\@@lyxframe<#1>{\@ifnextchar[{\@@@lyxframe<#1>}{\@@@lyxframe<#1>[]}} + \def\@@@lyxframe<#1>[{\@ifnextchar<{\@@@@@lyxframe<#1>[}{\@@@@lyxframe<#1>[<*>][}} + \def\@@@@@lyxframe<#1>[#2]{\@ifnextchar[{\@@@@lyxframe<#1>[#2]}{\@@@@lyxframe<#1>[#2][]}} + \long\def\@@@@lyxframe<#1>[#2][#3]#4\@lyxframestop#5\lyxframeend{% + \frame<#1>[#2][#3]{\frametitle{#4}#5}} + EndPreamble +End + +Style BeginPlainFrame + Category "Deprecated Styles" + TocLevel 4 + KeepEmpty 1 + LatexType Command + LatexName lyxframeend{}\lyxplainframe + Margin First_Dynamic + NextNoIndent 1 + ParSkip 0 + TopSep 2.5 + BottomSep 0.5 + ParSep 0 + Align Center + LabelType Static + LabelBottomSep 0 + LeftMargin M + LabelSep xx + LabelString "Frame (no head/foot/sidebars)" + Font + Series Bold + Size Largest + Color Blue + EndFont + LabelFont + Family Roman + Color latex + EndFont + Preamble + \long\def\lyxplainframe#1{\@lyxplainframe#1\@lyxframestop}% + \def\@lyxplainframe{\@ifnextchar<{\@@lyxplainframe}{\@@lyxplainframe<*>}}% + \long\def\@@lyxplainframe<#1>#2\@lyxframestop#3\lyxframeend{% + \frame<#1>[plain]{\frametitle{#2}#3}} + EndPreamble +End + +Style EndFrame + Category "Deprecated Styles" + KeepEmpty 1 + LatexType Command + LatexName lyxframeend + Margin First_Dynamic + ParSkip 0 + TopSep 0 + BottomSep 3 + ParSep 0 + Align Center + LabelType Static + LabelBottomSep 0 + LeftMargin MMMMM + LabelString "________________________________" + LabelFont + Family typewriter + Series Medium + Size Normal + Color latex + EndFont + Preamble + \def\lyxframeend{} % In case there is a superfluous frame end + EndPreamble +End diff --git a/lib/layouts/scrarticle-beamer.layout b/lib/layouts/scrarticle-beamer.layout index b8f4959614..414fa59fbf 100644 --- a/lib/layouts/scrarticle-beamer.layout +++ b/lib/layouts/scrarticle-beamer.layout @@ -25,6 +25,24 @@ Preamble } EndPreamble +########################################## +# OBSOLETE STUFF +# Everything below should be removed +# (but this is a file format change) +# +# TODO: +# * conversion of old frame +# and plain frame to new layout +########################################## + +# +# Backwards compatible definitions +# + +AddToPreamble +\providecommand\lyxframeend{} +EndPreamble + # Frame control definition Style BeginFrame # This redefinition is needed to make beamerarticle work diff --git a/lib/lyx2lyx/lyx_2_1.py b/lib/lyx2lyx/lyx_2_1.py index 9e063457bc..917e2f424f 100644 --- a/lib/lyx2lyx/lyx_2_1.py +++ b/lib/lyx2lyx/lyx_2_1.py @@ -3165,6 +3165,197 @@ def revert_captionlayouts(document): i = i + 1 +def revert_fragileframe(document): + " Reverts beamer FragileFrame layout to ERT " + + beamer_classes = ["beamer", "article-beamer", "scrarticle-beamer"] + if document.textclass not in beamer_classes: + return + + i = 0 + while True: + i = find_token(document.body, "\\begin_layout FragileFrame", i) + if i == -1: + return + # Find end of sequence + j = find_end_of_sequence(document.body, i) + if j == -1: + document.warning("Malformed lyx document. Cannot find end of FragileFrame sequence!") + i = i + 1 + continue + endseq = j + subst = ["\\begin_layout Standard"] + put_cmd_in_ert("\\begin{frame}") + esubst = ["\\end_layout", "", "\\begin_layout Standard"] + put_cmd_in_ert("\\end{frame}") + endseq = endseq + len(esubst) - len(document.body[j : j]) + if document.body[j] == "\\end_deeper": + document.body[j : j] = ["\\end_deeper", ""] + esubst + else: + document.body[j : j] = esubst + for q in range(i, j): + if document.body[q] == "\\begin_layout FragileFrame": + document.body[q] = "\\begin_layout %s" % document.default_layout + r = i + while r < j: + if document.body[r] == "\\begin_deeper": + s = find_end_of(document.body, r, "\\begin_deeper", "\\end_deeper") + if s != -1: + document.body[r] = "" + document.body[s] = "" + r = s + continue + r = r + 1 + for p in range(1, 5): + arg = find_token(document.body, "\\begin_inset Argument %d" % p, i, j) + if arg != -1: + if p == 1: + beginPlain = find_token(document.body, "\\begin_layout Plain Layout", arg) + endPlain = find_end_of_layout(document.body, beginPlain) + endInset = find_end_of_inset(document.body, arg) + content = document.body[beginPlain + 1 : endPlain] + # Adjust range end + j = j - len(document.body[arg : endInset + 1]) + # Remove arg inset + del document.body[arg : endInset + 1] + subst += put_cmd_in_ert("<") + content + put_cmd_in_ert(">") + elif p == 2: + beginPlain = find_token(document.body, "\\begin_layout Plain Layout", arg) + endPlain = find_end_of_layout(document.body, beginPlain) + endInset = find_end_of_inset(document.body, arg) + content = document.body[beginPlain + 1 : endPlain] + # Adjust range end + j = j - len(document.body[arg : endInset + 1]) + # Remove arg inset + del document.body[arg : endInset + 1] + subst += put_cmd_in_ert("[<") + content + put_cmd_in_ert(">]") + elif p == 3: + beginPlain = find_token(document.body, "\\begin_layout Plain Layout", arg) + endPlain = find_end_of_layout(document.body, beginPlain) + endInset = find_end_of_inset(document.body, arg) + content = document.body[beginPlain + 1 : endPlain] + # Adjust range end + j = j - len(document.body[arg : endInset + 1]) + # Remove arg inset + del document.body[arg : endInset + 1] + subst += put_cmd_in_ert("[fragile,") + content + put_cmd_in_ert("]") + elif p == 4: + beginPlain = find_token(document.body, "\\begin_layout Plain Layout", arg) + endPlain = find_end_of_layout(document.body, beginPlain) + endInset = find_end_of_inset(document.body, arg) + content = document.body[beginPlain + 1 : endPlain] + # Adjust range end + j = j - len(document.body[arg : endInset + 1]) + # Remove arg inset + del document.body[arg : endInset + 1] + subst += put_cmd_in_ert("{") + content + put_cmd_in_ert("}") + elif p == 3: + subst += put_cmd_in_ert("[fragile]") + + document.body[i : i + 1] = subst + i = j + + +def revert_newframes(document): + " Reverts beamer Frame and PlainFrame layouts to old forms " + + beamer_classes = ["beamer", "article-beamer", "scrarticle-beamer"] + if document.textclass not in beamer_classes: + return + + frame_dict = { + "Frame" : "BeginFrame", + "PlainFrame" : "BeginPlainFrame", + } + + rx = re.compile(r'^\\begin_layout (\S+)$') + i = 0 + while True: + i = find_token(document.body, "\\begin_layout", i) + if i == -1: + return + + m = rx.match(document.body[i]) + val = "" + if m: + val = m.group(1) + if val not in frame_dict.keys(): + i = i + 1 + continue + # Find end of sequence + j = find_end_of_sequence(document.body, i) + if j == -1: + document.warning("Malformed lyx document. Cannot find end of Frame sequence!") + i = i + 1 + continue + endseq = j + subst = ["\\begin_layout %s" % frame_dict[val]] + esubst = ["\\end_layout", "", "\\begin_layout EndFrame", "", "\\end_layout"] + endseq = endseq + len(esubst) - len(document.body[j : j]) + if document.body[j] == "\\end_deeper": + document.body[j : j] = ["\\end_deeper", ""] + esubst + else: + document.body[j : j] = esubst + for q in range(i, j): + if document.body[q] == "\\begin_layout %s" % val: + document.body[q] = "\\begin_layout %s" % document.default_layout + r = i + while r < j: + if document.body[r] == "\\begin_deeper": + s = find_end_of(document.body, r, "\\begin_deeper", "\\end_deeper") + if s != -1: + document.body[r] = "" + document.body[s] = "" + r = s + continue + r = r + 1 + l = find_end_of_layout(document.body, i) + for p in range(1, 5): + arg = find_token(document.body, "\\begin_inset Argument %d" % p, i, l) + if arg != -1: + if p == 1: + beginPlain = find_token(document.body, "\\begin_layout Plain Layout", arg) + endPlain = find_end_of_layout(document.body, beginPlain) + endInset = find_end_of_inset(document.body, arg) + content = document.body[beginPlain + 1 : endPlain] + # Adjust range end + l = l - len(document.body[arg : endInset + 1]) + # Remove arg inset + del document.body[arg : endInset + 1] + subst += put_cmd_in_ert("<") + content + put_cmd_in_ert(">") + elif p == 2: + beginPlain = find_token(document.body, "\\begin_layout Plain Layout", arg) + endPlain = find_end_of_layout(document.body, beginPlain) + endInset = find_end_of_inset(document.body, arg) + content = document.body[beginPlain + 1 : endPlain] + # Adjust range end + l = l - len(document.body[arg : endInset + 1]) + # Remove arg inset + del document.body[arg : endInset + 1] + subst += put_cmd_in_ert("[<") + content + put_cmd_in_ert(">]") + elif p == 3: + beginPlain = find_token(document.body, "\\begin_layout Plain Layout", arg) + endPlain = find_end_of_layout(document.body, beginPlain) + endInset = find_end_of_inset(document.body, arg) + content = document.body[beginPlain + 1 : endPlain] + # Adjust range end + l = l - len(document.body[arg : endInset + 1]) + # Remove arg inset + del document.body[arg : endInset + 1] + subst += put_cmd_in_ert("[") + content + put_cmd_in_ert("]") + elif p == 4: + beginPlain = find_token(document.body, "\\begin_layout Plain Layout", arg) + endPlain = find_end_of_layout(document.body, beginPlain) + endInset = find_end_of_inset(document.body, arg) + content = document.body[beginPlain + 1 : endPlain] + # Adjust range end + l = l - len(document.body[arg : endInset + 1]) + # Remove arg inset + del document.body[arg : endInset + 1] + subst += content + + document.body[i : i + 1] = subst + i = j + + ## # Conversion hub # @@ -3215,10 +3406,12 @@ convert = [ [455, []], [456, [convert_epigraph]], [457, [convert_use_stackrel]], - [458, [convert_captioninsets, convert_captionlayouts]] + [458, [convert_captioninsets, convert_captionlayouts]], + [459, []] ] revert = [ + [458, [revert_fragileframe, revert_newframes]], [457, [revert_captioninsets, revert_captionlayouts]], [456, [revert_use_stackrel]], [455, [revert_epigraph]], diff --git a/src/tex2lyx/TODO.txt b/src/tex2lyx/TODO.txt index 61a7346c06..9a8459eadf 100644 --- a/src/tex2lyx/TODO.txt +++ b/src/tex2lyx/TODO.txt @@ -98,6 +98,9 @@ Format LaTeX feature LyX feature 456 memoir: \epigraph{text}{source} layout Epigraph, InsetArgument 457 automatic stackrel loading \use_package stackrel 458 Extended InsetCaption syntax InsetCaption +459 beamer: \begin{frame}, \begin_layout Frame + \begin{frame}[plain], \begin_layout PlainFrame + \begin{frame}[fragile] \begin_layout FragileFrame General diff --git a/src/version.h b/src/version.h index 07e2980ab3..5d75b100a3 100644 --- a/src/version.h +++ b/src/version.h @@ -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 458 // spitz: extended caption inset -#define LYX_FORMAT_TEX2LYX 458 // spitz: extended caption inset +#define LYX_FORMAT_LYX 459 // spitz: new beamer frame layouts +#define LYX_FORMAT_TEX2LYX 459 // spitz: new beamer frame layouts #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX #ifndef _MSC_VER