From f44a55c3673b4d3f78dd7fb02283c7c98232bc0b Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Tue, 21 Aug 2018 08:19:24 +0200 Subject: [PATCH] tex2lyx: add bib encoding support. --- src/tex2lyx/Preamble.cpp | 3 +++ src/tex2lyx/Preamble.h | 4 ++++ src/tex2lyx/TODO.txt | 3 --- src/tex2lyx/tex2lyx.cpp | 2 ++ src/tex2lyx/text.cpp | 18 ++++++++++++++++++ 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp index f87ee6f853..924df16929 100644 --- a/src/tex2lyx/Preamble.cpp +++ b/src/tex2lyx/Preamble.cpp @@ -1211,6 +1211,9 @@ void Preamble::handle_package(Parser &p, string const & name, cerr << "Ignoring unkown refesection value '" << opt << "'."; } + opt = process_keyval_opt(options, "bibencoding"); + if (!opt.empty()) + bibencoding = opt; if (!options.empty()) { h_biblio_options = join(options, ","); options.clear(); diff --git a/src/tex2lyx/Preamble.h b/src/tex2lyx/Preamble.h index 0d3ff0113f..ebc60c7d6d 100644 --- a/src/tex2lyx/Preamble.h +++ b/src/tex2lyx/Preamble.h @@ -108,6 +108,10 @@ public: static const char * const coded_polyglossia_languages[]; /// std::vector biblatex_bibliographies; + /// + std::string bibencoding; + /// + std::string docencoding; private: /// diff --git a/src/tex2lyx/TODO.txt b/src/tex2lyx/TODO.txt index 82411c58b2..dfda94001c 100644 --- a/src/tex2lyx/TODO.txt +++ b/src/tex2lyx/TODO.txt @@ -45,9 +45,6 @@ Format LaTeX feature LyX feature \begin{landscape}...\end{landscape} \begin_inset Flex Landscape with longtable content: 555 V column type (varwidth package) Automatically detected with newlines, paragraph breaks and environment content in cells of rows -556 Bib files encoding - \begin_inset CommandInset bibtex Biblatex: bibencoding= [latex name] - encoding= [lyx name] BibTeX: \bgroup\inputencoding{}...\egroup 563 InsetArgument listpreamble: All content between \begin{env} and first \item of a list diff --git a/src/tex2lyx/tex2lyx.cpp b/src/tex2lyx/tex2lyx.cpp index 89589ef706..6437d9902d 100644 --- a/src/tex2lyx/tex2lyx.cpp +++ b/src/tex2lyx/tex2lyx.cpp @@ -960,6 +960,8 @@ bool tex2lyx(FileName const & infilename, ostream & os, string encoding, encoding = enc->iconvName(); else encoding = "ISO-8859-1"; + // store + preamble.docencoding = encoding; } ifdocstream is(setEncoding(encoding)); diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index 54db8f63f5..d242731b79 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -5091,6 +5091,15 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, bibliographystyle.clear(); } os << "options " << '"' << BibOpts << '"' << "\n"; + if (p.getEncoding() != preamble.docencoding) { + Encoding const * const enc = encodings.fromIconvName( + p.getEncoding(), Encoding::inputenc, true); + if (!enc) { + cerr << "Unknown bib encoding " << p.getEncoding() + << ". Ignoring." << std::endl; + } else + os << "encoding " << '"' << enc->name() << '"' << "\n"; + } end_inset(os); continue; } @@ -5131,6 +5140,15 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, os << "options " << '"' << BibOpts << '"' << "\n"; if (!bbloptions.empty()) os << "biblatexopts " << '"' << bbloptions << '"' << "\n"; + if (!preamble.bibencoding.empty()) { + Encoding const * const enc = encodings.fromLaTeXName( + preamble.bibencoding, Encoding::inputenc, true); + if (!enc) { + cerr << "Unknown bib encoding " << preamble.bibencoding + << ". Ignoring." << std::endl; + } else + os << "encoding " << '"' << enc->name() << '"' << "\n"; + } end_inset(os); need_commentbib = false; continue; -- 2.39.2