]> git.lyx.org Git - lyx.git/blobdiff - src/tex2lyx/Preamble.cpp
Fix bug in paragraph detection (can be seen in test case of bug #5187):
[lyx.git] / src / tex2lyx / Preamble.cpp
index dace26f0e3b88ff6e65f8332097967c646b6dccb..4ebfbc1c1a5f736615b447117a4a4b08812555ac 100644 (file)
@@ -165,6 +165,11 @@ const char * const known_basic_color_codes[] = {"#0000ff", "#000000", "#00ffff",
 const char * const known_if_3arg_commands[] = {"@ifundefined", "IfFileExists",
 0};
 
+/// packages that work only in xetex
+const char * const known_xetex_packages[] = {"arabxetex", "fixlatvian",
+"fontbook", "fontwrap", "mathspec", "philokalia", "polyglossia", "unisugar",
+"xeCJK", "xecolor", "xecyr", "xeindex", "xepersian", "xunicode", 0};
+
 // codes used to remove packages that are loaded automatically by LyX.
 // Syntax: package_beg_sep<name>package_mid_sep<package loading code>package_end_sep
 const char package_beg_sep = '\001';
@@ -313,6 +318,28 @@ void Preamble::suppressDate(bool suppress)
 }
 
 
+void Preamble::registerAuthor(std::string const & name)
+{
+       Author author(from_utf8(name), empty_docstring());
+       author.setUsed(true);
+       authors_.record(author);
+       h_tracking_changes = "true";
+       h_output_changes = "true";
+}
+
+
+Author const & Preamble::getAuthor(std::string const & name) const
+{
+       Author author(from_utf8(name), empty_docstring());
+       for (AuthorList::Authors::const_iterator it = authors_.begin();
+            it != authors_.end(); it++)
+               if (*it == author)
+                       return *it;
+       static Author const dummy;
+       return dummy;
+}
+
+
 void Preamble::add_package(string const & name, vector<string> & options)
 {
        // every package inherits the global options
@@ -517,6 +544,36 @@ void Preamble::handle_hyperref(vector<string> & options)
 }
 
 
+void Preamble::handle_geometry(vector<string> & options)
+{
+       h_use_geometry = "true";
+       vector<string>::iterator it;
+       // paper orientation
+       if ((it = find(options.begin(), options.end(), "landscape")) != options.end()) {
+               h_paperorientation = "landscape";
+               options.erase(it);
+       }
+       // paper size
+       // keyval version: "paper=letter"
+       string paper = process_keyval_opt(options, "paper");
+       if (!paper.empty())
+               h_papersize = paper + "paper";
+       // alternative version: "letterpaper"
+       handle_opt(options, known_paper_sizes, h_papersize);
+       delete_opt(options, known_paper_sizes);
+       // page margins
+       char const * const * margin = known_paper_margins;
+       for (; *margin; ++margin) {
+               string value = process_keyval_opt(options, *margin);
+               if (!value.empty()) {
+                       int k = margin - known_paper_margins;
+                       string name = known_coded_paper_margins[k];
+                       h_margins += '\\' + name + ' ' + value + '\n';
+               }
+       }
+}
+
+
 void Preamble::handle_package(Parser &p, string const & name,
                               string const & opts, bool in_lyx_preamble)
 {
@@ -524,6 +581,9 @@ void Preamble::handle_package(Parser &p, string const & name,
        add_package(name, options);
        string scale;
 
+       if (is_known(name, known_xetex_packages))
+               xetex = true;
+
        // roman fonts
        if (is_known(name, known_roman_fonts)) {
                h_font_roman = name;
@@ -670,7 +730,9 @@ void Preamble::handle_package(Parser &p, string const & name,
        else if (name == "url")
                ; // ignore this
 
-       else if (name == "color" || name == "subscript" || name == "ulem") {
+       else if (name == "booktabs" || name == "color" ||
+                name == "longtable" || name == "subscript" ||
+                name == "ulem") {
                if (!in_lyx_preamble)
                        h_preamble << package_beg_sep << name
                                   << package_mid_sep << "\\usepackage{"
@@ -684,8 +746,7 @@ void Preamble::handle_package(Parser &p, string const & name,
                ; // ignore this
 
        else if (name == "geometry")
-               ; // Ignore this, the geometry settings are made by the \geometry
-                 // command. This command is handled below.
+               handle_geometry(options);
 
        else if (name == "rotfloat")
                ; // ignore this
@@ -910,6 +971,7 @@ bool Preamble::writeLyXHeader(ostream & os)
           << "\\html_math_output " << h_html_math_output << "\n"
           << "\\html_css_as_file " << h_html_css_as_file << "\n"
           << "\\html_be_strict " << h_html_be_strict << "\n"
+          << authors_
           << "\\end_header\n\n"
           << "\\begin_body\n";
        // clear preamble for subdocuments
@@ -1004,7 +1066,7 @@ void Preamble::parse(Parser & p, string const & forceclass,
 
                else if (t.cs() == "color") {
                        string const space =
-                               (p.hasOpt() ? p.getArg('[', ']') : string());
+                               (p.hasOpt() ? p.getOpt() : string());
                        string argument = p.getArg('{', '}');
                        // check the case that a standard color is used
                        if (space.empty() && is_known(argument, known_basic_colors)) {
@@ -1017,7 +1079,7 @@ void Preamble::parse(Parser & p, string const & forceclass,
                        else {
                                h_preamble << t.asInput();
                                if (!space.empty())
-                                       h_preamble << '[' << space << ']';
+                                       h_preamble << space;
                                h_preamble << '{' << argument << '}';
                                // the color might already be set because \definecolor
                                // is parsed before this
@@ -1147,7 +1209,7 @@ void Preamble::parse(Parser & p, string const & forceclass,
                                opts.erase(it);
                        }
                        // paper sizes
-                       // some size options are know to any document classes, other sizes
+                       // some size options are known to any document classes, other sizes
                        // are handled by the \geometry command of the geometry package
                        handle_opt(opts, known_class_paper_sizes, h_papersize);
                        delete_opt(opts, known_class_paper_sizes);
@@ -1267,32 +1329,8 @@ void Preamble::parse(Parser & p, string const & forceclass,
                }
 
                else if (t.cs() == "geometry") {
-                       h_use_geometry = "true";
                        vector<string> opts = split_options(p.getArg('{', '}'));
-                       vector<string>::iterator it;
-                       // paper orientation
-                       if ((it = find(opts.begin(), opts.end(), "landscape")) != opts.end()) {
-                               h_paperorientation = "landscape";
-                               opts.erase(it);
-                       }
-                       // paper size
-                       handle_opt(opts, known_paper_sizes, h_papersize);
-                       delete_opt(opts, known_paper_sizes);
-                       // page margins
-                       char const * const * margin = known_paper_margins;
-                       int k = -1;
-                       for (; *margin; ++margin) {
-                               k += 1;
-                               // search for the "=" in e.g. "lmargin=2cm" to get the value
-                               for(size_t i = 0; i != opts.size(); i++) {
-                                       if (opts.at(i).find(*margin) != string::npos) {
-                                               string::size_type pos = opts.at(i).find("=");
-                                               string value = opts.at(i).substr(pos + 1);
-                                               string name = known_coded_paper_margins[k];
-                                               h_margins += "\\" + name + " " + value + "\n";
-                                       }
-                               }
-                       }
+                       handle_geometry(opts);
                }
 
                else if (t.cs() == "definecolor") {