[LyX/master] Implement possibility to define citestyle-specific commands with biblatex

Juergen Spitzmueller spitz at lyx.org
Wed Jul 10 14:59:33 UTC 2024


commit 40d644a7f9291dfdd04803dd94b79b573b40dfc7
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Wed Jul 10 16:58:34 2024 +0200

    Implement possibility to define citestyle-specific commands with biblatex
    
    Not yet used.
---
 lib/citeengines/biblatex-chicago.citeengine |  3 +-
 lib/citeengines/biblatex-natbib.citeengine  |  3 +-
 lib/citeengines/biblatex.citeengine         |  3 +-
 lib/doc/Customization.lyx                   | 92 ++++++++++++++++++++++++++++-
 lib/doc/de/Customization.lyx                | 59 +++++++++++++++++-
 src/BiblioInfo.cpp                          |  2 +
 src/Citation.h                              |  2 +
 src/TextClass.cpp                           | 17 ++++--
 src/frontends/qt/Menus.cpp                  |  2 +
 src/insets/InsetCitation.cpp                |  7 +++
 10 files changed, 179 insertions(+), 11 deletions(-)

diff --git a/lib/citeengines/biblatex-chicago.citeengine b/lib/citeengines/biblatex-chicago.citeengine
index 4f7c730413..dbfc2802eb 100644
--- a/lib/citeengines/biblatex-chicago.citeengine
+++ b/lib/citeengines/biblatex-chicago.citeengine
@@ -27,8 +27,9 @@ MaxCiteNames 3
 
 
 # The syntax of the cite command definitions below is:
-# LyXName|alias*<!_stardesc!_stardesctooltip>[][]=latexcmd
+# style at LyXName|alias*<!_stardesc!_stardesctooltip>[][]=latexcmd
 # 
+# * style:    (Optional) citestyle to which this command is specific.
 # * LyXName:  The LyX name as output in the LyX file. For
 #             portability reasons, we try to use the same
 #             name for same-formatted commands in the
diff --git a/lib/citeengines/biblatex-natbib.citeengine b/lib/citeengines/biblatex-natbib.citeengine
index c9dd269081..2a3a122f42 100644
--- a/lib/citeengines/biblatex-natbib.citeengine
+++ b/lib/citeengines/biblatex-natbib.citeengine
@@ -31,8 +31,9 @@ MaxCiteNames 3
 
 
 # The syntax of the cite command definitions below is:
-# LyXName|alias*<!_stardesc!_stardesctooltip>[][]=latexcmd
+# style at LyXName|alias*<!_stardesc!_stardesctooltip>[][]=latexcmd
 # 
+# * style:    (Optional) citestyle to which this command is specific.
 # * LyXName:  The LyX name as output in the LyX file. For
 #             portability reasons, we try to use the same
 #             name for same-formatted commands in the
diff --git a/lib/citeengines/biblatex.citeengine b/lib/citeengines/biblatex.citeengine
index ba8731e5f7..a1530c6ea5 100644
--- a/lib/citeengines/biblatex.citeengine
+++ b/lib/citeengines/biblatex.citeengine
@@ -27,8 +27,9 @@ MaxCiteNames 3
 
 
 # The syntax of the cite command definitions below is:
-# LyXName|alias*<!_stardesc!_stardesctooltip>[][]=latexcmd
+# style at LyXName|alias*<!_stardesc!_stardesctooltip>[][]=latexcmd
 # 
+# * style:    (Optional) citestyle to which this command is specific.
 # * LyXName:  The LyX name as output in the LyX file. For
 #             portability reasons, we try to use the same
 #             name for same-formatted commands in the
diff --git a/lib/doc/Customization.lyx b/lib/doc/Customization.lyx
index 4e35366c16..ee422b4bff 100644
--- a/lib/doc/Customization.lyx
+++ b/lib/doc/Customization.lyx
@@ -24603,9 +24603,74 @@ CiteEngine
 \end_layout
 
 \begin_layout LyX-Code
+
+\change_inserted -712698321 1720623059
+style@
+\change_unchanged
 LyXName|alias$*<!_stardesc!_stardesctooltip>[][]=latexcmd
 \end_layout
 
+\begin_layout Itemize
+
+\change_inserted -712698321 1720623254
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1720623079
+style
+\change_unchanged
+
+\end_layout
+
+\end_inset
+
+:
+ If this is given,
+ the command is specific to this (biblatex) citation style.
+ E.
+\begin_inset space \thinspace{}
+\end_inset
+
+g.,
+ with 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1720623135
+apa at nptextcite
+\change_unchanged
+
+\end_layout
+
+\end_inset
+
+ a citation command 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1720623254
+
+\backslash
+nptextcite
+\change_unchanged
+
+\end_layout
+
+\end_inset
+
+ which is only available with the 
+\emph on
+apa
+\emph default
+ citation style can be defined.
+\end_layout
+
 \begin_layout Itemize
 \begin_inset Flex Code
 status collapsed
@@ -24713,11 +24778,36 @@ latexcmd
 \end_layout
 
 \begin_layout Standard
+
+\change_inserted -712698321 1720623197
 \begin_inset Flex Code
 status collapsed
 
 \begin_layout Plain Layout
