]> git.lyx.org Git - features.git/commitdiff
Add Question and Question* theorem types (bug #9015)
authorJuergen Spitzmueller <spitz@lyx.org>
Fri, 9 Jan 2015 10:24:45 +0000 (11:24 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Fri, 9 Jan 2015 10:24:45 +0000 (11:24 +0100)
File format change.

development/FORMAT
lib/layouts/theorems-ams-extended-bytype.module
lib/layouts/theorems-refprefix.inc
lib/lyx2lyx/LyX.py
lib/lyx2lyx/lyx_2_2.py
src/version.h

index 627fbb593cd99045ef91c75a1902174c1f06ca0c..ea3fa8a03f9afffc0f65366403ef2491c5198e3d 100644 (file)
@@ -11,6 +11,11 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx.
 
 -----------------------
 
+2015-01-09 Jürgen Spitzmüller <spitz@lyx.org>
+       * 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 <spitz@lyx.org>
        * Format incremented to 479
          Support for beamer lemma environment.
index 1046d0129292100131221251b097b4f713a2cfe5..7b355cadf2fbf28be072db2f4fa2eb21e9e68a01 100644 (file)
@@ -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
index dc224e992ea96789449a3df5d6d252ce984a0779..87da6b7f11ffd959c67e8422f7f8939f34724b5a 100644 (file)
@@ -89,3 +89,8 @@ End
 IfStyle Assumption
        RefPrefix assu
 End
+
+
+IfStyle Question
+       RefPrefix que
+End
index 5c8c5006202a6c641bb2fbd992c85c4a85b083ac..658d0ec61e0263c4e57237934469ca9665015b59 100644 (file)
@@ -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))
                   ]
 
 ####################################################################
index 172cb23f2c02659d1ebf653f8ff0a480bd7cc3bc..eeea01e436d3612ae6468009031a8f1434cf1fe3 100644 (file)
@@ -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]],
index ffae5c4f40f7d944179badbb80fa32c4999307be..f29b0494c1645291e21d363120e8bbe077258772 100644 (file)
@@ -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