Provide reversed style specifier for citation commands

This lets you exclude given variants for specific citation styles only
This commit is contained in:
Juergen Spitzmueller 2024-07-13 17:20:29 +02:00
parent 660ec568ef
commit 6603c5362f
13 changed files with 113 additions and 39 deletions

View File

@ -30,7 +30,9 @@ MaxCiteNames 3
# style@LyXName|alias*<!_stardesc!_stardesctooltip>[][]=latexcmd # style@LyXName|alias*<!_stardesc!_stardesctooltip>[][]=latexcmd
# #
# * style: A (comma-separated) list of citestyles to which # * 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 # * LyXName: The LyX name as output in the LyX file. For
# portability reasons, we try to use the same # portability reasons, we try to use the same
# name for same-formatted commands in the # name for same-formatted commands in the

View File

@ -34,7 +34,9 @@ MaxCiteNames 3
# style@LyXName|alias*<!_stardesc!_stardesctooltip>[][]=latexcmd # style@LyXName|alias*<!_stardesc!_stardesctooltip>[][]=latexcmd
# #
# * style: A (comma-separated) list of citestyles to which # * 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 # * LyXName: The LyX name as output in the LyX file. For
# portability reasons, we try to use the same # portability reasons, we try to use the same
# name for same-formatted commands in the # name for same-formatted commands in the
@ -92,7 +94,7 @@ CiteEngine authoryear
Footcite$[][]=smartcite Footcite$[][]=smartcite
Autocite$[][] Autocite$[][]
citetitle*<!_citetitlestar!_citetitlestartooltip>[][] citetitle*<!_citetitlestar!_citetitlestartooltip>[][]
fullcite[][] !mla,mla-strict,mla-new,mla7@fullcite[][]
footfullcite[][] footfullcite[][]
nocite nocite
keyonly keyonly

View File

@ -30,7 +30,9 @@ MaxCiteNames 3
# style@LyXName|alias*<!_stardesc!_stardesctooltip>[][]=latexcmd # style@LyXName|alias*<!_stardesc!_stardesctooltip>[][]=latexcmd
# #
# * style: A (comma-separated) list of citestyles to which # * 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 # * LyXName: The LyX name as output in the LyX file. For
# portability reasons, we try to use the same # portability reasons, we try to use the same
# name for same-formatted commands in the # name for same-formatted commands in the
@ -74,7 +76,7 @@ MaxCiteNames 3
# #
CiteEngine authoryear CiteEngine authoryear
Cite$|citealt,citealp[][] Cite$|citealt,citealp[][]
Citet$[][]=textcite !mla,mla-strict,mla-new,mla7@Citet$[][]=textcite
Citep$[][]=parencite Citep$[][]=parencite
apa,apa6@nptextcite$[][] apa,apa6@nptextcite$[][]
Citeauthor*<!_citeauthorstar!_citeauthorstartooltip>[][] Citeauthor*<!_citeauthorstar!_citeauthorstartooltip>[][]
@ -84,7 +86,7 @@ CiteEngine authoryear
Footcite$[][]=smartcite Footcite$[][]=smartcite
Autocite$[][] Autocite$[][]
citetitle*<!_citetitlestar!_citetitlestartooltip>[][] citetitle*<!_citetitlestar!_citetitlestartooltip>[][]
fullcite[][] !mla,mla-strict,mla-new,mla7@fullcite[][]
footfullcite[][] footfullcite[][]
nocite nocite
keyonly keyonly

View File

@ -24612,7 +24612,7 @@ LyXName|alias$*<!_stardesc!_stardesctooltip>[][]=latexcmd
\begin_layout Itemize \begin_layout Itemize
\change_inserted -712698321 1720682930 \change_inserted -712698321 1720883627
\begin_inset Flex Code \begin_inset Flex Code
status collapsed status collapsed
@ -24668,6 +24668,27 @@ nptextcite
apa apa
\emph default \emph default
citation style can be defined. 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 \end_layout
\begin_layout Itemize \begin_layout Itemize

View File

@ -23501,6 +23501,23 @@ nptextcite
apa apa
\emph default \emph default
verfügbar ist. 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 \end_layout
\begin_layout Itemize \begin_layout Itemize

View File

