commit cc6c86ff3b7d10bc6a0ea286020f63a75fef9608
Author: Uwe Stöhr <[email protected]>
Date:   Wed Nov 18 01:14:30 2015 +0100

    theorems.inc: add environment "solution"
    
    fileformat change, fixes bug #6363

diff --git a/lib/layouts/theorems-bytype.inc b/lib/layouts/theorems-bytype.inc
index 91cb285..24c8acc 100644
--- a/lib/layouts/theorems-bytype.inc
+++ b/lib/layouts/theorems-bytype.inc
@@ -16,6 +16,7 @@
 # - Example
 # - Problem
 # - Exercise
+# - Solution
 # - Remark
 # - Claim
 # - Proof
@@ -240,6 +241,25 @@ Style Exercise
 End
 
 
+Style Solution
+       CopyStyle             Definition
+       LatexName             sol
+       LabelString           "Solution \thesolution."
+       Preamble
+         \theoremstyle{definition}
+         \newtheorem{sol}{\protect\solutionname}
+       EndPreamble
+       Requires              amsthm
+       LangPreamble
+               \providecommand{\solutionname}{_(Solution)}
+       EndLangPreamble
+       BabelPreamble
+               \addto\captions$$lang{\renewcommand{\solutionname}{_(Solution)}}
+       EndBabelPreamble
+       LabelCounter          solution
+End
+
+
 Style Remark
        CopyStyle             Theorem
        LatexName             rem
diff --git a/lib/layouts/theorems-bytype.module 
b/lib/layouts/theorems-bytype.module
index 233a66c..2265157 100644
--- a/lib/layouts/theorems-bytype.module
+++ b/lib/layouts/theorems-bytype.module
@@ -34,6 +34,8 @@ Counter problem
 End
 Counter exercise
 End
+Counter solution
+End
 Counter remark
 End
 Counter claim
diff --git a/lib/layouts/theorems.inc b/lib/layouts/theorems.inc
index 9e77b0e..ab684c0 100644
--- a/lib/layouts/theorems.inc
+++ b/lib/layouts/theorems.inc
@@ -15,6 +15,7 @@
 # - Example
 # - Problem
 # - Exercise
+# - Solution
 # - Remark
 # - Claim
 # - Case (by inclusion)
@@ -232,6 +233,23 @@ Style Exercise
 End
 
 
+Style Solution
+       CopyStyle             Definition
+       LatexName             sol
+       LabelString           "Solution \thetheorem."
+       Preamble
+               \theoremstyle{definition}
+               \newtheorem{sol}[thm]{\protect\solutionname}
+       EndPreamble
+       LangPreamble
+               \providecommand{\solutionname}{_(Solution)}
+       EndLangPreamble
+       BabelPreamble
+               \addto\captions$$lang{\renewcommand{\solutionname}{_(Solution)}}
+       EndBabelPreamble
+End
+
+
 Style Remark
        CopyStyle             Theorem
        DependsOn             Theorem
diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py
index 04dc3e7..6916184 100644
--- a/lib/lyx2lyx/LyX.py
+++ b/lib/lyx2lyx/LyX.py
@@ -85,7 +85,7 @@ format_relation = [("0_06",    [200], minor_versions("0.6" , 
4)),
                    ("1_6", list(range(277,346)), minor_versions("1.6" , 10)),
                    ("2_0", list(range(346,414)), minor_versions("2.0" , 8)),
                    ("2_1", list(range(414,475)), minor_versions("2.1" , 0)),
-                   ("2_2", list(range(475,502)), minor_versions("2.2" , 0))
+                   ("2_2", list(range(475,503)), minor_versions("2.2" , 0))
                   ]
 
 ####################################################################
diff --git a/lib/lyx2lyx/lyx_2_2.py b/lib/lyx2lyx/lyx_2_2.py
index cd88e05..e041a6b 100644
--- a/lib/lyx2lyx/lyx_2_2.py
+++ b/lib/lyx2lyx/lyx_2_2.py
@@ -2111,6 +2111,50 @@ def revert_fontsettings(document):
         j = j + 1
 
 
