diff --git a/lib/layouts/theorems-bytype.inc b/lib/layouts/theorems-bytype.inc index 91cb2856c7..24c8accb5c 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 233a66c4ec..226515712b 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 9e77b0e454..ab684c0287 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 04dc3e7a90..6916184e58 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 cd88e05d34..e041a6bfd9 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 b3e4a470d3..802fd0b2dd 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 263abcde7e..3da93b9c77 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 489308f100..10c82581d3 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 e93a868823..b590ee9470 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 3bdd502221..966cfc1e8f 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 ae6d472070..59fd2b068d 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 588f67043a..fe269d536e 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 38bfb3870b..d1bc2a187b 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 39db027de3..89ebe8ae8a 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 d0232fb81e..d05a2e2061 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 4bf0ef39d4..1a2dca7152 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 e77e9e3088..22e57d7a9c 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 13933c4eec..a97578c813 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 3b3a2f8150..8ef1d7357d 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 a4788a42a7..53e3ec463d 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 00f7643a1c..3d1f60cce8 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 f6de323470..0871b0a01e 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