]> git.lyx.org Git - lyx.git/blobdiff - src/tex2lyx/preamble.cpp
fix problem with non-recognized utf8 encoding that lead to broken .lyx
[lyx.git] / src / tex2lyx / preamble.cpp
index da4759abe6150f3c3db5d6f31b1f9cd5167c30f0..62dd2abb491dee139071574ec1488661d72227bb 100644 (file)
@@ -249,7 +249,7 @@ string const scale_as_percentage(string const & scale)
 
 
 void handle_package(string const & name, string const & opts,
-                                       bool in_lyx_preamble)
+                   bool in_lyx_preamble)
 {
        vector<string> options = split_options(opts);
        add_package(name, options);
@@ -329,15 +329,17 @@ void handle_package(string const & name, string const & opts,
                // only set when there is not more than one inputenc option
                // therefore check for the "," character
                // also only set when there is not more then one babel language option
-               if (opts.find(",") == string::npos && one_language == true)
+               if (opts.find(",") == string::npos && one_language == true) {
                        if (opts == "ascii")
                                //change ascii to auto to be in the unicode range, see
                                //http://bugzilla.lyx.org/show_bug.cgi?id=4719
                                h_inputencoding = "auto";
-                       else
+                       else if (!opts.empty())
                                h_inputencoding = opts;
+               }
                options.clear();
        }
+
        else if (name == "makeidx")
                ; // ignore this
 
@@ -507,19 +509,20 @@ void parse_preamble(Parser & p, ostream & os,
                else if (t.cat() == catComment) {
                        // regex to parse comments
                        static regex const islyxfile("%% LyX .* created this file");
-                       static regex const usercommands("User specified LaTeX commands");       
+                       static regex const usercommands("User specified LaTeX commands");
                        
                        string const comment = t.asInput();
                        cerr << "Seen comment: " << comment << std::endl;
                        smatch sub;
                        if (regex_search(comment, sub, islyxfile))
                                is_lyx_file = true;
-                       else if (is_lyx_file 
+                       else if (is_lyx_file
                                 && regex_search(comment, sub, usercommands))
                                in_lyx_preamble = false;
                        else if (!in_lyx_preamble)
                                h_preamble << t.asInput();
-                       cerr << "lyx_file: " << is_lyx_file << ", lyx_preamble " << in_lyx_preamble << std::endl;
+                       cerr << "lyx_file: " << is_lyx_file << ", lyx_preamble "
+                            << in_lyx_preamble << std::endl;
                }
 
                else if (t.cs() == "pagestyle")
@@ -527,14 +530,14 @@ void parse_preamble(Parser & p, ostream & os,
 
                else if (t.cs() == "makeatletter") {
                        if (!is_lyx_file || !in_lyx_preamble
-                               || p.getCatCode('@') != catLetter)
+                           || p.getCatCode('@') != catLetter)
                                h_preamble << "\\makeatletter";
                        p.setCatCode('@', catLetter);
                }
 
                else if (t.cs() == "makeatother") {
                        if (!is_lyx_file || !in_lyx_preamble
-                               || p.getCatCode('@') != catOther)
+                           || p.getCatCode('@') != catOther)
                                h_preamble << "\\makeatother";
                        p.setCatCode('@', catOther);
                }
@@ -658,13 +661,17 @@ void parse_preamble(Parser & p, ostream & os,
                                vector<string>::const_iterator it  = vecnames.begin();
                                vector<string>::const_iterator end = vecnames.end();
                                for (; it != end; ++it)
-                                       handle_package(trim(*it), string(),
-                                       in_lyx_preamble);
+                                       handle_package(trim(*it), string(), 
+                                                      in_lyx_preamble);
                        } else {
                                handle_package(name, options, in_lyx_preamble);
                        }
                }
 
+               else if (t.cs() == "inputencoding") {
+                       h_inputencoding = p.getArg('{','}');
+               }
+
                else if (t.cs() == "newenvironment") {
                        string const name = p.getArg('{', '}');
                        ostringstream ss;
@@ -683,7 +690,7 @@ void parse_preamble(Parser & p, ostream & os,
                                name += p.get_token().asString();
                        if (!in_lyx_preamble)
                                h_preamble << "\\def\\" << name << '{'
-                               << p.verbatim_item() << "}";
+                                          << p.verbatim_item() << "}";
                }
 
                else if (t.cs() == "newcolumntype") {