]> git.lyx.org Git - lyx.git/blobdiff - src/tex2lyx/math.C
add config.h
[lyx.git] / src / tex2lyx / math.C
index 5e84b5d50dc23f25d6a45a2b92ada7720e3b73a8..7e03031872761828328c8b50acd89a51dff519e8 100644 (file)
@@ -16,6 +16,9 @@
 
 #include <iostream>
 
+
+namespace lyx {
+
 using std::cerr;
 using std::endl;
 
@@ -25,17 +28,7 @@ using std::string;
 
 bool is_math_env(string const & name)
 {
-       static char const * known_math_envs[] = { "equation", "equation*",
-       "eqnarray", "eqnarray*", "align", "align*", "gather", "gather*",
-       "multline", "multline*", "math", "displaymath", "flalign", "flalign*",
-       // These require extra args
-       "alignat", "alignat*", "xalignat", "xalignat*", "xxalignat",
-       0};
-
-       for (char const ** what = known_math_envs; *what; ++what)
-               if (*what == name)
-                       return true;
-       return false;
+       return known_math_environments.find(name) != known_math_environments.end();
 }
 
 
@@ -100,7 +93,6 @@ void parse_math(Parser & p, ostream & os, unsigned flags, const mode_type mode)
                }
 
                else if (t.cat() == catLetter ||
-                              t.cat() == catSpace ||
                               t.cat() == catSuper ||
                               t.cat() == catSub ||
                               t.cat() == catOther ||
@@ -109,15 +101,6 @@ void parse_math(Parser & p, ostream & os, unsigned flags, const mode_type mode)
                               t.cat() == catParameter)
                        os << t.character();
 
-               else if (t.cat() == catNewline) {
-                       //if (p.next_token().cat() == catNewline) {
-                       //      p.get_token();
-                       //      handle_par(os);
-                       //} else {
-                               os << "\n "; // note the space
-                       //}
-               }
-
                else if (t.cat() == catBegin) {
                        os << '{';
                        parse_math(p, os, FLAG_BRACE_LAST, mode);
@@ -130,8 +113,13 @@ void parse_math(Parser & p, ostream & os, unsigned flags, const mode_type mode)
                        os << "unexpected '}' in math\n";
                }
 
-               else if (t.cat() == catComment)
-                       handle_comment(p);
+               else if (t.cat() == catComment) {
+                       if (!t.cs().empty())
+                               cerr << "Ignoring comment: " << t.asInput();
+                       else
+                               // "%\n" combination
+                               p.skip_spaces();
+               }
 
                //
                // control sequences
@@ -200,6 +188,17 @@ void parse_math(Parser & p, ostream & os, unsigned flags, const mode_type mode)
                        os << '}';
                }
 
+               else if (t.cs() == "tag") {
+                       os << '\\' << t.cs();
+                       if (p.next_token().asInput() == "*") {
+                               p.get_token();
+                               os << '*';
+                       }
+                       os << '{';
+                       parse_math(p, os, FLAG_ITEM, MATHTEXT_MODE);
+                       os << '}';
+               }
+
                else if (t.cs() == "mbox" || t.cs() == "fbox") {
                        os << "\\" << t.cs() << '{';
                        parse_math(p, os, FLAG_ITEM, MATHTEXT_MODE);
@@ -220,6 +219,13 @@ void parse_math(Parser & p, ostream & os, unsigned flags, const mode_type mode)
                else if (t.cs() == "ss")
                        os << "ß";
 
+               else if (t.cs() == "cr") {
+                       // lyx can't handle \\cr
+                       cerr << "Warning: Converting TeX '\\cr' to LaTeX '\\\\'."
+                            << endl;
+                       os << "\\\\";
+               }
+
                else
                        os << t.asInput();
 
@@ -234,3 +240,6 @@ void parse_math(Parser & p, ostream & os, unsigned flags, const mode_type mode)
 
 
 // }])
+
+
+} // namespace lyx