From 6869d5205fdbbb601e65881bbb0ab2991f3de7cf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Uwe=20St=C3=B6hr?= Date: Mon, 20 Feb 2012 02:10:33 +0000 Subject: [PATCH] support for verbatim: step 1: the layout and the lyx2lyx code,;fileformat change (next step is the beamer issue and last step tex2lyx support) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@40784 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/FORMAT | 9 +++++ lib/layouts/stdlayouts.inc | 24 +++++++++++++ lib/lyx2lyx/lyx_2_1.py | 70 ++++++++++++++++++++++++++++++++++++-- src/version.h | 2 +- 4 files changed, 102 insertions(+), 3 deletions(-) diff --git a/development/FORMAT b/development/FORMAT index f08041d925..2e685f4b3f 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -11,6 +11,15 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx. ----------------------- +2012-02-20 Uwe Stöhr + * Format incremented to 426 (r40784) + support for the verbatim environment + (added only a layout) + +2012-01-23 Uwe Stöhr + * Format incremented to 425 (r40663) + support for the LaTeX-package cancel (fix bug 6819) + 2012-01-09 Julien Rioux * Format incremented to 424 (r40592) New buffer param \cite_engine_type to specify the type of diff --git a/lib/layouts/stdlayouts.inc b/lib/layouts/stdlayouts.inc index a1a360ba58..40742e586c 100644 --- a/lib/layouts/stdlayouts.inc +++ b/lib/layouts/stdlayouts.inc @@ -71,6 +71,30 @@ Style Verse End +Style Verbatim + Category MainText + LatexType Environment + LatexName verbatim + NextNoIndent 1 + ParbreakIsNewline 1 + FreeSpacing 1 + PassThru 1 + NewLine 0 + ParSkip 0.4 + TopSep 0.7 + BottomSep 0.7 + ParSep 0.5 + Align Block + AlignPossible Block + LabelType No_Label + Font + Family Typewriter + EndFont + HTMLTag

+	HTMLItem		p
+End
+
+
 Style --Separator--
 	Category              MainText
 	KeepEmpty             1
diff --git a/lib/lyx2lyx/lyx_2_1.py b/lib/lyx2lyx/lyx_2_1.py
index 5cb4cb9416..dc755f389d 100644
--- a/lib/lyx2lyx/lyx_2_1.py
+++ b/lib/lyx2lyx/lyx_2_1.py
@@ -26,7 +26,8 @@ import sys, os
 # Uncomment only what you need to import, please.
 
 from parser_tools import del_token, find_token, find_end_of, find_end_of_inset, \
-    find_re, get_option_value, get_value, get_quoted_value, set_option_value
+    find_end_of_layout, find_re, get_option_value, get_value, get_quoted_value, \
+    set_option_value
 
 #from parser_tools import find_token, find_end_of, find_tokens, \
   #find_token_exact, find_end_of_inset, find_end_of_layout, \
@@ -471,6 +472,69 @@ def revert_cancel(document):
         i = j
 
 
+def revert_verbatim(document):
+    " Revert verbatim einvironments completely to TeX-code. "
+    i = 0
+    consecutive = False
+    subst_end = ['\end_layout', '', '\\begin_layout Plain Layout',
+    	         '\end_layout', '',
+                 '\\begin_layout Plain Layout', '', '',
+                 '\\backslash', '',
+                 'end{verbatim}',
+                 '\\end_layout', '', '\\end_inset',
+                 '', '', '\\end_layout']
+    subst_begin = ['\\begin_layout Standard', '\\noindent',
+                   '\\begin_inset ERT', 'status collapsed', '',
+                   '\\begin_layout Plain Layout', '', '', '\\backslash',
+                   'begin{verbatim}',
+                   '\\end_layout', '', '\\begin_layout Plain Layout', '']
+    while 1:
+        i = find_token(document.body, "\\begin_layout Verbatim", i)
+        if i == -1:
+            return
+        j = find_end_of_layout(document.body, i)
+        if j == -1:
+            document.warning("Malformed lyx document: Can't find end of Verbatim layout")
+            i += 1
+            continue
+        # delete all line breaks insets (there are no other insets)
+        l = i
+        while 1:
+            n = find_token(document.body, "\\begin_inset Newline newline", l)
+            if n == -1:
+                n = find_token(document.body, "\\begin_inset Newline linebreak", l)
+                if n == -1:
+                    break
+            m = find_end_of_inset(document.body, n)
+            del(document.body[m:m+1])
+            document.body[n:n+1] = ['\end_layout', '', '\\begin_layout Plain Layout']
+            l += 1
+            j += 1
+        # consecutive verbatim environments need to be connected
+        k = find_token(document.body, "\\begin_layout Verbatim", j)
+        if k == j + 2 and consecutive == False:
+            consecutive = True
+            document.body[j:j+1] = ['\end_layout', '', '\\begin_layout Plain Layout']
+            document.body[i:i+1] = subst_begin
+            continue
+        if k == j + 2 and consecutive == True:
+            document.body[j:j+1] = ['\end_layout', '', '\\begin_layout Plain Layout']
+            del(document.body[i:i+1])
+            continue
+        if k != j + 2 and consecutive == True:
+            document.body[j:j+1] = subst_end
+            # the next paragraph must not be indented
+            document.body[j+19:j+19] = ['\\noindent']
+            del(document.body[i:i+1])
+            consecutive = False
+            continue
+        else:
+            document.body[j:j+1] = subst_end
+            # the next paragraph must not be indented
+            document.body[j+19:j+19] = ['\\noindent']
+            document.body[i:i+1] = subst_begin
+
+
 ##
 # Conversion hub
 #
@@ -488,10 +552,12 @@ convert = [
            [422, [convert_use_packages]],
            [423, [convert_use_mathtools]],
            [424, [convert_cite_engine_type]],
-           [425, []]
+           [425, []],
+           [426, []]
           ]
 
 revert =  [
+           [425, [revert_verbatim]],
            [424, [revert_cancel]],
            [423, [revert_cite_engine_type]],
            [422, [revert_use_mathtools]],
diff --git a/src/version.h b/src/version.h
index 76741f8e01..b9bc0da5d5 100644
--- a/src/version.h
+++ b/src/version.h
@@ -30,7 +30,7 @@ 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 425 // uwestoehr: support for the package cancel
+#define LYX_FORMAT_LYX 426 // uwestoehr: support for verbatim
 #define LYX_FORMAT_TEX2LYX 425 // uwestoehr: support for the package cancel
 
 #if LYX_FORMAT_FOR_TEX2LYX != LYX_FORMAT_FOR_LYX
-- 
2.39.2