]> git.lyx.org Git - lyx.git/blobdiff - src/tex2lyx/Preamble.cpp
Fix "stray '}' in text" warnings: When parsing with FLAG_ITEM the braces need
[lyx.git] / src / tex2lyx / Preamble.cpp
index ad472f89ec75839d315bd721e9fafa252828540a..c0b3cb9ac4cc9e81d54b889f10a42c6a6ec3cb14 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
@@ -524,6 +551,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;
@@ -599,7 +629,6 @@ void Preamble::handle_package(Parser &p, string const & name,
                // we need to keep it in the preamble to prevent cases like bug #7861.
                if (!opts.empty()) {
                        // check if more than one option was used - used later for inputenc
-                       // in case inputenc is parsed before babel, set the encoding to auto
                        if (options.begin() != options.end() - 1)
                                one_language = false;
                        // babel takes the last language of the option of its \usepackage
@@ -634,8 +663,8 @@ void Preamble::handle_package(Parser &p, string const & name,
                // inputenc option because otherwise h_inputencoding must be
                // set to "auto" (the default encoding of the document language)
                // Therefore check for the "," character.
-               // It is also only set when there is not more then one babel
-               // language option but this is handled in the routine for babel.
+               // It is also only set when there is not more than one babel
+               // language option.
                if (opts.find(",") == string::npos && one_language == true)
                        h_inputencoding = opts;
                if (!options.empty())
@@ -671,10 +700,7 @@ void Preamble::handle_package(Parser &p, string const & name,
        else if (name == "url")
                ; // ignore this
 
-       else if (name == "subscript")
-               ; // ignore this
-
-       else if (name == "color") {
+       else if (name == "color" || name == "subscript" || name == "ulem") {
                if (!in_lyx_preamble)
                        h_preamble << package_beg_sep << name
                                   << package_mid_sep << "\\usepackage{"
@@ -687,13 +713,6 @@ void Preamble::handle_package(Parser &p, string const & name,
        else if (name == "setspace")
                ; // ignore this
 
-#if 0
-       // do not ignore as long as we don't support all commands (e.g. \xout is missing)
-       // and as long as we don't support change tracking
-       else if (name == "ulem")
-               ; // ignore this
-#endif
-
        else if (name == "geometry")
                ; // Ignore this, the geometry settings are made by the \geometry
                  // command. This command is handled below.
@@ -921,6 +940,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
@@ -1014,17 +1034,22 @@ void Preamble::parse(Parser & p, string const & forceclass,
                }
 
                else if (t.cs() == "color") {
+                       string const space =
+                               (p.hasOpt() ? p.getOpt() : string());
                        string argument = p.getArg('{', '}');
                        // check the case that a standard color is used
-                       if (is_known(argument, known_basic_colors)) {
+                       if (space.empty() && is_known(argument, known_basic_colors)) {
                                h_fontcolor = rgbcolor2code(argument);
                                preamble.registerAutomaticallyLoadedPackage("color");
-                       } else if (argument == "document_fontcolor")
+                       } else if (space.empty() && argument == "document_fontcolor")
                                preamble.registerAutomaticallyLoadedPackage("color");
                        // check the case that LyX's document_fontcolor is defined
                        // but not used for \color
                        else {
-                               h_preamble << t.asInput() << '{' << argument << '}';
+                               h_preamble << t.asInput();
+                               if (!space.empty())
+                                       h_preamble << space;
+                               h_preamble << '{' << argument << '}';
                                // the color might already be set because \definecolor
                                // is parsed before this
                                h_fontcolor = "";