]> git.lyx.org Git - lyx.git/blobdiff - src/tex2lyx/math.C
Bug fix; ensure that all is Ok after the combox is moved with
[lyx.git] / src / tex2lyx / math.C
index b02a58c88a7dee0a8dc1488176d0a47741d1faa1..ea3cc9d4e03374e0718bf74127466452b611aa73 100644 (file)
@@ -1,29 +1,36 @@
-/** 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 <string>
-#include <vector>
 
 using std::cerr;
 using std::endl;
+
 using std::ostream;
 using std::string;
-using std::vector;
 
 
 bool is_math_env(string const & name)
 {
        static char const * known_math_envs[] = { "equation", "equation*",
-       "eqnarray", "eqnarray*", "align", "align*", 0};
+       "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)
@@ -35,7 +42,7 @@ bool is_math_env(string const & name)
 void parse_math(Parser & p, ostream & os, unsigned flags, const mode_type mode)
 {
        while (p.good()) {
-               Token const & t = p.getToken();
+               Token const & t = p.get_token();
 
 #ifdef FILEDEBUG
                cerr << "t: " << t << " flags: " << flags << "\n";
@@ -64,13 +71,13 @@ void parse_math(Parser & p, ostream & os, unsigned flags, const mode_type mode)
                if (t.cat() == catMath) {
                        if (mode == MATHTEXT_MODE) {
                                // we are inside some text mode thingy, so opening new math is allowed
-                               Token const & n = p.getToken();
+                               Token const & n = p.get_token();
                                if (n.cat() == catMath) {
                                        // TeX's $$...$$ syntax for displayed math
                                        os << "\\[";
                                        parse_math(p, os, FLAG_SIMPLE, MATH_MODE);
                                        os << "\\]";
-                                       p.getToken(); // skip the second '$' token
+                                       p.get_token(); // skip the second '$' token
                                } else {
                                        // simple $...$  stuff
                                        p.putback();
@@ -93,7 +100,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 ||
@@ -102,15 +108,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.nextToken().cat() == catNewline) {
-                       //      p.getToken();
-                       //      handle_par(os);
-                       //} else {
-                               os << "\n "; // note the space
-                       //}
-               }
-
                else if (t.cat() == catBegin) {
                        os << '{';
                        parse_math(p, os, FLAG_BRACE_LAST, mode);
@@ -123,8 +120,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,6 +139,9 @@ 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() ==
                        os << "\\[";
                        parse_math(p, os, FLAG_EQUATION, MATH_MODE);
                        os << "\\]";
@@ -148,23 +153,23 @@ void parse_math(Parser & p, ostream & os, unsigned flags, const mode_type mode)
 
                else if (t.cs() == "begin") {
                        string const name = p.getArg('{', '}');
-                       active_environments_push(name);
+                       active_environments.push_back(name);
                        os << "\\begin{" << name << "}";
                        if (name == "tabular")
                                parse_math(p, os, FLAG_END, MATHTEXT_MODE);
                        else
                                parse_math(p, os, FLAG_END, mode);
                        os << "\\end{" << name << "}";
+                       active_environments.pop_back();
                }
 
                else if (t.cs() == "end") {
                        if (flags & FLAG_END) {
                                // eat environment name
                                string const name = p.getArg('{', '}');
-                               if (name != curr_env())
+                               if (name != active_environment())
                                        p.error("\\end{" + name + "} does not match \\begin{"
-                                               + curr_env() + "}");
-                               active_environments_pop();
+                                               + active_environment() + "}");
                                return;
                        }
                        p.error("found 'end' unexpectedly");
@@ -183,20 +188,21 @@ 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 << '}';
                }
 
                else if (t.cs() == "\"") {
-                       string const name = p.verbatimItem();
+                       string const name = p.verbatim_item();
                             if (name == "a") os << 'ä';
                        else if (name == "o") os << 'ö';
                        else if (name == "u") os << 'ü';
@@ -209,7 +215,7 @@ void parse_math(Parser & p, ostream & os, unsigned flags, const mode_type mode)
                else if (t.cs() == "ss")
                        os << "ß";
 
-               else 
+               else
                        os << t.asInput();
 
                if (flags & FLAG_LEAVE) {