]> git.lyx.org Git - features.git/commitdiff
tex2lyx:
authorUwe Stöhr <uwestoehr@web.de>
Sun, 14 Jun 2009 02:16:51 +0000 (02:16 +0000)
committerUwe Stöhr <uwestoehr@web.de>
Sun, 14 Jun 2009 02:16:51 +0000 (02:16 +0000)
- correct the conversion of InsetCommand
- code optimization
- support for format 253: nomenclature is now recognized

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30093 a592a061-630c-0410-9148-cb99ea01b6c8

src/tex2lyx/Parser.cpp
src/tex2lyx/Parser.h
src/tex2lyx/preamble.cpp
src/tex2lyx/text.cpp

index 8fbadfef2483e642b7f7f2e45e2829a10f6fcede..fdfcc38bc51b9b0980f0a789b68467e0dbd14560 100644 (file)
@@ -334,6 +334,14 @@ string Parser::getOpt()
 }
 
 
+string Parser::getOptContent()
+// the same as getOpt but without the brackets
+{
+       string const res = getArg('[', ']');
+       return res.empty() ? string() : res;
+}
+
+
 string Parser::getFullParentheseArg()
 {
        Arg arg = getFullArg('(', ')');
index c79296175e8144ee2982f3763601943d9da5faed..ed2c7211ebfec3baba86ab3fa5a136595519f1f8 100644 (file)
@@ -158,9 +158,13 @@ public:
         */
        std::string getOpt();
        /*!
-        * \returns getFullArg('(', ')') including the parentheses or the
+        * \returns getFullArg('[', ']') including the parentheses or the
         * empty string if there is no such argument.
         */
+       std::string getOptContent();
+       /*!
+        * the same as getOpt but without the brackets
+        */
        std::string getFullParentheseArg();
        /*!
         * \returns the contents of the environment \p name.
index 33e4fabedc34d8209be05409e4df561d4b48edd5..0b1f426ab9999de642069207112e60e33cc87755 100644 (file)
@@ -452,7 +452,7 @@ void handle_package(Parser &p, string const & name, string const & opts,
 void end_preamble(ostream & os, TextClass const & /*textclass*/)
 {
        os << "#LyX file created by tex2lyx " << PACKAGE_VERSION << "\n"
-          << "\\lyxformat 252\n"
+          << "\\lyxformat 253\n"
           << "\\begin_document\n"
           << "\\begin_header\n"
           << "\\textclass " << h_textclass << "\n";
index 218b6cbcee88a3dbefa04f1b418c47cce1ce2693..05d0a0bdf4097dcb40910cc6e26675e0b3b30709 100644 (file)
@@ -354,12 +354,13 @@ void begin_inset(ostream & os, string const & name)
        os << "\n\\begin_inset " << name;
 }
 
+/*// use this voi when format 288 is supported
 void begin_command_inset(ostream & os, string const & name,
                                                 string const & latexname)
 {
        os << "\n\\begin_inset CommandInset " << name;
        os << "\nLatexCommand " << latexname << "\n";
-}
+}*/
 
 
 void end_inset(ostream & os)
@@ -1464,7 +1465,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                else if (t.cs() == "bibitem") {
                        context.set_item();
                        context.check_layout(os);
-                       begin_command_inset(os, "bibitem", "bibitem");
+                       begin_inset(os, "LatexCommand ");
+                       os << t.cs() << "\n";
                        os << p.getOpt();
                        os << "key " << '"' << p.verbatim_item() << '"' << "\n";
                        end_inset(os);
@@ -1784,7 +1786,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                else if (t.cs() == "tableofcontents") {
                        p.skip_spaces();
                        context.check_layout(os);
-                       begin_command_inset(os, "toc", "tableofcontents");
+                       begin_inset(os, "LatexCommand ");
+                       os << t.cs() << "\n";
                        end_inset(os);
                        skip_braces(p); // swallow this
                }
@@ -1922,7 +1925,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
 
                else if (is_known(t.cs(), known_ref_commands)) {
                        context.check_layout(os);
-                       begin_command_inset(os, "ref", t.cs());
+                       begin_inset(os, "LatexCommand ");
+                       os << t.cs() << "\n";
                        // lyx cannot handle newlines in a latex command
                        // FIXME: Move the substitution into parser::getOpt()?
                        os << subst(p.getOpt(), "\n", " ");
@@ -1978,7 +1982,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                before.erase(0, 1);
                                before.erase(before.length() - 1, 1);
                        }
-                       begin_command_inset(os, "citation", command);
+                       begin_inset(os, "LatexCommand ");
+                       os << t.cs() << "\n";
                        os << "after " << '"' << after << '"' << "\n";
                        os << "before " << '"' << before << '"' << "\n";
                        os << "key " << '"' << p.verbatim_item() << '"' << "\n";
@@ -2022,7 +2027,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                before.erase(0, 1);
                                before.erase(before.length() - 1, 1);
                        }
