From 1a3dbbf07ad837a685af93bf3d1d1a784e0d27ae Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Sun, 4 Mar 2018 17:29:59 +0100 Subject: [PATCH] tex2lyx: refsection and bibbysection support (biblatex) --- src/tex2lyx/Preamble.cpp | 12 ++++++++++++ src/tex2lyx/Preamble.h | 1 + src/tex2lyx/TODO.txt | 6 +----- src/tex2lyx/text.cpp | 29 +++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp index 48c0033a62..cd8b5143a0 100644 --- a/src/tex2lyx/Preamble.cpp +++ b/src/tex2lyx/Preamble.cpp @@ -1073,6 +1073,16 @@ void Preamble::handle_package(Parser &p, string const & name, if (!opt.empty()) h_biblatex_bibstyle = opt; } + opt = process_keyval_opt(options, "refsection"); + if (!opt.empty()) { + if (opt == "none" || opt == "part" + || opt == "chapter" || opt == "section" + || opt == "subsection") + h_multibib = opt; + else + cerr << "Ignoring unkown refesection value '" + << opt << "'."; + } if (!options.empty()) { h_biblio_options = join(options, ","); options.clear(); @@ -1312,6 +1322,8 @@ bool Preamble::writeLyXHeader(ostream & os, bool subdoc, string const & outfiled os << "\\biblatex_bibstyle " << h_biblatex_bibstyle << "\n"; if (!h_biblatex_citestyle.empty()) os << "\\biblatex_citestyle " << h_biblatex_citestyle << "\n"; + if (!h_multibib.empty()) + os << "\\multibib " << h_multibib << "\n"; os << "\\use_indices " << h_use_indices << "\n" << "\\paperorientation " << h_paperorientation << '\n' << "\\suppress_date " << h_suppress_date << '\n' diff --git a/src/tex2lyx/Preamble.h b/src/tex2lyx/Preamble.h index 389bf5e48a..074a85c613 100644 --- a/src/tex2lyx/Preamble.h +++ b/src/tex2lyx/Preamble.h @@ -133,6 +133,7 @@ private: std::ostringstream h_preamble; std::string h_backgroundcolor; + std::string h_multibib; std::string h_biblio_style; std::string h_biblio_options; std::string h_biblatex_bibstyle; diff --git a/src/tex2lyx/TODO.txt b/src/tex2lyx/TODO.txt index f5744e7f93..e5488b5936 100644 --- a/src/tex2lyx/TODO.txt +++ b/src/tex2lyx/TODO.txt @@ -114,13 +114,9 @@ Format LaTeX feature LyX feature Same for: \Cites, \textcites, \Textcites, \parencites, \Parencites, \smartcites, \Smartcites, \autocites, Autocites 533 Multibib support - \begin{btUnit}...\end{btUnit} \multibib {none|part|chapter|section|subsetion} + \begin{btUnit}...\end{btUnit} \multibib {none|part|chapter|section|subsection} (if a part, chapter, section etc. follows the \begin...) - \usepackage[refsection= \multibib - \bibbysection[] \begin_inset CommandInset bibtex - biblatexopts "" - btprint "bibbysection" 534 Chapterbib support \usepackage{chapterbib} \multibib child diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index 8b8dc6180f..559aa735b5 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -4671,6 +4671,35 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, need_commentbib = false; } + else if (t.cs() == "bibbysection") { + context.check_layout(os); + string BibOpts; + string bbloptions = p.hasOpt() ? p.getArg('[', ']') : string(); + vector opts = getVectorFromString(bbloptions); + vector::iterator it = + find(opts.begin(), opts.end(), "heading=bibintoc"); + if (it != opts.end()) { + opts.erase(it); + BibOpts = "bibtotoc"; + } + bbloptions = getStringFromVector(opts); + begin_command_inset(os, "bibtex", "bibtex"); + os << "btprint " << '"' << "bibbysection" << '"' << "\n"; + string bibfiles; + for (auto const & bf : preamble.biblatex_bibliographies) { + if (!bibfiles.empty()) + bibfiles += ","; + bibfiles += normalize_filename(bf); + } + if (!bibfiles.empty()) + os << "bibfiles " << '"' << bibfiles << '"' << "\n"; + os << "options " << '"' << BibOpts << '"' << "\n"; + if (!bbloptions.empty()) + os << "biblatexopts " << '"' << bbloptions << '"' << "\n"; + end_inset(os); + need_commentbib = false; + } + else if (t.cs() == "parbox") { // Test whether this is an outer box of a shaded box p.pushPosition(); -- 2.39.2