-Alias
+
+\change_inserted -712698321 1720623197
+Style
+\change_unchanged
+
+\end_layout
+
+\end_inset
+
+,
+ 
+\change_unchanged
+
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_deleted -712698321 1720623181
+A
+\change_inserted -712698321 1720623181
+a
+\change_unchanged
+lias
 \end_layout
 
 \end_inset
diff --git a/lib/doc/de/Customization.lyx b/lib/doc/de/Customization.lyx
index 09c9ec8f40..42c3e8fd84 100644
--- a/lib/doc/de/Customization.lyx
+++ b/lib/doc/de/Customization.lyx
@@ -23456,7 +23456,51 @@ CiteEngine
 \end_layout
 
 \begin_layout LyX-Code
-LyXName|alias$*<!_stardesc!_stardesctooltip>[][]=latexcmd
+style at LyXName|alias$*<!_stardesc!_stardesctooltip>[][]=latexcmd
+\end_layout
+
+\begin_layout Itemize
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+style
+\end_layout
+
+\end_inset
+
+:
+ Wenn dies angegeben wird,
+ wird der Befehl als spezifisch für einen (Biblatex-)Zitierstil markiert.
+ Mit 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+apa at nptextcite
+\end_layout
+
+\end_inset
+
+ können Sie so bspw.
+ einen Befehl 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\backslash
+nptextcite
+\end_layout
+
+\end_inset
+
+ definieren,
+ der nur mit dem Zitierstil 
+\emph on
+apa
+\emph default
+ verfügbar ist.
 \end_layout
 
 \begin_layout Itemize
@@ -23588,7 +23632,18 @@ latexcmd
 status collapsed
 
 \begin_layout Plain Layout
-Alias
+Style
+\end_layout
+
+\end_inset
+
+,
+ 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+alias
 \end_layout
 
 \end_inset
diff --git a/src/BiblioInfo.cpp b/src/BiblioInfo.cpp
index 60c29c8f99..01f8d36ffa 100644
--- a/src/BiblioInfo.cpp
+++ b/src/BiblioInfo.cpp
@@ -1569,6 +1569,8 @@ 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)
+			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 77c6f6f07f..8ed64a7646 100644
--- a/src/Citation.h
+++ b/src/Citation.h
@@ -43,6 +43,8 @@ public:
 	std::string stardesc;
 	/// Optional tooltip for the starred version
 	std::string startooltip;
+	/// Style that supports the command
+	std::string style;
 	/// 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 06d7b8453b..eacb41c7cc 100644
--- a/src/TextClass.cpp
+++ b/src/TextClass.cpp
@@ -1169,15 +1169,16 @@ bool TextClass::readCiteEngine(Lexer & lexrc, ReadType rt, bool const add)
 		/** For portability reasons (between different
 		 *  cite engines such as natbib and biblatex),
 		 *  we distinguish between:
-		 *  1. The LyX name as output in the LyX file
-		 *  2. Possible aliases that might fall back to
+		 *  1. The style that features this command
+		 *  2. The LyX name as output in the LyX file
+		 *  3. Possible aliases that might fall back to
 		 *     the given LyX name in the current engine
-		 *  3. The actual LaTeX command that is output
-		 *  (2) and (3) are optional.
+		 *  4. The actual LaTeX command that is output
+		 *  (1), (3) and (4) are optional.
 		 *  Also, the GUI string for the starred version can
 		 *  be changed
 		 *  The syntax is:
-		 *  LyXName|alias,nextalias*<!stardesc!stardesctooltip>[][]=latexcmd
+		 *  style at LyXName|alias,nextalias*<!stardesc!stardesctooltip>[][]=latexcmd
 		 */
 		enum ScanMode {
 			LyXName,
@@ -1192,6 +1193,7 @@ bool TextClass::readCiteEngine(Lexer & lexrc, ReadType rt, bool const add)
 		string alias;
 		string latex_cmd;
 		string stardesc;
+		string style;
 		size_t const n = def.size();
 		for (size_t i = 0; i != n; ++i) {
 			ichar = def[i];
@@ -1223,6 +1225,11 @@ bool TextClass::readCiteEngine(Lexer & lexrc, ReadType rt, bool const add)
 					lyx_cmd += ichar;
 			}
 		}
+		// split off style prefix if there
+		if (contains(lyx_cmd, '@')) {
+			lyx_cmd = split(lyx_cmd, style, '@');
+			cs.style = style;
+		}
 		cs.name = lyx_cmd;
 		cs.cmd = latex_cmd.empty() ? lyx_cmd : latex_cmd;
 		if (!alias.empty()) {
diff --git a/src/frontends/qt/Menus.cpp b/src/frontends/qt/Menus.cpp
index a191073935..f1ad6fefc5 100644
--- a/src/frontends/qt/Menus.cpp
+++ b/src/frontends/qt/Menus.cpp
@@ -1749,6 +1749,8 @@ 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)
+			continue;
 		ccs.forceUpperCase &= force;
 		ccs.hasStarredVersion &= star;
 		addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(label),
diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp
index 5082e112f2..120786245c 100644
--- a/src/insets/InsetCitation.cpp
+++ b/src/insets/InsetCitation.cpp
@@ -380,6 +380,13 @@ 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) {
+				// citation not supported with current style
+				// reset to \cite
+				normalized_input = "cite";
+				it = valid_styles.begin();
+				continue;
+			}
 			cs = *it;
 			break;
 		}


More information about the lyx-cvs mailing list