commit 041a3add6c044132ef42e2f7be77dc63214159ef
Author: Uwe Stöhr <[email protected]>
Date:   Sun May 24 17:03:13 2015 +0200

    tex2lyx/Preamble.cpp: fix bug #9561
    
    there were 2 issues:
    - the body was not output to the Preamble
    - the theorem module already defines a theorem. It must not be output to 
the preamble to avoid a redefinition error of LaTeX
    
    update the test files accordingly

diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp
index 613cbbb..f48da7a 100644
--- a/src/tex2lyx/Preamble.cpp
+++ b/src/tex2lyx/Preamble.cpp
@@ -1684,13 +1684,22 @@ void Preamble::parse(Parser & p, string const & 
forceclass,
                        string const body = p.verbatim_item();
                        string const opt3 = p.getFullOpt();
 
-                       add_known_theorem(name, opt1, !opt2.empty(),
-                               from_utf8("\\newtheorem{" + name + '}' +
-                                         opt1 + opt2 + '{' + body + '}' + 
opt3));
+                       string const complete = "\\newtheorem{" + name + '}' +
+                                         opt1 + opt2 + '{' + body + '}' + opt3;
+
+                       add_known_theorem(name, opt1, !opt2.empty(), 
from_utf8(complete));
+
+                       // we know that our theorem module already add 
automatically some
+                       // theorem definition. They must not be output in the 
preamble to
+                       // avoid LaTeX errors about redefinitions
+                       if (complete == 
"\\newtheorem{thm}{\\protect\\theoremname}")
+                               in_lyx_preamble = true;
+                       else
+                               in_lyx_preamble = false;
 
                        if (!in_lyx_preamble)
                                h_preamble << "\\newtheorem{" << name << '}'
-                                          << opt1 << opt2 << '{' << '}' << 
opt3;
+                                          << opt1 << opt2 << '{' << body << 
'}' << opt3;
                }
 
                else if (t.cs() == "def") {
diff --git a/src/tex2lyx/test/test-modules.lyx.lyx 
b/src/tex2lyx/test/test-modules.lyx.lyx
index f661dcf..35f5837 100644
--- a/src/tex2lyx/test/test-modules.lyx.lyx
+++ b/src/tex2lyx/test/test-modules.lyx.lyx
@@ -5,8 +5,16 @@
 \origin roundtrip
 \textclass amsart
 \begin_preamble
+\numberwithin{equation}{section} %% Comment out for sequentially-numbered
+\numberwithin{figure}{section} %% Comment out for sequentially-numbered
+\providecommand{\theoremname}{Theorem}
+\theoremstyle{plain}
+\newtheorem{lem}[thm]{Lemma}
+
 \usepackage{babel}
 
+
+
 \end_preamble
 \use_default_options false
 \begin_modules
diff --git a/src/tex2lyx/test/test-modules.tex 
b/src/tex2lyx/test/test-modules.tex
index b27ada9..abb9875 100644
--- a/src/tex2lyx/test/test-modules.tex
+++ b/src/tex2lyx/test/test-modules.tex
@@ -1,19 +1,14 @@
-%% LyX 1.6.1 created this file.  For more info, see http://www.lyx.org/.
-%% Do not edit unless you really know what you are doing.
 \documentclass[oneside,english]{amsart}
 \usepackage[T1]{fontenc}
 \usepackage[latin9]{inputenc}
 \usepackage{amsthm}
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
 \numberwithin{equation}{section} %% Comment out for sequentially-numbered
 \numberwithin{figure}{section} %% Comment out for sequentially-numbered
 \providecommand{\theoremname}{Theorem}
 \theoremstyle{plain}
-\theoremstyle{plain}
 \newtheorem{thm}{\protect\theoremname}
-  \theoremstyle{plain}
-  \newtheorem{lem}[thm]{Lemma}
+\theoremstyle{plain}
+\newtheorem{lem}[thm]{Lemma}
 
 \usepackage{babel}
 

Reply via email to