]> git.lyx.org Git - lyx.git/blobdiff - src/tex2lyx/math.C
Really fix start_of_appendix output
[lyx.git] / src / tex2lyx / math.C
index b6ca81070934b95f2eca2dca9e9786469fbf3034..eb57b1b822b53117c96b9a90aa47f4a063690445 100644 (file)
@@ -1,29 +1,39 @@
-/** The .tex to .lyx converter
-    \author André Pönitz (2003)
+/**
+ * \file math.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author André Pönitz
+ *
+ * Full author contact details are available in file CREDITS.
  */
 
 // {[(
 
 #include <config.h>
 
-#include "Lsstream.h"
 #include "tex2lyx.h"
 
 #include <iostream>
-#include <vector>
 
 using std::cerr;
 using std::endl;
+
 using std::ostream;
-using std::vector;
+using std::string;
 
 
 bool is_math_env(string const & name)
 {
-       static char const * known_math_envs[] = { "equation", "equation*",
-       "eqnarray", "eqnarray*", "align", "align*", 0};
-
-       for (char const ** what = known_math_envs; *what; ++what)
+       static char const * 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 * const * what = known_math_envs; *what; ++what)
                if (*what == name)
                        return true;
        return false;
@@ -91,7 +101,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 ||
@@ -100,15 +109,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);
@@ -121,8 +121,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
@@ -137,7 +142,7 @@ void parse_math(Parser & p, ostream & os, unsigned flags, const mode_type mode)
                else if (t.cs() == "[") {
                        // special handling of a few common SW user quirks
                        p.skip_spaces();
-                       //if (p.next_token().cs() == 
+                       //if (p.next_token().cs() ==
                        os << "\\[";
                        parse_math(p, os, FLAG_EQUATION, MATH_MODE);
                        os << "\\]";
@@ -156,6 +161,7 @@ void parse_math(Parser & p, ostream & os, unsigned flags, const mode_type mode)
                        else
                                parse_math(p, os, FLAG_END, mode);
                        os << "\\end{" << name << "}";
+                       active_environments.pop_back();
                }
 
                else if (t.cs() == "end") {
@@ -165,7 +171,6 @@ void parse_math(Parser & p, ostream & os, unsigned flags, const mode_type mode)
                                if (name != active_environment())
                                        p.error("\\end{" + name + "} does not match \\begin{"
                                                + active_environment() + "}");
-                               active_environments.pop_back();
                                return;
                        }
                        p.error("found 'end' unexpectedly");
@@ -184,14 +189,15 @@ void parse_math(Parser & p, ostream & os, unsigned flags, const mode_type mode)
                }
 
                else if (t.cs() == "textrm" || t.cs() == "textsf" || t.cs() == "textbf"
-                               || t.cs() == "texttt" || t.cs() == "textsc") {
+                               || t.cs() == "texttt" || t.cs() == "textsc"
+                               || t.cs() == "text" || t.cs() == "intertext") {
                        os << '\\' << t.cs() << '{';
                        parse_math(p, os, FLAG_ITEM, MATHTEXT_MODE);
                        os << '}';
                }
 
-               else if (t.cs() == "mbox") {
-                       os << "\\mbox{";
+               else if (t.cs() == "mbox" || t.cs() == "fbox") {
+                       os << "\\" << t.cs() << '{';
                        parse_math(p, os, FLAG_ITEM, MATHTEXT_MODE);
                        os << '}';
                }
@@ -210,7 +216,14 @@ void parse_math(Parser & p, ostream & os, unsigned flags, const mode_type mode)
                else if (t.cs() == "ss")
                        os << "ß";
 
-               else 
+               else if (t.cs() == "cr") {
+                       // lyx can't handle \\cr
+                       cerr << "Warning: Converting TeX '\\cr' to LaTeX '\\\\'."
+                            << endl;
+                       os << "\\\\";
+               }
+
+               else
                        os << t.asInput();
 
                if (flags & FLAG_LEAVE) {