commit 706960eba4e467b0d4512e8649b7e58569f9aa96
Author: Juergen Spitzmueller <[email protected]>
Date:   Fri Jan 9 11:24:45 2015 +0100

    Add Question and Question* theorem types (bug #9015)
    
    File format change.

diff --git a/development/FORMAT b/development/FORMAT
index 627fbb5..ea3fa8a 100644
--- a/development/FORMAT
+++ b/development/FORMAT
@@ -11,6 +11,11 @@ adjustments are made to tex2lyx and bugs are fixed in 
lyx2lyx.
 
 -----------------------
 
+2015-01-09 Jürgen Spitzmüller <[email protected]>
+       * Format incremented to 480:
+         Add self-defined Question* and Question lemma types to
+          theorems-ams-extended-bytype module.
+
 2014-08-31 Jürgen Spitzmüller <[email protected]>
        * Format incremented to 479
          Support for beamer lemma environment.
diff --git a/lib/layouts/theorems-ams-extended-bytype.module 
b/lib/layouts/theorems-ams-extended-bytype.module
index 1046d01..7b355ca 100644
--- a/lib/layouts/theorems-ams-extended-bytype.module
+++ b/lib/layouts/theorems-ams-extended-bytype.module
@@ -33,6 +33,7 @@ Requires      amsmath
 # - Acknowledgement
 # - Conclusion
 # - Assumption
+# - Question
 
 # We need separate counters for each theorem-like style.
 Counter criterion
@@ -55,6 +56,8 @@ Counter conclusion
 End
 Counter assumption
 End
+Counter question
+End
 
 
 Style Criterion
@@ -405,4 +408,38 @@ Style Assumption*
        EndBabelPreamble
 End
 
+Style Question
+       CopyStyle             Theorem
+       DependsOn             Theorem
+       LatexName             question
+       LabelString           "Question \thequestion."
+       Preamble
+         \theoremstyle{plain}
+         \newtheorem{question}{\protect\questionname}
+       EndPreamble
+       LangPreamble
+         \providecommand{\questionname}{_(Question)}
+       EndLangPreamble
+       BabelPreamble
+         \addto\captions$$lang{\renewcommand{\questionname}{_(Question)}}
+       EndBabelPreamble
+       LabelCounter          question
+End
+
+Style Question*
+       CopyStyle             Theorem*
+       LatexName             question*
+       LabelString           "Question."
+       Preamble
+         \theoremstyle{plain}
+         \newtheorem*{question*}{\protect\questionname}
+       EndPreamble
+       LangPreamble
+         \providecommand{\questionname}{_(Question)}
+       EndLangPreamble
+       BabelPreamble
+         \addto\captions$$lang{\renewcommand{\questionname}{_(Question)}}
+       EndBabelPreamble
+End
+
 Input theorems-refprefix.inc
diff --git a/lib/layouts/theorems-refprefix.inc 
b/lib/layouts/theorems-refprefix.inc
index dc224e9..87da6b7 100644
--- a/lib/layouts/theorems-refprefix.inc
+++ b/lib/layouts/theorems-refprefix.inc
@@ -89,3 +89,8 @@ End
 IfStyle Assumption
        RefPrefix assu
 End
+
+
+IfStyle Question
+       RefPrefix que
+End
diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py
index 5c8c500..658d0ec 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", range(277,346), minor_versions("1.6" , 10)),
                    ("2_0", range(346,414), minor_versions("2.0", 8)),
                    ("2_1", range(414,475), minor_versions("2.1", 0)),
-                   ("2_2", range(475,480), minor_versions("2.2", 0))
+                   ("2_2", range(475,481), minor_versions("2.2", 0))
                   ]
 
 ####################################################################
diff --git a/lib/lyx2lyx/lyx_2_2.py b/lib/lyx2lyx/lyx_2_2.py
index 172cb23..eeea01e 100644
--- a/lib/lyx2lyx/lyx_2_2.py
+++ b/lib/lyx2lyx/lyx_2_2.py
@@ -411,6 +411,75 @@ def revert_beamer_lemma(document):
 
         i = j
 
+
+
+def revert_question_env(document):
+    """
+    Reverts question and question* environments of
+    theorems-ams-extended-bytype module to ERT
+    """
+
+    # Do we use theorems-ams-extended-bytype module?
+    have_mod = False
+    mods = document.get_module_list()
+    for mod in mods:
+        if mod == "theorems-ams-extended-bytype":
+            have_mod = True
+            continue
+
+    if not have_mod:
+        return
+
+    consecutive = False
+    i = 0
+    while True:
+        i = find_token(document.body, "\\begin_layout Question", i)
+        if i == -1:
+            return
+
+        starred = document.body[i] == "\\begin_layout Question*"
+
+        j = find_end_of_layout(document.body, i)
+        if j == -1:
+            document.warning("Malformed LyX document: Can't find end of 
Question layout")
+            i += 1
+            continue
+
+        # if this is not a consecutive env, add start command
+        begcmd = []
+        if not consecutive:
+            if starred:
+                begcmd = put_cmd_in_ert("\\begin{question*}")
+            else:
+                begcmd = put_cmd_in_ert("\\begin{question}")
+
+        # has this a consecutive theorem of same type?
+        consecutive = False
+        if starred:
+            consecutive = document.body[j + 2] == "\\begin_layout Question*"
+        else:
+            consecutive = document.body[j + 2] == "\\begin_layout Question"
+
+        # if this is not followed by a consecutive env, add end command
+        if not consecutive:
+            if starred:
+                document.body[j : j + 1] = put_cmd_in_ert("\\end{question*}") 
+ ["\\end_layout"]
+            else:
+                document.body[j : j + 1] = put_cmd_in_ert("\\end{question}") + 
["\\end_layout"]
+
+        document.body[i : i + 1] = ["\\begin_layout Standard", ""] + begcmd
+
+        add_to_preamble(document, "\\providecommand{\questionname}{Question}")
+
+        if starred:
+            add_to_preamble(document, "\\theoremstyle{plain}\n" \
+                                      
"\\newtheorem*{question*}{\\protect\\questionname}")
+        else:
+            add_to_preamble(document, "\\theoremstyle{plain}\n" \
+                                      
"\\newtheorem{question}{\\protect\\questionname}")
+
+        i = j
+
   
 ##
 # Conversion hub
@@ -425,10 +494,12 @@ convert = [
            [476, []],
            [477, []],
            [478, []],
-           [479, []]
+           [479, []],
+           [480, []]
           ]
 
 revert =  [
+           [479, [revert_question_env]],
            [478, [revert_beamer_lemma]],
            [477, [revert_xarrow]],
            [476, [revert_swissgerman]],
diff --git a/src/version.h b/src/version.h
index ffae5c4..f29b049 100644
--- a/src/version.h
+++ b/src/version.h
@@ -36,8 +36,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 479 // spitz: beamer Lemma layout
-#define LYX_FORMAT_TEX2LYX 479
+#define LYX_FORMAT_LYX 480 // spitz: question and question* environments
+#define LYX_FORMAT_TEX2LYX 480
 
 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
 #ifndef _MSC_VER

Reply via email to