Am Samstag, dem 16.10.2021 um 12:30 -0400 schrieb Richard Kimberly
Heck:
> > > As I tried to explain this is not due to preamble edits per se,
> > > but due
> > > to doing any change in document preferences. As biber is not
> > > available,
> > > it cannot be (re-)selected in settings. All we could do about
> > > that is
> > > issue a warning.
> 
> I think this would be an adequate solution.

The attached patches implement a better solution:

* LyX does _not_ change document settings silently. Rather than that,
it keeps the current setting but indicates it is not available, like we
do for document classes, e.g. "biber (not available)". This prevents
unwanted changes on document sharing (patch 0002).

* on compilation of such documents, LyX tries to fall back to a
sensible available compiler (e.g. biber -> bibtex8) and warns the user
about that, suggesting to install the missing compiler (patch 0001).

I think this addresses Paul's concerns as good as it gets.

Could somebody please commit to master? I still cannot connect to the
git server.

Riki, this might also be candidate for stable. If you think so, please
cherry-pick.

Thanks,
Jürgen

From 4106fdfc522e1bf28da80ac3ddfe601569318f8f Mon Sep 17 00:00:00 2001
From: Juergen Spitzmueller <sp...@lyx.org>
Date: Sun, 17 Oct 2021 11:30:24 +0200
Subject: [PATCH 2/2] Do not change bibliography processor to default if it is
 not found

Rather than that, keep it with a warning that it is not available.
Fallback procedure (which maintains security measures) is done in
the conversion step.

This prevents document properties being silently changed on sharing.
---
 src/frontends/qt/GuiDocument.cpp | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/frontends/qt/GuiDocument.cpp b/src/frontends/qt/GuiDocument.cpp
index 9389272335..8f8661c5b2 100644
--- a/src/frontends/qt/GuiDocument.cpp
+++ b/src/frontends/qt/GuiDocument.cpp
@@ -3996,17 +3996,17 @@ void GuiDocument::paramsToDialog()
 	string options =
 		split(bp_.bibtex_command, command, ' ');
 
-	int const bpos = biblioModule->bibtexCO->findData(toqstr(command));
-	if (bpos != -1) {
-		biblioModule->bibtexCO->setCurrentIndex(bpos);
-		biblioModule->bibtexOptionsLE->setText(toqstr(options).trimmed());
-	} else {
-		// We reset to default if we do not know the specified compiler
-		// This is for security reasons
-		biblioModule->bibtexCO->setCurrentIndex(
-			biblioModule->bibtexCO->findData(toqstr("default")));
-		biblioModule->bibtexOptionsLE->clear();
+	int bpos = biblioModule->bibtexCO->findData(toqstr(command));
+	if (bpos == -1) {
+		// We add and set the unknown compiler, indicating that it is unavailable
+		// to assure document compilation and for security reasons, a fallback
+		// will be used on document processing stage
+		biblioModule->bibtexCO->addItem(toqstr(bformat(_("%1$s (not available)"),
+							from_utf8(command))), toqstr(command));
+		bpos = biblioModule->bibtexCO->findData(toqstr(command));
 	}
+	biblioModule->bibtexCO->setCurrentIndex(bpos);
+	biblioModule->bibtexOptionsLE->setText(toqstr(options).trimmed());
 	biblioModule->bibtexOptionsLE->setEnabled(
 		biblioModule->bibtexCO->currentIndex() != 0);
 
-- 
2.33.0

From 5be89422751e8ba6c9389f4019e19b2609d74357 Mon Sep 17 00:00:00 2001
From: Juergen Spitzmueller <sp...@lyx.org>
Date: Sun, 17 Oct 2021 11:29:18 +0200
Subject: [PATCH 1/2] Provide proper fallback if a bibliography processor is
 not found

Check for appropriate fallbacks and warn user if the requested
bibliography processor is unavailable.
---
 src/BufferParams.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++--
 src/BufferParams.h   |  5 +++-
 src/Converter.cpp    |  2 +-
 src/LaTeX.cpp        |  2 +-
 4 files changed, 69 insertions(+), 6 deletions(-)

diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
index d9fb39e3b6..a41a570751 100644
--- a/src/BufferParams.cpp
+++ b/src/BufferParams.cpp
@@ -3612,11 +3612,71 @@ vector<CitationStyle> BufferParams::citeStyles() const
 }
 
 
