commit 035d5399645c1176af8690adec7e15fe1d963e78
Author: Juergen Spitzmueller <[email protected]>
Date:   Fri Mar 29 15:50:18 2019 +0100

    tex2lyx: support for bibencoding argument of \addbibresource
---
 src/tex2lyx/Preamble.cpp |   23 ++++++++++++++++++++++-
 src/tex2lyx/Preamble.h   |    2 ++
 src/tex2lyx/text.cpp     |   16 ++++++++++++++++
 3 files changed, 40 insertions(+), 1 deletions(-)

diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp
index 924df16..b0ac779 100644
--- a/src/tex2lyx/Preamble.cpp
+++ b/src/tex2lyx/Preamble.cpp
@@ -1752,7 +1752,28 @@ void Preamble::parse(Parser & p, string const & 
forceclass,
                }
 
                if (t.cs() == "addbibresource") {
-                       
biblatex_bibliographies.push_back(removeExtension(p.getArg('{', '}')));
+                       string const options =  p.getArg('[', ']');
+                       string const arg = removeExtension(p.getArg('{', '}'));
+                       if (!options.empty()) {
+                               // check if the option contains a bibencoding, 
if yes, extract it
+                               string::size_type pos = 
options.find("bibencoding=");
+                               string encoding;
+                               if (pos != string::npos) {
+                                       string::size_type i = options.find(',', 
pos);
+                                       if (i == string::npos)
+                                               encoding = options.substr(pos + 
1);
+                                       else
+                                               encoding = options.substr(pos, 
i - pos);
+                                       pos = encoding.find('=');
+                                       if (pos == string::npos)
+                                               encoding.clear();
+                                       else
+                                               encoding = encoding.substr(pos 
+ 1);
+                               }
+                               if (!encoding.empty())
+                                       
biblatex_encodings.push_back(normalize_filename(arg) + ' ' + encoding);
+                       }
+                       biblatex_bibliographies.push_back(arg);
                        continue;
                }
 
diff --git a/src/tex2lyx/Preamble.h b/src/tex2lyx/Preamble.h
index 804e5ca..63b812b 100644
--- a/src/tex2lyx/Preamble.h
+++ b/src/tex2lyx/Preamble.h
@@ -113,6 +113,8 @@ public:
        ///
        std::vector<std::string> biblatex_bibliographies;
        ///
+       std::vector<std::string> biblatex_encodings;
+       ///
        std::string bibencoding;
        ///
        std::string docencoding;
diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp
index badae84..4dd5fa7 100644
--- a/src/tex2lyx/text.cpp
+++ b/src/tex2lyx/text.cpp
@@ -5344,6 +5344,14 @@ void parse_text(Parser & p, ostream & os, unsigned 
flags, bool outer,
                                } else
                                        os << "encoding " << '"' << enc->name() 
<< '"' << "\n";
                        }
+                       string bibfileencs;
+                       for (auto const & bf : preamble.biblatex_encodings) {
+                               if (!bibfileencs.empty())
+                                       bibfileencs += "\t";
+                               bibfileencs += bf;
+                       }
+                       if (!bibfileencs.empty())
+                               os << "file_encodings " << '"' << bibfileencs 
<< '"' << "\n";
                        end_inset(os);
                        need_commentbib = false;
                        continue;
@@ -6209,6 +6217,14 @@ void check_comment_bib(ostream & os, Context & context)
        }
        if (!bibfiles.empty())
                os << "bibfiles " << '"' << bibfiles << '"' << "\n";
+       string bibfileencs;
+       for (auto const & bf : preamble.biblatex_encodings) {
+               if (!bibfileencs.empty())
+                       bibfileencs += "\t";
+               bibfileencs += bf;
+       }
+       if (!bibfileencs.empty())
+               os << "file_encodings " << '"' << bibfileencs << '"' << "\n";
        end_inset(os);// Bibtex
        os << "\\end_layout\n";
        end_inset(os);// Note

Reply via email to