commit f44a55c3673b4d3f78dd7fb02283c7c98232bc0b
Author: Juergen Spitzmueller <[email protected]>
Date: Tue Aug 21 08:19:24 2018 +0200
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 f87ee6f..924df16 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 0d3ff01..ebc60c7 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<std::string> biblatex_bibliographies;
+ ///
+ std::string bibencoding;
+ ///
+ std::string docencoding;
private:
///
diff --git a/src/tex2lyx/TODO.txt b/src/tex2lyx/TODO.txt
index 82411c5..dfda940 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: <features rotate ="90"...>
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=<encoding>
[latex name]
- encoding=<encoding> [lyx name] BibTeX:
\bgroup\inputencoding{<encoding>}...\egroup
563 InsetArgument listpreamble:<nr> All content between \begin{env} and
first \item of a list
diff --git a/src/tex2lyx/tex2lyx.cpp b/src/tex2lyx/tex2lyx.cpp
index 89589ef..6437d99 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 54db8f6..d242731 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;