-string const BufferParams::bibtexCommand() const
+string const BufferParams::getBibtexCommand(string const cmd, bool const warn) const
+{
+	// split from options
+	string command_in;
+	split(cmd, command_in, ' ');
+
+	// Look if the requested command is available. If so, use that.
+	for (auto const & alts : lyxrc.bibtex_alternatives) {
+		string command_prov;
+		split(alts, command_prov, ' ');
+		if (command_in == command_prov)
+			return cmd;
+	}
+
+	// If not, find the most suitable fallback for the current cite framework,
+	// and warn. Note that we omit options in any such case.
+	string fallback;
+	if (useBiblatex()) {
+		// For Biblatex, we prefer biber (also for Japanese)
+		// and try to fall back to bibtex8
+		if (lyxrc.bibtex_alternatives.find("biber") != lyxrc.bibtex_alternatives.end())
+			fallback = "biber";
+		else if (lyxrc.bibtex_alternatives.find("bibtex8") != lyxrc.bibtex_alternatives.end())
+			fallback = "bibtex8";
+	}
+	// For classic BibTeX and as last resort for biblatex, try bibtex
+	if (fallback.empty()) {
+		if (lyxrc.bibtex_alternatives.find("bibtex") != lyxrc.bibtex_alternatives.end())
+			fallback = "bibtex";
+	}
+
+	if (!warn)
+		return fallback;
+
+	if (fallback.empty()) {
+		frontend::Alert::warning(
+			_("No bibliography processor found!"),
+			support::bformat(
+			  _("The bibliography processor requested by this document "
+			    "(%1$s) is not available and no appropriate "
+			    "alternative has been found. "
+			    "No bibliography and references will be generated.\n"
+			    "Please fix your installation!"),
+			  from_utf8(cmd)));
+	} else {
+		frontend::Alert::warning(
+			_("Requested bibliography processor not found!"),
+			support::bformat(
+			  _("The bibliography processor requested by this document "
+			    "(%1$s) is not available. "
+			    "As a fallback, '%2$s' will be used, options are omitted. "
+			    "This might result in errors or unwanted changes in "
+			    "the bibliography. Please check carefully!\n"
+			    "It is suggested to install the missing processor."),
+			  from_utf8(cmd), from_utf8(fallback)));
+	}
+	return fallback;
+}
+
+
+string const BufferParams::bibtexCommand(bool const warn) const
 {
 	// Return document-specific setting if available
 	if (bibtex_command != "default")
-		return bibtex_command;
+		return getBibtexCommand(bibtex_command, warn);
 
 	// If we have "default" in document settings, consult the prefs
 	// 1. Japanese (uses a specific processor)
@@ -3636,7 +3696,7 @@ string const BufferParams::bibtexCommand() const
 	// 2. All other languages
 	else if (lyxrc.bibtex_command != "automatic")
 		// Return the specified program, if "automatic" is not set
-		return lyxrc.bibtex_command;
+		return getBibtexCommand(lyxrc.bibtex_command, warn);
 
 	// 3. Automatic: find the most suitable for the current cite framework
 	if (useBiblatex()) {
diff --git a/src/BufferParams.h b/src/BufferParams.h
index a1dfaa9b72..38649e7c2f 100644
--- a/src/BufferParams.h
+++ b/src/BufferParams.h
@@ -518,7 +518,7 @@ public:
 	std::vector<CitationStyle> citeStyles() const;
 
 	/// Return the actual bibtex command (lyxrc or buffer param)
-	std::string const bibtexCommand() const;
+	std::string const bibtexCommand(bool const warn = false) const;
 
 	/// Are we using biblatex?
 	bool useBiblatex() const;
@@ -651,6 +651,9 @@ private:
 	std::map<std::string, std::string> bib_encodings;
 	/// Split bibliography?
 	bool use_bibtopic;
+	/// Return the actual or an appropriate fallback bibtex command
+	std::string const getBibtexCommand(std::string const cmd,
+					   bool const warn) const;
 	///
 	DocumentClassPtr doc_class_;
 	///
diff --git a/src/Converter.cpp b/src/Converter.cpp
index 4e9a2ad426..0578026be3 100644
--- a/src/Converter.cpp
+++ b/src/Converter.cpp
@@ -478,7 +478,7 @@ Converters::RetVal Converters::convert(Buffer const * buffer,
 			 || suffixIs(bp.bufferFormat(), "-ja"))
 			&& bp.encoding().package() == Encoding::japanese;
 		runparams.use_indices = bp.use_indices;
-		runparams.bibtex_command = bp.bibtexCommand();
+		runparams.bibtex_command = bp.bibtexCommand(true);
 		runparams.index_command = (bp.index_command == "default") ?
 			string() : bp.index_command;
 		runparams.document_language = bp.language->lang();
diff --git a/src/LaTeX.cpp b/src/LaTeX.cpp
index a8d14b1f74..ce3d73eef2 100644
--- a/src/LaTeX.cpp
+++ b/src/LaTeX.cpp
@@ -768,7 +768,7 @@ bool LaTeX::runBibTeX(vector<AuxInfo> const & bibtex_info,
 				it->aux_file.absFileName())));
 		Systemcall one;
 		Systemcall::Starttype const starttype = 
-	        allow_cancel ? Systemcall::WaitLoop : Systemcall::Wait;
+			allow_cancel ? Systemcall::WaitLoop : Systemcall::Wait;
 		exit_code = one.startscript(starttype, tmp, path, lpath, true);
 		if (exit_code) {
 			return result;
-- 
2.33.0

Attachment: signature.asc
Description: This is a digitally signed message part

-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to