mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 10:58:52 +00:00
Proper support for beamer overprint environment
This has a list-like structure (with \onslide item commands). The previous implementation was rather useless, since it required lots of ERT. Since the new implementation is so different, we use ERT for conersion/reversion. The lyx2lyx routines are not yet perfect, though.
This commit is contained in:
parent
c3aa718151
commit
4f36061811
@ -11,6 +11,14 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx.
|
||||
|
||||
-----------------------
|
||||
|
||||
2012-12-19 Jürgen Spitzmüller <spitz@lyx.org>
|
||||
* Format incremented to 454:
|
||||
Real support for beamer overprint environment. This environment has a
|
||||
list structure (with \onslide item commands). Previously, we just output
|
||||
the begin/end tags, which was rather useless. Since the syntax is so
|
||||
different, the old overprint layouts are converted to ERT, likewise the
|
||||
reversion is to ERT.
|
||||
|
||||
2012-12-15 Georg Baum <Georg.Baum@post.rwth-aachen.de>
|
||||
* Format incremented to 453
|
||||
support for the LaTeX-package stmaryrd (fix bug 8434)
|
||||
|
@ -688,29 +688,32 @@ End
|
||||
|
||||
Style Overprint
|
||||
Category Overlays
|
||||
Margin First_Dynamic
|
||||
LatexType Environment
|
||||
NextNoIndent 0
|
||||
ParIndent MM
|
||||
Align Left
|
||||
LabelType Static
|
||||
LabelSep xx
|
||||
Margin Static
|
||||
LatexType Item_Environment
|
||||
LatexName overprint
|
||||
LabelString "Overprint"
|
||||
ParSkip 0.5
|
||||
TopSep 1
|
||||
BottomSep 1
|
||||
ParSep 0
|
||||
KeepEmpty 1
|
||||
LabelFont
|
||||
Family Roman
|
||||
Color latex
|
||||
EndFont
|
||||
ItemCommand onslide
|
||||
Argument 1
|
||||
MenuString "Overprint Area Width"
|
||||
LabelString "Width"
|
||||
Tooltip "The width of the overprint area (default: text width)"
|
||||
EndArgument
|
||||
Argument item:1
|
||||
MenuString "Item Overlay Specifications"
|
||||
LabelString "On Slide"
|
||||
Tooltip "Overlay specifications for this item"
|
||||
LeftDelim <
|
||||
RightDelim >
|
||||
AutoInsert 1
|
||||
EndArgument
|
||||
NextNoIndent 1
|
||||
LeftMargin MMN
|
||||
LabelSep xx
|
||||
ItemSep 0.2
|
||||
TopSep 0.7
|
||||
BottomSep 0.7
|
||||
ParSep 0.3
|
||||
Align Left
|
||||
LabelType Itemize
|
||||
End
|
||||
|
||||
Style OverlayArea
|
||||
@ -1348,7 +1351,6 @@ InsetLayout Flex:Alert
|
||||
Tooltip "Specify the overlay settings (see beamer manual)"
|
||||
LeftDelim <
|
||||
RightDelim >
|
||||
AutoInsert 1
|
||||
EndArgument
|
||||
End
|
||||
|
||||
@ -1420,6 +1422,7 @@ InsetLayout Flex:Visible
|
||||
Tooltip "Specify the overlay settings (see beamer manual)"
|
||||
LeftDelim <
|
||||
RightDelim >
|
||||
AutoInsert 1
|
||||
EndArgument
|
||||
End
|
||||
|
||||
|
@ -26,8 +26,9 @@ import sys, os
|
||||
# Uncomment only what you need to import, please.
|
||||
|
||||
from parser_tools import count_pars_in_inset, del_token, find_token, find_token_exact, \
|
||||
find_token_backwards, find_end_of, find_end_of_inset, find_end_of_layout, find_re, \
|
||||
get_option_value, get_containing_layout, get_value, get_quoted_value, set_option_value
|
||||
find_token_backwards, find_end_of, find_end_of_inset, find_end_of_layout, \
|
||||
find_end_of_sequence, find_re, get_option_value, get_containing_layout, \
|
||||
get_value, get_quoted_value, set_option_value
|
||||
|
||||
#from parser_tools import find_token, find_end_of, find_tokens, \
|
||||
#find_end_of_inset, find_end_of_layout, \
|
||||
@ -2711,6 +2712,131 @@ def convert_beamerblocks(document):
|
||||
i = j
|
||||
|
||||
|
||||
def convert_overprint(document):
|
||||
" Convert old beamer overprint layouts 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 Overprint", 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 Overprint sequence!")
|
||||
i = i + 1
|
||||
continue
|
||||
endseq = j
|
||||
subst = ["\\begin_layout Standard"] + put_cmd_in_ert("\\begin{overprint}")
|
||||
esubst = ["\\end_layout", "", "\\begin_layout Standard"] + put_cmd_in_ert("\\end{overprint}") + ["\\end_layout"]
|
||||
endseq = endseq + len(esubst) - len(document.body[j : j])
|
||||
document.body[j : j] = esubst
|
||||
argbeg = find_token(document.body, "\\begin_inset Argument 1", i, j)
|
||||
if argbeg != -1:
|
||||
argend = find_end_of_layout(document.body, argbeg)
|
||||
if argend == -1:
|
||||
document.warning("Malformed lyx document. Cannot find end of Overprint argument!")
|
||||
i = i + 1
|
||||
continue
|
||||
beginPlain = find_token(document.body, "\\begin_layout Plain Layout", argbeg)
|
||||
endPlain = find_end_of_layout(document.body, beginPlain)
|
||||
content = document.body[beginPlain + 1 : endPlain]
|
||||
# Adjust range end
|
||||
endseq = endseq - len(document.body[argbeg : argend + 1])
|
||||
# Remove arg inset
|
||||
del document.body[argbeg : argend + 1]
|
||||
subst += put_cmd_in_ert("[") + content + put_cmd_in_ert("]")
|
||||
|
||||
endseq = endseq - len(document.body[i : i])
|
||||
document.body[i : i] = subst + ["\\end_layout"]
|
||||
endseq += len(subst)
|
||||
|
||||
for p in range(i, endseq):
|
||||
if document.body[p] == "\\begin_layout Overprint":
|
||||
document.body[p] = "\\begin_layout Standard"
|
||||
|
||||
i = endseq
|
||||
|
||||
|
||||
def revert_overprint(document):
|
||||
" Revert old beamer overprint layouts 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 Overprint", 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 Overprint sequence!")
|
||||
i = i + 1
|
||||
continue
|
||||
endseq = j
|
||||
subst = ["\\begin_layout Standard"] + put_cmd_in_ert("\\begin{overprint}")
|
||||
esubst = ["\\end_layout", "", "\\begin_layout Standard"] + put_cmd_in_ert("\\end{overprint}")
|
||||
endseq = endseq + len(esubst) - len(document.body[j : j])
|
||||
document.body[j : j] = esubst
|
||||
argbeg = find_token(document.body, "\\begin_inset Argument 1", i, j)
|
||||
if argbeg != -1:
|
||||
argend = find_end_of_inset(document.body, argbeg)
|
||||
if argend == -1:
|
||||
document.warning("Malformed lyx document. Cannot find end of Overprint argument!")
|
||||
i = i + 1
|
||||
continue
|
||||
beginPlain = find_token(document.body, "\\begin_layout Plain Layout", argbeg)
|
||||
endPlain = find_end_of_layout(document.body, beginPlain)
|
||||
content = document.body[beginPlain + 1 : endPlain]
|
||||
# Adjust range end
|
||||
endseq = endseq - len(document.body[argbeg : argend])
|
||||
# Remove arg inset
|
||||
del document.body[argbeg : argend + 1]
|
||||
subst += put_cmd_in_ert("[") + content + put_cmd_in_ert("]")
|
||||
|
||||
endseq = endseq - len(document.body[i : i])
|
||||
document.body[i : i] = subst + ["\\end_layout"]
|
||||
endseq += len(subst)
|
||||
|
||||
p = i
|
||||
while True:
|
||||
if p >= endseq:
|
||||
break
|
||||
if document.body[p] == "\\begin_layout Overprint":
|
||||
q = find_end_of_layout(document.body, p)
|
||||
if q == -1:
|
||||
document.warning("Malformed lyx document. Cannot find end of Overprint layout!")
|
||||
p += 1
|
||||
continue
|
||||
subst = ["\\begin_layout Standard"] + put_cmd_in_ert("\\onslide")
|
||||
argbeg = find_token(document.body, "\\begin_inset Argument item:1", p, q)
|
||||
if argbeg != -1:
|
||||
argend = find_end_of_inset(document.body, argbeg)
|
||||
if argend == -1:
|
||||
document.warning("Malformed lyx document. Cannot find end of Overprint item argument!")
|
||||
p += 1
|
||||
continue
|
||||
beginPlain = find_token(document.body, "\\begin_layout Plain Layout", argbeg)
|
||||
endPlain = find_end_of_layout(document.body, beginPlain)
|
||||
content = document.body[beginPlain + 1 : endPlain]
|
||||
# Adjust range end
|
||||
endseq = endseq - len(document.body[argbeg : argend + 1])
|
||||
# Remove arg inset
|
||||
del document.body[argbeg : argend + 1]
|
||||
subst += put_cmd_in_ert("<") + content + put_cmd_in_ert(">")
|
||||
endseq = endseq - len(document.body[p : p + 1]) + len(subst)
|
||||
document.body[p : p + 1] = subst
|
||||
p = p + 1
|
||||
|
||||
i = endseq
|
||||
|
||||
|
||||
##
|
||||
# Conversion hub
|
||||
@ -2757,10 +2883,12 @@ convert = [
|
||||
[450, []],
|
||||
[451, [convert_beamerargs, convert_againframe_args, convert_corollary_args, convert_quote_args]],
|
||||
[452, [convert_beamerblocks]],
|
||||
[453, [convert_use_stmaryrd]]
|
||||
[453, [convert_use_stmaryrd]],
|
||||
[454, [convert_overprint]]
|
||||
]
|
||||
|
||||
revert = [
|
||||
[453, [revert_overprint]],
|
||||
[452, [revert_use_stmaryrd]],
|
||||
[451, [revert_beamerblocks]],
|
||||
[450, [revert_beamerargs, revert_beamerargs2, revert_beamerargs3, revert_beamerflex]],
|
||||
|
@ -104,6 +104,10 @@ find_end_of_inset(lines, i):
|
||||
find_end_of_layout(lines, i):
|
||||
Specialization of find_end_of for layouts.
|
||||
|
||||
find_end_of_sequence(lines, i):
|
||||
Find the end of the sequence of layouts of the same kind.
|
||||
Considers nesting.
|
||||
|
||||
is_in_inset(lines, i, inset):
|
||||
Checks if line i is in an inset of the given type.
|
||||
If so, returns starting and ending lines. Otherwise,
|
||||
@ -141,6 +145,9 @@ check_token(line, token):
|
||||
is_nonempty_line(line):
|
||||
Does line contain something besides whitespace?
|
||||
|
||||
count_pars_in_inset(lines, i):
|
||||
Counts the paragraphs inside an inset.
|
||||
|
||||
'''
|
||||
|
||||
import re
|
||||
@ -486,3 +493,34 @@ def count_pars_in_inset(lines, i):
|
||||
pars += 1
|
||||
|
||||
return pars
|
||||
|
||||
|
||||
def find_end_of_sequence(lines, i):
|
||||
'''
|
||||
Returns the end of a sequence of identical layouts.
|
||||
'''
|
||||
lay = get_containing_layout(lines, i)
|
||||
if lay == False:
|
||||
return -1
|
||||
layout = lay[0]
|
||||
endlay = lay[2]
|
||||
i = endlay
|
||||
while True:
|
||||
m = re.match(r'\\begin_layout (.*)', lines[i])
|
||||
if m and m.group(1) != layout:
|
||||
return endlay
|
||||
elif lines[i] == "\\begin_deeper":
|
||||
j = find_end_of(lines, i, "\\begin_deeper", "\\end_deeper")
|
||||
if j != -1:
|
||||
i = j
|
||||
continue
|
||||
if m and m.group(1) == layout:
|
||||
endlay = find_end_of_layout(lines, i)
|
||||
i = endlay
|
||||
continue
|
||||
if i == len(lines) - 1:
|
||||
break
|
||||
i = i + 1
|
||||
|
||||
return endlay
|
||||
|
||||
|
@ -90,6 +90,10 @@ Format LaTeX feature LyX feature
|
||||
452 beamer block arguments InsetArgument
|
||||
\begin{block}<overlay>{title}
|
||||
453 automatic stmaryrd loading \use_package stmaryrd
|
||||
454 beamer overprint environment InsetArgument, layout Overprint
|
||||
\begin{overprint}[maxlength]
|
||||
\onslide<slide> text ...
|
||||
\end{overprint}
|
||||
|
||||
|
||||
General
|
||||
|
@ -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 453 // gb: support the stmaryrd package
|
||||
#define LYX_FORMAT_TEX2LYX 453 // gb: support the stmaryrd package
|
||||
#define LYX_FORMAT_LYX 454 // spitz: support for beamer overprint
|
||||
#define LYX_FORMAT_TEX2LYX 454 // spitz: support for beamer overprint
|
||||
|
||||
#if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
|
||||
#ifndef _MSC_VER
|
||||
|
Loading…
Reference in New Issue
Block a user