+def revert_solution(document):
+    " Reverts the solution environmen of the theorem module to TeX code "
+
+    # Do we use theorems-std module?
+    have_mod = False
+    mods = document.get_module_list()
+    for mod in mods:
+        if mod == "theorems-std" or mod == "theorems-bytype":
+            have_mod = True
+            continue
+    if not have_mod:
+        return
+    consecutive = False
+    i = 0
+    while True:
+        i = find_token(document.body, "\\begin_layout Solution", 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 
Solution layout")
+            i += 1
+            continue
+        # if this is not a consecutive env, add start command
+        begcmd = []
+        if not consecutive:
+            begcmd = put_cmd_in_ert("\\begin{sol}")
+        # has this a consecutive theorem of same type?
+        consecutive = False
+        consecutive = document.body[j + 2] == "\\begin_layout Solution"
+        # if this is not followed by a consecutive env, add end command
+        if not consecutive:
+            document.body[j : j + 1] = put_cmd_in_ert("\\end{sol}") + 
["\\end_layout"]
+        document.body[i : i + 1] = ["\\begin_layout Standard", ""] + begcmd
+        add_to_preamble(document, "\\providecommand{\solutionname}{Solution}")
+        if mod == "theorems-std":
+            add_to_preamble(document, "\\theoremstyle{plain}\n" \
+                                      
"\\newtheorem{sol}[thm]{\\protect\\solutionname}")
+        if mod == "theorems-bytype":
+            add_to_preamble(document, "\\theoremstyle{definition}\n" \
+                                      
"\\newtheorem{sol}{\\protect\\solutionname}")
+        i = j
+
+
 ##
 # Conversion hub
 #
@@ -2146,10 +2190,12 @@ convert = [
            [498, []],
            [499, [convert_moderncv]],
            [500, []],
-           [501, [convert_fontsettings]]
+           [501, [convert_fontsettings]],
+           [502, []]
           ]
 
 revert =  [
+           [501, [revert_solution]],
            [500, [revert_fontsettings]],
            [499, [revert_achemso]],
            [498, [revert_moderncv_1, revert_moderncv_2]],
diff --git a/src/tex2lyx/test/CJK.lyx.lyx b/src/tex2lyx/test/CJK.lyx.lyx
index b3e4a47..802fd0b 100644
--- a/src/tex2lyx/test/CJK.lyx.lyx
+++ b/src/tex2lyx/test/CJK.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 501
+\lyxformat 502
 \begin_document
 \begin_header
 \origin roundtrip
diff --git a/src/tex2lyx/test/CJKutf8.lyx.lyx b/src/tex2lyx/test/CJKutf8.lyx.lyx
index 263abcd..3da93b9 100644
--- a/src/tex2lyx/test/CJKutf8.lyx.lyx
+++ b/src/tex2lyx/test/CJKutf8.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 501
+\lyxformat 502
 \begin_document
 \begin_header
 \origin roundtrip
diff --git a/src/tex2lyx/test/DummyDocument.lyx.lyx 
b/src/tex2lyx/test/DummyDocument.lyx.lyx
index 489308f..10c8258 100644
--- a/src/tex2lyx/test/DummyDocument.lyx.lyx
+++ b/src/tex2lyx/test/DummyDocument.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 501
+\lyxformat 502
 \begin_document
 \begin_header
 \origin roundtrip
diff --git a/src/tex2lyx/test/Dummy~Document.lyx.lyx 
b/src/tex2lyx/test/Dummy~Document.lyx.lyx
index e93a868..b590ee9 100644
--- a/src/tex2lyx/test/Dummy~Document.lyx.lyx
+++ b/src/tex2lyx/test/Dummy~Document.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 501
+\lyxformat 502
 \begin_document
 \begin_header
 \origin roundtrip
diff --git a/src/tex2lyx/test/XeTeX-polyglossia.lyx.lyx 
b/src/tex2lyx/test/XeTeX-polyglossia.lyx.lyx
index 3bdd502..966cfc1 100644
--- a/src/tex2lyx/test/XeTeX-polyglossia.lyx.lyx
+++ b/src/tex2lyx/test/XeTeX-polyglossia.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 501
+\lyxformat 502
 \begin_document
 \begin_header
 \origin roundtrip
diff --git a/src/tex2lyx/test/algo2e.lyx.lyx b/src/tex2lyx/test/algo2e.lyx.lyx
index ae6d472..59fd2b0 100644
--- a/src/tex2lyx/test/algo2e.lyx.lyx
+++ b/src/tex2lyx/test/algo2e.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 501
+\lyxformat 502
 \begin_document
 \begin_header
 \origin roundtrip
diff --git a/src/tex2lyx/test/box-color-size-space-align.lyx.lyx 
b/src/tex2lyx/test/box-color-size-space-align.lyx.lyx
index 588f670..fe269d5 100644
--- a/src/tex2lyx/test/box-color-size-space-align.lyx.lyx
+++ b/src/tex2lyx/test/box-color-size-space-align.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 501
+\lyxformat 502
 \begin_document
 \begin_header
 \origin roundtrip
diff --git a/src/tex2lyx/test/test-insets-basic.lyx.lyx 
b/src/tex2lyx/test/test-insets-basic.lyx.lyx
index 38bfb38..d1bc2a1 100644
--- a/src/tex2lyx/test/test-insets-basic.lyx.lyx
+++ b/src/tex2lyx/test/test-insets-basic.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 501
+\lyxformat 502
 \begin_document
 \begin_header
 \origin roundtrip
diff --git a/src/tex2lyx/test/test-insets.lyx.lyx 
b/src/tex2lyx/test/test-insets.lyx.lyx
index 39db027..89ebe8a 100644
--- a/src/tex2lyx/test/test-insets.lyx.lyx
+++ b/src/tex2lyx/test/test-insets.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 501
+\lyxformat 502
 \begin_document
 \begin_header
 \origin roundtrip
diff --git a/src/tex2lyx/test/test-memoir.lyx.lyx 
b/src/tex2lyx/test/test-memoir.lyx.lyx
index d0232fb..d05a2e2 100644
--- a/src/tex2lyx/test/test-memoir.lyx.lyx
+++ b/src/tex2lyx/test/test-memoir.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 501
+\lyxformat 502
 \begin_document
 \begin_header
 \origin roundtrip
diff --git a/src/tex2lyx/test/test-modules.lyx.lyx 
b/src/tex2lyx/test/test-modules.lyx.lyx
index 4bf0ef3..1a2dca7 100644
--- a/src/tex2lyx/test/test-modules.lyx.lyx
+++ b/src/tex2lyx/test/test-modules.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 501
+\lyxformat 502
 \begin_document
 \begin_header
 \origin roundtrip
diff --git a/src/tex2lyx/test/test-refstyle-theorems.lyx.lyx 
b/src/tex2lyx/test/test-refstyle-theorems.lyx.lyx
index e77e9e3..22e57d7 100644
--- a/src/tex2lyx/test/test-refstyle-theorems.lyx.lyx
+++ b/src/tex2lyx/test/test-refstyle-theorems.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 501
+\lyxformat 502
 \begin_document
 \begin_header
 \origin roundtrip
diff --git a/src/tex2lyx/test/test-scr.lyx.lyx 
b/src/tex2lyx/test/test-scr.lyx.lyx
index 13933c4..a97578c 100644
--- a/src/tex2lyx/test/test-scr.lyx.lyx
+++ b/src/tex2lyx/test/test-scr.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 501
+\lyxformat 502
 \begin_document
 \begin_header
 \origin roundtrip
diff --git a/src/tex2lyx/test/test-structure.lyx.lyx 
b/src/tex2lyx/test/test-structure.lyx.lyx
index 3b3a2f8..8ef1d73 100644
--- a/src/tex2lyx/test/test-structure.lyx.lyx
+++ b/src/tex2lyx/test/test-structure.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 501
+\lyxformat 502
 \begin_document
 \begin_header
 \origin roundtrip
diff --git a/src/tex2lyx/test/test.lyx.lyx b/src/tex2lyx/test/test.lyx.lyx
index a4788a4..53e3ec4 100644
--- a/src/tex2lyx/test/test.lyx.lyx
+++ b/src/tex2lyx/test/test.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 501
+\lyxformat 502
 \begin_document
 \begin_header
 \origin roundtrip
diff --git a/src/tex2lyx/test/verbatim.lyx.lyx 
b/src/tex2lyx/test/verbatim.lyx.lyx
index 00f7643..3d1f60c 100644
--- a/src/tex2lyx/test/verbatim.lyx.lyx
+++ b/src/tex2lyx/test/verbatim.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 501
+\lyxformat 502
 \begin_document
 \begin_header
 \origin roundtrip
diff --git a/src/version.h b/src/version.h
index f6de323..0871b0a 100644
--- a/src/version.h
+++ b/src/version.h
@@ -32,8 +32,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 501 // gb: store both TeX and non-TeX font selections
-#define LYX_FORMAT_TEX2LYX 501
+#define LYX_FORMAT_LYX 502 // uwestoehr: new environment "solution" in theorems
+#define LYX_FORMAT_TEX2LYX 502
 
 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
 #ifndef _MSC_VER

Reply via email to