diff --git a/src/tex2lyx/preamble.cpp b/src/tex2lyx/preamble.cpp index 8de4f3b715..df9462dbe9 100644 --- a/src/tex2lyx/preamble.cpp +++ b/src/tex2lyx/preamble.cpp @@ -48,6 +48,7 @@ const char * const modules_placeholder = "\001modules\001"; // needed to handle encodings with babel bool one_language = true; +string h_inputencoding = "auto"; namespace { @@ -165,7 +166,6 @@ string h_textclass = "article"; string h_use_default_options = "false"; string h_options; string h_language = "english"; -string h_inputencoding = "auto"; string h_font_roman = "default"; string h_font_sans = "default"; string h_font_typewriter = "default"; @@ -517,7 +517,7 @@ void handle_package(Parser &p, string const & name, string const & opts, else if (name == "fontenc") ;// ignore this - else if (name == "inputenc") { + else if (name == "inputenc" || name == "luainputenc") { // h_inputencoding is only set when there is not more than one // inputenc option because otherwise h_inputencoding must be // set to "auto" (the default encoding of the document language) diff --git a/src/tex2lyx/tex2lyx.cpp b/src/tex2lyx/tex2lyx.cpp index 958e4a7eb3..8d5e858885 100644 --- a/src/tex2lyx/tex2lyx.cpp +++ b/src/tex2lyx/tex2lyx.cpp @@ -624,11 +624,22 @@ namespace { * You must ensure that \p parentFilePath is properly set before calling * this function! */ -void tex2lyx(idocstream & is, ostream & os, string const & encoding) +void tex2lyx(idocstream & is, ostream & os, string encoding) { + // Set a sensible default encoding. + // This is used until an encoding command is found. + // For child documents use the encoding of the master, else latin1, + // since latin1 does not cause an iconv error if the actual encoding + // is different (bug 7509). + if (encoding.empty()) { + if (h_inputencoding == "auto") + encoding = "latin1"; + else + encoding = h_inputencoding; + } + Parser p(is); - if (!encoding.empty()) - p.setEncoding(encoding); + p.setEncoding(encoding); //p.dump(); ostringstream ps; diff --git a/src/tex2lyx/tex2lyx.h b/src/tex2lyx/tex2lyx.h index 6a3057f188..f2bde2e8cb 100644 --- a/src/tex2lyx/tex2lyx.h +++ b/src/tex2lyx/tex2lyx.h @@ -52,6 +52,7 @@ extern std::string babel2lyx(std::string const & language); /// used packages with options extern std::map > used_packages; extern const char * const modules_placeholder; +extern std::string h_inputencoding; /// in text.cpp std::string translate_len(std::string const &);