@ -1600,20 +1600,17 @@ BiblioInfo::CiteStringMap const BiblioInfo::getCiteStrings(
if (empty()) if (empty())
return vector<pair<docstring,docstring>>(); return vector<pair<docstring,docstring>>();
string style; vector<CitationStyle> realStyles;
CiteStringMap csm(styles.size()); for (size_t i = 0; i != styles.size(); ++i) {
for (size_t i = 0; i != csm.size(); ++i) {
bool ours = false;
// exclude variants that are not supported in the current style // exclude variants that are not supported in the current style
for (string const & s: styles[i].styles) { if (buf.masterParams().isActiveBiblatexCiteStyle(styles[i]))
if (s == buf.masterParams().biblatex_citestyle) { realStyles.push_back(styles[i]);
ours = true;
break;
} }
}
if (!styles[i].styles.empty() && !ours) string style;
continue; CiteStringMap csm(realStyles.size());
style = styles[i].name; for (size_t i = 0; i != csm.size(); ++i) {
style = realStyles[i].name;
csm[i] = make_pair(from_ascii(style), getLabel(keys, buf, style, ci)); csm[i] = make_pair(from_ascii(style), getLabel(keys, buf, style, ci));
} }

View 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 string const BufferParams::getBibtexCommand(string const cmd, bool const warn) const
{ {
// split from options // split from options

View File

@ -527,6 +527,8 @@ public:
std::vector<std::string> citeCommands() const; std::vector<std::string> citeCommands() const;
/// the available citation styles /// the available citation styles
std::vector<CitationStyle> citeStyles() const; 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) /// Return the actual bibtex command (lyxrc or buffer param)
std::string const bibtexCommand(bool const warn = false) const; std::string const bibtexCommand(bool const warn = false) const;

View File

@ -45,6 +45,8 @@ public:
std::string startooltip; std::string startooltip;
/// Styles that supports the command /// Styles that supports the command
std::vector <std::string> styles; std::vector <std::string> styles;
/// Styles that do not supports the command
std::vector <std::string> nostyles;
/// upper casing author prefixes (van -> Van) /// upper casing author prefixes (van -> Van)
bool forceUpperCase; bool forceUpperCase;
/// starred version (full author list by default) /// starred version (full author list by default)

View File

@ -1224,6 +1224,11 @@ bool TextClass::readCiteEngine(Lexer & lexrc, ReadType rt, bool const add)
// split off style prefix if there // split off style prefix if there
if (contains(lyx_cmd, '@')) { if (contains(lyx_cmd, '@')) {
lyx_cmd = split(lyx_cmd, style, '@'); lyx_cmd = split(lyx_cmd, style, '@');
// a '!' prefix indicates nostyle
if (prefixIs(style, "!")) {
style = style.substr(1);
cs.nostyles = getVectorFromString(style);
} else
cs.styles = getVectorFromString(style); cs.styles = getVectorFromString(style);
} }
char fchar = lyx_cmd[0]; char fchar = lyx_cmd[0];

View File

@ -939,8 +939,17 @@ void GuiCitation::setCitedKeys()
bool GuiCitation::initialiseParams(string const & sdata) bool GuiCitation::initialiseParams(string const & sdata)
{ {
InsetCommand::string2params(sdata, params_); InsetCommand::string2params(sdata, params_);
citeCmds_ = documentBuffer().params().citeCommands(); citeStyles_.clear();
citeStyles_ = documentBuffer().params().citeStyles(); 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(); init();
return true; return true;
} }

View File

@ -1749,16 +1749,11 @@ void MenuDefinition::expandCiteStyles(BufferView const * bv)
for (int ii = 1; cit != end; ++cit, ++ii) { for (int ii = 1; cit != end; ++cit, ++ii) {
docstring label = cit->second; docstring label = cit->second;
CitationStyle ccs = citeStyleList[ii - 1]; CitationStyle ccs = citeStyleList[ii - 1];
bool ours = false;
// exclude variants that are not supported in the current style // exclude variants that are not supported in the current style
for (string const & s: ccs.styles) { while (!bp.isActiveBiblatexCiteStyle(ccs)) {
if (s == bp.biblatex_citestyle) { ++ii;
ours = true; ccs = citeStyleList[ii - 1];
break;
} }
}
if (!ccs.styles.empty() && !ours)
continue;
ccs.forceUpperCase &= force; ccs.forceUpperCase &= force;
ccs.hasStarredVersion &= star; ccs.hasStarredVersion &= star;
addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(label), addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(label),

View File

@ -380,15 +380,8 @@ CitationStyle asValidLatexCommand(BufferParams const & bp, string const & input,
for (; it != end; ++it) { for (; it != end; ++it) {
CitationStyle this_cs = *it; CitationStyle this_cs = *it;
if (this_cs.name == normalized_input) { if (this_cs.name == normalized_input) {
bool ours = false;
// exclude variants that are not supported in the current style // exclude variants that are not supported in the current style
for (string const & s: this_cs.styles) { if (!bp.isActiveBiblatexCiteStyle(this_cs)) {
if (s == bp.biblatex_citestyle) {
ours = true;
break;
}
}
if (!this_cs.styles.empty() && !ours) {
// citation not supported with current style // citation not supported with current style
// reset to \cite // reset to \cite
normalized_input = "cite"; normalized_input = "cite";