]> git.lyx.org Git - lyx.git/blobdiff - src/tex2lyx/text.cpp
InsetParamsDialog: fix Restore button enabling/disabling.
[lyx.git] / src / tex2lyx / text.cpp
index eb88a9695810b32c9809eb5034eeffba54bafc91..4f5b60e6092292b0f6053ca9d451cc961591f5e9 100644 (file)
@@ -454,17 +454,37 @@ void output_command_layout(ostream & os, Parser & p, bool outer,
        }
        context.check_deeper(os);
        context.check_layout(os);
-       if (context.layout->optionalargs > 0) {
+       unsigned int optargs = 0;
+       while (optargs < context.layout->optargs) {
                eat_whitespace(p, os, context, false);
-               if (p.next_token().character() == '[') {
-                       p.get_token(); // eat '['
-                       begin_inset(os, "OptArg\n");
-                       os << "status collapsed\n\n";
-                       parse_text_in_inset(p, os, FLAG_BRACK_LAST, outer, context);
-                       end_inset(os);
-                       eat_whitespace(p, os, context, false);
-               }
+               if (p.next_token().character() != '[') 
+                       break;
+               p.get_token(); // eat '['
+               begin_inset(os, "OptArg\n");
+               os << "status collapsed\n\n";
+               parse_text_in_inset(p, os, FLAG_BRACK_LAST, outer, context);
+               end_inset(os);
+               eat_whitespace(p, os, context, false);
+               optargs++;
+       }
+#if 0
+       // This is the code needed to parse required arguments, but 
+       // required arguments come into being only much later than the
+       // file format tex2lyx is presently outputting.
+       unsigned int reqargs = 0;
+       while (reqargs < context.layout->reqargs) {
+               eat_whitespace(p, os, context, false);
+               if (p.next_token().character() != '{') 
+                       break;
+               p.get_token(); // eat '{'
+               begin_inset(os, "OptArg\n");
+               os << "status collapsed\n\n";
+               parse_text_in_inset(p, os, FLAG_BRACE_LAST, outer, context);
+               end_inset(os);
+               eat_whitespace(p, os, context, false);
+               reqargs++;
        }
+#endif
        parse_text(p, os, FLAG_ITEM, outer, context);
        context.check_end_layout(os);
        if (parent_context.deeper_paragraph) {
@@ -1041,7 +1061,7 @@ void fix_relative_filename(string & name)
        if (FileName::isAbsolute(name))
                return;
 
-       name = to_utf8(makeRelPath(from_utf8(makeAbsPath(name, getMasterFilePath()).absFilename()),
+       name = to_utf8(makeRelPath(from_utf8(makeAbsPath(name, getMasterFilePath()).absFileName()),
                                   from_utf8(getParentFilePath())));
 }
 
@@ -1121,8 +1141,6 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                Context & context)
 {
        Layout const * newlayout = 0;
-       // store the current selectlanguage to be used after \foreignlanguage
-       string selectlang;
        // Store the latest bibliographystyle (needed for bibtex inset)
        string bibliographystyle;
        bool const use_natbib = used_packages.find("natbib") != used_packages.end();
@@ -1152,6 +1170,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
 
                if (t.character() == ']' && (flags & FLAG_BRACK_LAST))
                        return;
+               if (t.character() == '}' && (flags & FLAG_BRACE_LAST))
+                       return;
 
                //
                // cat codes
@@ -1484,9 +1504,9 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                                else
                                                        simple = false;
                                        } else
-                                               paramtext += p.get_token().asString();
+                                               paramtext += p.get_token().cs();
                                } else {
-                                       paramtext += p.get_token().asString();
+                                       paramtext += p.get_token().cs();
                                        simple = false;
                                }
                        }
@@ -1816,7 +1836,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
 
                else if (t.cs() == "listof") {
                        p.skip_spaces(true);
-                       string const name = p.get_token().asString();
+                       string const name = p.get_token().cs();
                        if (context.textclass.floats().typeExist(name)) {
                                context.check_layout(os);
                                begin_inset(os, "FloatList ");
@@ -1983,10 +2003,14 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        if (!after.empty()) {
                                after.erase(0, 1);
                                after.erase(after.length() - 1, 1);
+                               // LyX cannot handle newlines in the parameter
+                               after = subst(after, "\n", " ");
                        }
                        if (!before.empty()) {
                                before.erase(0, 1);
                                before.erase(before.length() - 1, 1);
+                               // LyX cannot handle newlines in the parameter
+                               before = subst(before, "\n", " ");
                        }
                        begin_inset(os, "LatexCommand ");
                        os << t.cs() << "\n";
@@ -2215,10 +2239,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        // save the language for the case that a
                        // \foreignlanguage is used 
 
-                       //FIXME: this is wrong, the language should
-                       // be saved in the context. (JMarc)
-                       selectlang = subst(p.verbatim_item(), "\n", " ");
-                       os << "\\lang " << selectlang << "\n";
+                       context.font.language = subst(p.verbatim_item(), "\n", " ");
+                       os << "\\lang " << context.font.language << "\n";
                }
 
                else if (t.cs() == "foreignlanguage") {
@@ -2229,7 +2251,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        // has to be parsed (like for \textsf, for
                        // example). 
                        // set back to last selectlanguage
-                       os << "\n\\lang " << selectlang << "\n";
+                       os << "\n\\lang " << context.font.language << "\n";
                }
 
                else if (t.cs() == "inputencoding") {
@@ -2269,6 +2291,12 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        skip_braces(p);
                }
 
+               else if (t.cs() == "textquotedbl") {
+                       context.check_layout(os);
+                       os << "\"";
+                       skip_braces(p);
+               }
+
                else if (t.cs() == "@" && p.next_token().asInput() == ".") {
                        context.check_layout(os);
                        os << "\\SpecialChar \\@.\n";
@@ -2401,7 +2429,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        }
                        if (makeAbsPath(filename, path).exists()) {
                                string const abstexname =
-                                       makeAbsPath(filename, path).absFilename();
+                                       makeAbsPath(filename, path).absFileName();
                                string const abslyxname =
                                        changeExtension(abstexname, ".lyx");
                                fix_relative_filename(filename);