[LyX/master] Allow to pass several styles for style-specific cite commands

Juergen Spitzmueller spitz at lyx.org
Thu Jul 11 08:10:18 UTC 2024


commit f7cc716861efbc209831323ad4b9643f4a9bf28e
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Thu Jul 11 10:09:26 2024 +0200

    Allow to pass several styles for style-specific cite commands
---
 lib/doc/Customization.lyx    |  5 ++---
 lib/doc/de/Customization.lyx |  4 ++--
 src/BiblioInfo.cpp           | 10 +++++++++-
 src/Citation.h               |  4 ++--
 src/TextClass.cpp            |  2 +-
 src/frontends/qt/Menus.cpp   | 10 +++++++++-
 src/insets/InsetCitation.cpp | 10 +++++++++-
 7 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/lib/doc/Customization.lyx b/lib/doc/Customization.lyx
index 4fb1e37268..238404bc3b 100644
--- a/lib/doc/Customization.lyx
+++ b/lib/doc/Customization.lyx
@@ -24612,7 +24612,7 @@ LyXName|alias$*<!_stardesc!_stardesctooltip>[][]=latexcmd
 
 \begin_layout Itemize
 
-\change_inserted -712698321 1720623254
+\change_inserted -712698321 1720682930
 \begin_inset Flex Code
 status collapsed
 
@@ -24627,8 +24627,7 @@ style
 \end_inset
 
 :
- If this is given,
- the command is specific to this (biblatex) citation style.
+ a (comma-separated) list of biblatex citation styles to which this command is specific.
  E.
 \begin_inset space \thinspace{}
 \end_inset
diff --git a/lib/doc/de/Customization.lyx b/lib/doc/de/Customization.lyx
index efdbaaff48..162aa3dd8b 100644
--- a/lib/doc/de/Customization.lyx
+++ b/lib/doc/de/Customization.lyx
@@ -23470,8 +23470,8 @@ style
 \end_inset
 
 :
- Wenn dies angegeben wird,
- wird der Befehl als spezifisch für einen (Biblatex-)Zitierstil markiert.
+ eine (kommaseparierter) Liste von (Biblatex-)Zitierstilen,
+ für die der Befehl spezifisch ist.
  Mit 
 \begin_inset Flex Code
 status collapsed
diff --git a/src/BiblioInfo.cpp b/src/BiblioInfo.cpp
index 04235e424a..2db4041bc6 100644
--- a/src/BiblioInfo.cpp
+++ b/src/BiblioInfo.cpp
@@ -1603,7 +1603,15 @@ BiblioInfo::CiteStringMap const BiblioInfo::getCiteStrings(
 	string style;
 	CiteStringMap csm(styles.size());
 	for (size_t i = 0; i != csm.size(); ++i) {
-		if (!styles[i].style.empty() && styles[i].style != buf.masterParams().biblatex_citestyle)
+		bool ours = false;
+		// exclude variants that are not supported in the current style
+		for (string const & s: styles[i].styles) {
+			if (s == buf.masterParams().biblatex_citestyle) {
+				ours = true;
+				break;
+			}
+		}
+		if (!styles[i].styles.empty() && !ours)
 			continue;
 		style = styles[i].name;
 		csm[i] = make_pair(from_ascii(style), getLabel(keys, buf, style, ci));
diff --git a/src/Citation.h b/src/Citation.h
index 8ed64a7646..02e8d4ba3c 100644
--- a/src/Citation.h
+++ b/src/Citation.h
@@ -43,8 +43,8 @@ public:
 	std::string stardesc;
 	/// Optional tooltip for the starred version
 	std::string startooltip;
-	/// Style that supports the command
-	std::string style;
+	/// Styles that supports the command
+	std::vector <std::string> styles;
 	/// upper casing author prefixes (van -> Van)
 	bool forceUpperCase;
 	/// starred version (full author list by default)
diff --git a/src/TextClass.cpp b/src/TextClass.cpp
index eacb41c7cc..43731e14cc 100644
--- a/src/TextClass.cpp
+++ b/src/TextClass.cpp
@@ -1228,7 +1228,7 @@ bool TextClass::readCiteEngine(Lexer & lexrc, ReadType rt, bool const add)
 		// split off style prefix if there
 		if (contains(lyx_cmd, '@')) {
 			lyx_cmd = split(lyx_cmd, style, '@');
-			cs.style = style;
+			cs.styles = getVectorFromString(style);
 		}
 		cs.name = lyx_cmd;
 		cs.cmd = latex_cmd.empty() ? lyx_cmd : latex_cmd;
diff --git a/src/frontends/qt/Menus.cpp b/src/frontends/qt/Menus.cpp
index f1ad6fefc5..16466b564e 100644
--- a/src/frontends/qt/Menus.cpp
+++ b/src/frontends/qt/Menus.cpp
@@ -1749,7 +1749,15 @@ void MenuDefinition::expandCiteStyles(BufferView const * bv)
 	for (int ii = 1; cit != end; ++cit, ++ii) {
 		docstring label = cit->second;
 		CitationStyle ccs = citeStyleList[ii - 1];
-		if (!ccs.style.empty() && ccs.style != bp.biblatex_citestyle)
+		bool ours = false;
+		// exclude variants that are not supported in the current style
+		for (string const & s: ccs.styles) {
+			if (s == bp.biblatex_citestyle) {
+				ours = true;
+				break;
+			}
+		}
+		if (!ccs.styles.empty() && !ours)
 			continue;
 		ccs.forceUpperCase &= force;
 		ccs.hasStarredVersion &= star;
diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp
index 120786245c..c7933b8850 100644
--- a/src/insets/InsetCitation.cpp
+++ b/src/insets/InsetCitation.cpp
@@ -380,7 +380,15 @@ CitationStyle asValidLatexCommand(BufferParams const & bp, string const & input,
 	for (; it != end; ++it) {
 		CitationStyle this_cs = *it;
 		if (this_cs.name == normalized_input) {
-			if (!this_cs.style.empty() && this_cs.style != bp.biblatex_citestyle) {
+			bool ours = false;
+			// exclude variants that are not supported in the current style
+			for (string const & s: this_cs.styles) {
+				if (s == bp.biblatex_citestyle) {
+					ours = true;
+					break;
+				}
+			}
+			if (!this_cs.styles.empty() && !ours) {
 				// citation not supported with current style
 				// reset to \cite
 				normalized_input = "cite";


More information about the lyx-cvs mailing list