-                       begin_command_inset(os, "citation", command);
+                       begin_inset(os, "LatexCommand ");
+                       os << t.cs() << "\n";
                        os << "after " << '"' << after << '"' << "\n";
                        os << "before " << '"' << before << '"' << "\n";
                        os << "key " << '"' << citation << '"' << "\n";
@@ -2032,12 +2038,9 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                else if (t.cs() == "cite") {
                        context.check_layout(os);
                        // lyx cannot handle newlines in a latex command
-                       string after = subst(p.getOpt(), "\n", " ");
-                       if (!after.empty()) {
-                               after.erase(0, 1);
-                               after.erase(after.length() - 1, 1);
-                       }
-                       begin_command_inset(os, "citation", t.cs());
+                       string after = subst(p.getOptContent(), "\n", " ");
+                       begin_inset(os, "LatexCommand ");
+                       os << t.cs() << "\n";
                        os << "after " << '"' << after << '"' << "\n";
                        os << "key " << '"' << subst(p.verbatim_item(), "\n", " ") << '"' << "\n";
                        end_inset(os);
@@ -2046,15 +2049,29 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                else if (t.cs() == "index") {
                        context.check_layout(os);
                        begin_inset(os, "LatexCommand ");
-                       os << t.cs() << "\n";;
+                       os << t.cs() << "\n";
                        // lyx cannot handle newlines in a latex command
                        os << "name " << '"' << subst(p.verbatim_item(), "\n", " ") << '"' << "\n";
                        end_inset(os);
                }
+
+               else if (t.cs() == "nomenclature") {
+                       context.check_layout(os);
+                       begin_inset(os, "LatexCommand ");
+                       os << t.cs() << "\n";
+                       // lyx cannot handle newlines in a latex command
+                       string prefix = subst(p.getOptContent(), "\n", " ");
+                       if (!prefix.empty())
+                               os << "prefix " << '"' << prefix << '"' << "\n";
+                       os << "symbol " << '"' << subst(p.verbatim_item(), "\n", " ") << '"' << "\n";
+                       os << "description " << '"' << subst(p.verbatim_item(), "\n", " ") << '"' << "\n";
+                       end_inset(os);
+               }
                
                else if (t.cs() == "label") {
                        context.check_layout(os);
-                       begin_command_inset(os, t.cs(), t.cs());
+                       begin_inset(os, "LatexCommand ");
+                       os << t.cs() << "\n";
                        // lyx cannot handle newlines in a latex command
                        os << "name " << '"' << subst(p.verbatim_item(), "\n", " ") << '"' << "\n";
                        end_inset(os);
@@ -2062,7 +2079,16 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
 
                else if (t.cs() == "printindex") {
                        context.check_layout(os);
-                       begin_command_inset(os, "index_print", t.cs());
+                       begin_inset(os, "LatexCommand ");
+                       os << t.cs() << "\n";
+                       end_inset(os);
+                       skip_braces(p);
+               }
+
+               else if (t.cs() == "printnomenclature") {
+                       context.check_layout(os);
+                       begin_inset(os, "LatexCommand ");
+                       os << t.cs() << "\n";
                        end_inset(os);
                        skip_braces(p);
                }
@@ -2070,7 +2096,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                else if (t.cs() == "url") {
                        context.check_layout(os);
                        begin_inset(os, "LatexCommand ");
-                       os << t.cs() << "\n";;
+                       os << t.cs() << "\n";
                        // lyx cannot handle newlines in a latex command
                        os << "target " << '"' << subst(p.verbatim_item(), "\n", " ") << '"' << "\n";
                        end_inset(os);
@@ -2401,7 +2427,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
 
                else if (t.cs() == "bibliography") {
                        context.check_layout(os);
-                       begin_command_inset(os, "bibtex", "bibtex");
+                       begin_inset(os, "LatexCommand ");
+                       os << "bibtex" << "\n";
                        os << "bibfiles " << '"' << p.verbatim_item() << '"' << "\n";
                        // Do we have a bibliographystyle set?
                        if (!bibliographystyle.empty())