]> git.lyx.org Git - lyx.git/blobdiff - src/tex2lyx/preamble.cpp
fix msvc linker error: for the linker struct and class isn't the same here
[lyx.git] / src / tex2lyx / preamble.cpp
index 8003e54195d8bb84d63fb77db96ba7d88182372d..8de4f3b7150869634278e1fac1172333626bc564 100644 (file)
@@ -44,6 +44,7 @@ namespace lyx {
 extern map<char, int> special_columns;
 
 map<string, vector<string> > used_packages;
+const char * const modules_placeholder = "\001modules\001";
 
 // needed to handle encodings with babel
 bool one_language = true;
@@ -200,6 +201,7 @@ string h_use_esint               = "1";
 string h_cite_engine             = "basic";
 string h_use_bibtopic            = "false";
 string h_paperorientation        = "portrait";
+string h_notefontcolor;
 string h_secnumdepth             = "3";
 string h_tocdepth                = "3";
 string h_paragraph_separation    = "indent";
@@ -673,6 +675,7 @@ void end_preamble(ostream & os, TextClass const & /*textclass*/)
        if (!h_options.empty())
                os << "\\options " << h_options << "\n";
        os << "\\use_default_options " << h_use_default_options << "\n"
+          << modules_placeholder
           << "\\language " << h_language << "\n"
           << "\\inputencoding " << h_inputencoding << "\n"
           << "\\font_roman " << h_font_roman << "\n"
@@ -718,8 +721,10 @@ void end_preamble(ostream & os, TextClass const & /*textclass*/)
           << "\\use_esint " << h_use_esint << "\n"
           << "\\cite_engine " << h_cite_engine << "\n"
           << "\\use_bibtopic " << h_use_bibtopic << "\n"
-          << "\\paperorientation " << h_paperorientation << "\n"
-          << h_margins
+          << "\\paperorientation " << h_paperorientation << '\n';
+       if (LYX_FORMAT >= 382 && !h_notefontcolor.empty())
+               os << "\\notefontcolor " << h_notefontcolor << '\n';
+       os << h_margins
           << "\\secnumdepth " << h_secnumdepth << "\n"
           << "\\tocdepth " << h_tocdepth << "\n"
           << "\\paragraph_separation " << h_paragraph_separation << "\n";
@@ -792,7 +797,6 @@ void parse_preamble(Parser & p, ostream & os,
                        h_preamble << t.asInput();
 
                else if (t.cat() == catComment) {
-                       // regex to parse comments (currently not used)
                        static regex const islyxfile("%% LyX .* created this file");
                        static regex const usercommands("User specified LaTeX commands");
 
@@ -831,9 +835,11 @@ void parse_preamble(Parser & p, ostream & os,
                        p.setCatCode('@', catOther);
                }
 
-               else if (t.cs() == "newcommand" || t.cs() == "renewcommand"
-                           || t.cs() == "providecommand"
+               else if (t.cs() == "newcommand" || t.cs() == "newcommandx"
+                     || t.cs() == "renewcommand" || t.cs() == "renewcommandx"
+                     || t.cs() == "providecommand" || t.cs() == "providecommandx"
                                || t.cs() == "DeclareRobustCommand"
+                     || t.cs() == "DeclareRobustCommandx"
                                || t.cs() == "ProvideTextCommandDefault"
                                || t.cs() == "DeclareMathAccent") {
                        bool star = false;
@@ -842,7 +848,7 @@ void parse_preamble(Parser & p, ostream & os,
                                star = true;
                        }
                        string const name = p.verbatim_item();
-                       string const opt1 = p.getOpt();
+                       string const opt1 = p.getFullOpt();
                        string const opt2 = p.getFullOpt();
                        string const body = p.verbatim_item();
                        // font settings
@@ -860,6 +866,10 @@ void parse_preamble(Parser & p, ostream & os,
                                // remove leading "\"
                                h_font_default_family = family.erase(0,1);
                        }
+
+                       // Add the command to the known commands
+                       add_known_command(name, opt1, !opt2.empty(), from_utf8(body));
+
                        // only non-lyxspecific stuff
                        if (!in_lyx_preamble) {
                                ostringstream ss;
@@ -869,9 +879,6 @@ void parse_preamble(Parser & p, ostream & os,
                                ss << '{' << name << '}' << opt1 << opt2
                                   << '{' << body << "}";
                                h_preamble << ss.str();
-
-                               // Add the command to the known commands
-                               add_known_command(name, opt1, !opt2.empty());
 /*
                                ostream & out = in_preamble ? h_preamble : os;
                                out << "\\" << t.cs() << "{" << name << "}"
@@ -894,7 +901,7 @@ void parse_preamble(Parser & p, ostream & os,
                        // options.
                        handle_opt(opts, known_languages, h_language);
                        delete_opt(opts, known_languages);
-                       
+
                        // paper orientation
                        if ((it = find(opts.begin(), opts.end(), "landscape")) != opts.end()) {
                                h_paperorientation = "landscape";
@@ -929,6 +936,8 @@ void parse_preamble(Parser & p, ostream & os,
                        delete_opt(opts, known_class_paper_sizes);
                        // the remaining options
                        h_options = join(opts, ",");
+                       // FIXME This does not work for classes that have a
+                       //       different name in LyX than in LaTeX
                        h_textclass = p.getArg('{', '}');
                }
 
@@ -952,14 +961,18 @@ void parse_preamble(Parser & p, ostream & os,
 
                else if (t.cs() == "newenvironment") {
                        string const name = p.getArg('{', '}');
-                       ostringstream ss;
-                       ss << "\\newenvironment{" << name << "}";
-                       ss << p.getOpt();
-                       ss << p.getOpt();
-                       ss << '{' << p.verbatim_item() << '}';
-                       ss << '{' << p.verbatim_item() << '}';
-                       if (!in_lyx_preamble)
-                               h_preamble << ss.str();
+                       string const opt1 = p.getFullOpt();
+                       string const opt2 = p.getFullOpt();
+                       string const beg = p.verbatim_item();
+                       string const end = p.verbatim_item();
+                       if (!in_lyx_preamble) {
+                               h_preamble << "\\newenvironment{" << name
+                                          << '}' << opt1 << opt2 << '{'
+                                          << beg << "}{" << end << '}';
+                       }
+                       add_known_environment(name, opt1, !opt2.empty(),
+                                             from_utf8(beg), from_utf8(end));
+
                }
 
                else if (t.cs() == "def") {
@@ -1068,6 +1081,21 @@ void parse_preamble(Parser & p, ostream & os,
                        }
                }
 
+               else if (t.cs() == "definecolor") {
+                       string const color = p.getArg('{', '}');
+                       string const space = p.getArg('{', '}');
+                       string const value = p.getArg('{', '}');
+                       if (LYX_FORMAT >= 382 &&
+                           color == "note_fontcolor" && space == "rgb") {
+                               RGBColor c(RGBColorFromLaTeX(value));
+                               h_notefontcolor = X11hexname(c);
+                       } else {
+                               h_preamble << "\\definecolor{" << color
+                                          << "}{" << space << "}{" << value
+                                          << '}';
+                       }
+               }
+
                else if (t.cs() == "jurabibsetup") {
                        // FIXME p.getArg('{', '}') is most probably wrong (it
                        //       does not handle nested braces).
@@ -1128,12 +1156,11 @@ void parse_preamble(Parser & p, ostream & os,
                h_textclass = forceclass;
        if (noweb_mode && !prefixIs(h_textclass, "literate-"))
                h_textclass.insert(0, "literate-");
-       FileName layoutfilename = libFileSearch("layouts", h_textclass, "layout");
-       if (layoutfilename.empty()) {
-               cerr << "Error: Could not find layout file for textclass \"" << h_textclass << "\"." << endl;
-               exit(1);
+       tc.setName(h_textclass);
+       if (!tc.load()) {
+               cerr << "Error: Could not read layout file for textclass \"" << h_textclass << "\"." << endl;
+               exit(EXIT_FAILURE);
        }
-       tc.read(layoutfilename);
        if (h_papersides.empty()) {
                ostringstream ss;
                ss << tc.sides();