Jürgen Spitzmüller wrote:
> > Maybe, but that letters can have parts behind the \end{letter} command is
> > a fact. And the "bad" implementation of beamer is a consequence of
> > missing LyX support for certain commands.
>
> But we can do better for scrlttr2. I'll have a look.

Attached patch reimplements the automatic end letter tag, but introduces an 
optional end letter tag for cases like the serial letter. Thus KOMA letter 
users are not forced to insert an end letter tag, but it is possible for such 
special cases like serial letters.

The lyx2lyx routine becomes obsolete (I don't think you should convert ERT).

Jürgen
Index: lib/lyx2lyx/lyx_1_6.py
===================================================================
--- lib/lyx2lyx/lyx_1_6.py	(Revision 22806)
+++ lib/lyx2lyx/lyx_1_6.py	(Arbeitskopie)
@@ -1223,31 +1223,6 @@
         i = i + 1
 
 
-def convert_serial_letter(document):
-    " adds an EndLetter environment to scrlttr2 documents. "
-    tc = document.textclass
-    if (tc == "scrlttr2"):
-        i = len(document.body)
-        document.body[i-2] = '\\begin_layout EndLetter\n' \
-        '\\begin_inset Note Note\n' \
-        'status collapsed\n\n' \
-        '\\begin_layout Standard\n' \
-        'keep this environment empty\n' \
-        '\\end_layout\n\n' \
-        '\\end_inset\n\n\n' \
-        '\\end_layout\n\n'
-        i = 0
-        # remove ERT insets containing "\end{letter}"
-        while True:
-            i = find_token(document.body, "\\begin_inset ERT", i)
-            document.warning(str(i))
-            if i == -1:
-                return
-            if document.body[i+7] == "end{letter}":
-                del document.body[i-1:i+14]
-            i = i + 1
-
-
 ##
 # Conversion hub
 #
@@ -1290,7 +1265,7 @@
            [311, [convert_ams_classes]],
            [312, []],
            [313, [convert_module_names]],
-           [314, [convert_serial_letter]]
+           [314, []]
           ]
 
 revert =  [[313, []],
Index: lib/templates/koma-letter2.lyx
===================================================================
--- lib/templates/koma-letter2.lyx	(Revision 22806)
+++ lib/templates/koma-letter2.lyx	(Arbeitskopie)
@@ -146,6 +146,7 @@
 
 \begin_layout Standard
 
+
 \backslash
 today
 \end_layout
@@ -186,7 +187,8 @@
 status collapsed
 
 \begin_layout Standard
-http://www.ctan.org/tex-archive/macros/latex/contrib/supported/koma-script/scrguien.pdf
+http://www.ctan.org/tex-archive/macros/latex/contrib/supported/koma-script/scrguie
+n.pdf
 \end_layout
 
 \end_inset
@@ -208,18 +210,5 @@
 The LyX Users
 \end_layout
 
-\begin_layout EndLetter
-\begin_inset Note Note
-status collapsed
-
-\begin_layout Standard
-keep this environment empty
-\end_layout
-
-\end_inset
-
-
-\end_layout
-
 \end_body
 \end_document
Index: lib/layouts/scrlttr2.layout
===================================================================
--- lib/layouts/scrlttr2.layout	(Revision 22806)
+++ lib/layouts/scrlttr2.layout	(Arbeitskopie)
@@ -35,12 +35,18 @@
 	Obsoletedby           Labeling
 End
 
+Preamble
+	\newif\ifletterclosed
+EndPreamble
 
 
 Style Address
 	LatexType             Command
 	LatexName             begin
 	LatexParam            {letter}
+	Preamble
+		\AtEndDocument{\ifletterclosed\else\end{letter}\fi}
+	EndPreamble
 	KeepEmpty             1
 	LeftMargin            xxxxxxxxxxxx::xx
 	LabelSep              xx
@@ -326,6 +332,9 @@
 	Margin                Dynamic
 	LatexType             Command
 	LatexName             end{letter}
+	Preamble
+		\letterclosedtrue
+	EndPreamble
 	KeepEmpty             1
 	TopSep                1
 	ParSkip               0.4

Reply via email to