]> git.lyx.org Git - lyx.git/commitdiff
Provide reversed style specifier for citation commands
authorJuergen Spitzmueller <spitz@lyx.org>
Sat, 13 Jul 2024 15:20:29 +0000 (17:20 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Sat, 13 Jul 2024 15:20:29 +0000 (17:20 +0200)
This lets you exclude given variants for specific citation styles only

13 files changed:
lib/citeengines/biblatex-chicago.citeengine
lib/citeengines/biblatex-natbib.citeengine
lib/citeengines/biblatex.citeengine
lib/doc/Customization.lyx
lib/doc/de/Customization.lyx
src/BiblioInfo.cpp
src/BufferParams.cpp
src/BufferParams.h
src/Citation.h
src/TextClass.cpp
src/frontends/qt/GuiCitation.cpp
src/frontends/qt/Menus.cpp
src/insets/InsetCitation.cpp

index 2a5b8171a1d3a2d7a07c311b45f19111cb3e013e..916ede34c6aae30c8ef7bf68311ba6276132d74e 100644 (file)
@@ -30,7 +30,9 @@ MaxCiteNames 3
 # style@LyXName|alias*<!_stardesc!_stardesctooltip>[][]=latexcmd
 # 
 # * style:    A (comma-separated) list of citestyles to which
-#             this command is specific.
+#             this command is specific. If preceeded by '!',
+#             the list indicates citestyles for which the command
+#             is _not_ supported.
 # * 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
index 8c034b9bed397b7c5f56c143816d88029968910d..c487810b904717e9e08e4aecb23cef70a7654af8 100644 (file)
@@ -34,7 +34,9 @@ MaxCiteNames 3
 # style@LyXName|alias*<!_stardesc!_stardesctooltip>[][]=latexcmd
 # 
 # * style:    A (comma-separated) list of citestyles to which
-#             this command is specific.
+#             this command is specific. If preceeded by '!',
+#             the list indicates citestyles for which the command
+#             is _not_ supported.
 # * 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
@@ -92,7 +94,7 @@ CiteEngine authoryear
        Footcite$[][]=smartcite
        Autocite$[][]
        citetitle*<!_citetitlestar!_citetitlestartooltip>[][]
-       fullcite[][]
+       !mla,mla-strict,mla-new,mla7@fullcite[][]
        footfullcite[][]
        nocite
        keyonly
index 0d77bc811cff87a2987ee091eeec987162e2a422..92199df9fc0bf110f9c7a0356f30271808cadeed 100644 (file)
@@ -30,7 +30,9 @@ MaxCiteNames 3
 # style@LyXName|alias*<!_stardesc!_stardesctooltip>[][]=latexcmd
 # 
 # * style:    A (comma-separated) list of citestyles to which
-#             this command is specific.
+#             this command is specific. If preceeded by '!',
+#             the list indicates citestyles for which the command
+#             is _not_ supported.
 # * 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
@@ -74,7 +76,7 @@ MaxCiteNames 3
 #
 CiteEngine authoryear
        Cite$|citealt,citealp[][]
-       Citet$[][]=textcite
+       !mla,mla-strict,mla-new,mla7@Citet$[][]=textcite
        Citep$[][]=parencite
        apa,apa6@nptextcite$[][]
        Citeauthor*<!_citeauthorstar!_citeauthorstartooltip>[][]
@@ -84,7 +86,7 @@ CiteEngine authoryear
        Footcite$[][]=smartcite
        Autocite$[][]
        citetitle*<!_citetitlestar!_citetitlestartooltip>[][]
-       fullcite[][]
+       !mla,mla-strict,mla-new,mla7@fullcite[][]
        footfullcite[][]
        nocite
        keyonly
index 238404bc3b67433ff50ee5c06f307d0fe80e37ef..5c1dbafc5edc41a5fbcc86f26973b7182a72c631 100644 (file)
@@ -24612,7 +24612,7 @@ LyXName|alias$*<!_stardesc!_stardesctooltip>[][]=latexcmd
 
 \begin_layout Itemize
 
-\change_inserted -712698321 1720682930
+\change_inserted -712698321 1720883627
 \begin_inset Flex Code
 status collapsed
 
@@ -24668,6 +24668,27 @@ nptextcite
 apa
 \emph default
  citation style can be defined.
+ If the list is prepended by an exclamation mark (
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1720883593
+!
+\change_unchanged
+
+\end_layout
+
+\end_inset
+
+),
+ the meaning is reversed:
+ it means that the style is used in all 
+\emph on
+but
+\emph default
+ the listed styles.
 \end_layout
 
 \begin_layout Itemize
index 162aa3dd8b6214b98810474d8f920a486f2252de..18e3a342bd510e3046b537ba21a77ae52a97edc4 100644 (file)
@@ -23501,6 +23501,23 @@ nptextcite
 apa
 \emph default
  verfügbar ist.
+ Wenn der Liste ein Ausrufezeichen (
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+!
+\end_layout
+
+\end_inset
+
+) vorangestellt ist,
+ ist die Bedeutung umgekehrt:
+ der Befehl gilt dann in allen 
+\emph on
+außer
+\emph default
+ den aufgelisteten Stilen.
 \end_layout
 
 \begin_layout Itemize
index 2db4041bc6d764dfe411d8595b57ea286ebc4cf9..1292ef3303f90f3158635c7371d87c05869ff26c 100644 (file)
@@ -1600,20 +1600,17 @@ BiblioInfo::CiteStringMap const BiblioInfo::getCiteStrings(
        if (empty())
                return vector<pair<docstring,docstring>>();
 
+       vector<CitationStyle> realStyles;
+       for (size_t i = 0; i != styles.size(); ++i) {
+               // exclude variants that are not supported in the current style
+               if (buf.masterParams().isActiveBiblatexCiteStyle(styles[i]))
+                       realStyles.push_back(styles[i]);
+       }
+
        string style;
-       CiteStringMap csm(styles.size());
+       CiteStringMap csm(realStyles.size());
        for (size_t i = 0; i != csm.size(); ++i) {
-               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;
+               style = realStyles[i].name;
                csm[i] = make_pair(from_ascii(style), getLabel(keys, buf, style, ci));
        }
 
index c4493d42cae4884dbd7f1f723c180f39695bd284..43b08f9d1bc29f5d26bc6654eb1556657d0d5d4b 100644 (file)
@@ -3789,6 +3789,33 @@ vector<CitationStyle> BufferParams::citeStyles() const
 }
 
 
+bool BufferParams::isActiveBiblatexCiteStyle(CitationStyle const & cs) const
+{
+       if (!useBiblatex())
+               return false;
+
+       if (cs.styles.empty() && cs.nostyles.empty())
+               // no restrictions
+               return true;
+
+       // exclude variants that are excluded in the current style
+       for (string const & s: cs.nostyles) {
+               if (s == biblatex_citestyle)
+                       // explicitly excluded style
+                       return false;
+       }
+       if (cs.styles.empty())
+               // not excluded
+               return true;
+
+       // only include variants that are supported in the current style
+       for (string const & s: cs.styles) {
+               if (s == biblatex_citestyle)
+                       return true;
+       }
+       return false;
+}
+
 string const BufferParams::getBibtexCommand(string const cmd, bool const warn) const
 {
        // split from options
index 92c1418da1f2cb5e9c58ba2413a40e9c808b25a6..2178d65677c3f65c08ca95c66d846c02931e5dc7 100644 (file)
@@ -527,6 +527,8 @@ public:
        std::vector<std::string> citeCommands() const;
        /// the available citation styles
        std::vector<CitationStyle> citeStyles() const;
+       /// is the biblatex citestyle active in the current context?
+       bool isActiveBiblatexCiteStyle(CitationStyle const & cs) const;
 
        /// Return the actual bibtex command (lyxrc or buffer param)
        std::string const bibtexCommand(bool const warn = false) const;
index 02e8d4ba3c7d356f04917852de23a47a3715fbdb..747599d5f85f21a5d890ab05ad17ac05af37c8d5 100644 (file)
@@ -45,6 +45,8 @@ public:
        std::string startooltip;
        /// Styles that supports the command
        std::vector <std::string> styles;
+       /// Styles that do not supports the command
+       std::vector <std::string> nostyles;
        /// upper casing author prefixes (van -> Van)
        bool forceUpperCase;
        /// starred version (full author list by default)
index da58054fb304cc14dfe03a659100c45f95209217..933489743d9a4439f7ae4e79f68039ee1cccd18a 100644 (file)
@@ -1224,7 +1224,12 @@ 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.styles = getVectorFromString(style);
+                       // a '!' prefix indicates nostyle
+                       if (prefixIs(style, "!")) {
+                               style = style.substr(1);
+                               cs.nostyles = getVectorFromString(style);
+                       } else
+                               cs.styles = getVectorFromString(style);
                }
                char fchar = lyx_cmd[0];
                if (isUpperCase(fchar)) {
index de39ce769871fe45d74a415126eeab076632c7e2..ea10d171e442309fd2c460a293411343643c1ab3 100644 (file)
@@ -939,8 +939,17 @@ void GuiCitation::setCitedKeys()
 bool GuiCitation::initialiseParams(string const & sdata)
 {
        InsetCommand::string2params(sdata, params_);
-       citeCmds_ = documentBuffer().params().citeCommands();
-       citeStyles_ = documentBuffer().params().citeStyles();
+       citeStyles_.clear();
+       citeCmds_.clear();
+       vector<string> const cmds = documentBuffer().params().citeCommands();
+       vector<CitationStyle> const styles = documentBuffer().params().citeStyles();
+       for (size_t i = 0; i != styles.size(); ++i) {
+               // only include variants that are supported in the current style
+               if (documentBuffer().params().isActiveBiblatexCiteStyle(styles[i])) {
+                       citeStyles_.push_back(styles[i]);
+                       citeCmds_.push_back(cmds[i]);
+               }
+       }
        init();
        return true;
 }
index 16466b564e32c87c8c956960b4f4e6d9a52bb3f1..30575bb2eba594f4195de4a19af8461497218942 100644 (file)
@@ -1749,16 +1749,11 @@ void MenuDefinition::expandCiteStyles(BufferView const * bv)
        for (int ii = 1; cit != end; ++cit, ++ii) {
                docstring label = cit->second;
                CitationStyle ccs = citeStyleList[ii - 1];
-               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;
-                       }
+               while (!bp.isActiveBiblatexCiteStyle(ccs)) {
+                       ++ii;
+                       ccs = citeStyleList[ii - 1];
                }
-               if (!ccs.styles.empty() && !ours)
-                       continue;
                ccs.forceUpperCase &= force;
                ccs.hasStarredVersion &= star;
                addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(label),
index c7933b8850a3f103d0f46204dbb138ec83217eab..bf5f3526e52a87e37233c0f48834694bc0e916b3 100644 (file)
@@ -380,15 +380,8 @@ CitationStyle asValidLatexCommand(BufferParams const & bp, string const & input,
        for (; it != end; ++it) {
                CitationStyle this_cs = *it;
                if (this_cs.name == normalized_input) {
-                       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) {
+                       if (!bp.isActiveBiblatexCiteStyle(this_cs)) {
                                // citation not supported with current style
                                // reset to \cite
                                normalized_input = "cite";