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: 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

View 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

View 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

View 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

View 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

View File

@ -1600,20 +1600,17 @@ BiblioInfo::CiteStringMap const BiblioInfo::getCiteStrings(
if (empty())
return vector<pair<docstring,docstring>>();
string style;
CiteStringMap csm(styles.size());
for (size_t i = 0; i != csm.size(); ++i) {
bool ours = false;
vector<CitationStyle> realStyles;
for (size_t i = 0; i != styles.size(); ++i) {
// 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;
if (buf.masterParams().isActiveBiblatexCiteStyle(styles[i]))
realStyles.push_back(styles[i]);
}
string style;
CiteStringMap csm(realStyles.size());
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));
}

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
{
// split from options

View 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;

View 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)

View 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)) {

View 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;
}

View 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),

View 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";