Implement possibility to define citestyle-specific commands with biblatex

Not yet used.
This commit is contained in:
Juergen Spitzmueller 2024-07-10 16:58:34 +02:00
parent 8bc3799b35
commit 40d644a7f9
10 changed files with 179 additions and 11 deletions

View File

@ -27,8 +27,9 @@ MaxCiteNames 3
# The syntax of the cite command definitions below is: # The syntax of the cite command definitions below is:
# LyXName|alias*<!_stardesc!_stardesctooltip>[][]=latexcmd # style@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 # * 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

@ -31,8 +31,9 @@ MaxCiteNames 3
# The syntax of the cite command definitions below is: # The syntax of the cite command definitions below is:
# LyXName|alias*<!_stardesc!_stardesctooltip>[][]=latexcmd # style@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 # * 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

@ -27,8 +27,9 @@ MaxCiteNames 3
# The syntax of the cite command definitions below is: # The syntax of the cite command definitions below is:
# LyXName|alias*<!_stardesc!_stardesctooltip>[][]=latexcmd # style@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 # * 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

@ -24603,9 +24603,74 @@ CiteEngine
\end_layout \end_layout
\begin_layout LyX-Code \begin_layout LyX-Code
\change_inserted -712698321 1720623059
style@
\change_unchanged
LyXName|alias$*<!_stardesc!_stardesctooltip>[][]=latexcmd LyXName|alias$*<!_stardesc!_stardesctooltip>[][]=latexcmd
\end_layout \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@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_layout Itemize
\begin_inset Flex Code \begin_inset Flex Code
status collapsed status collapsed
@ -24713,11 +24778,36 @@ latexcmd
\end_layout \end_layout
\begin_layout Standard \begin_layout Standard
\change_inserted -712698321 1720623197
\begin_inset Flex Code \begin_inset Flex Code
status collapsed status collapsed
\begin_layout Plain Layout \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_layout
\end_inset \end_inset

View File

@ -23456,7 +23456,51 @@ CiteEngine
\end_layout \end_layout
\begin_layout LyX-Code \begin_layout LyX-Code
LyXName|alias$*<!_stardesc!_stardesctooltip>[][]=latexcmd style@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@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 \end_layout
\begin_layout Itemize \begin_layout Itemize
@ -23588,7 +23632,18 @@ latexcmd
status collapsed status collapsed
\begin_layout Plain Layout \begin_layout Plain Layout
Alias Style
\end_layout
\end_inset
,
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
alias
\end_layout \end_layout
\end_inset \end_inset

View File

@ -1569,6 +1569,8 @@ BiblioInfo::CiteStringMap const BiblioInfo::getCiteStrings(
string style; string style;
CiteStringMap csm(styles.size()); CiteStringMap csm(styles.size());
for (size_t i = 0; i != csm.size(); ++i) { 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; style = styles[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

@ -43,6 +43,8 @@ public:
std::string stardesc; std::string stardesc;
/// Optional tooltip for the starred version /// Optional tooltip for the starred version
std::string startooltip; std::string startooltip;
/// Style that supports the command
std::string style;
/// 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

@ -1169,15 +1169,16 @@ bool TextClass::readCiteEngine(Lexer & lexrc, ReadType rt, bool const add)
/** For portability reasons (between different /** For portability reasons (between different
* cite engines such as natbib and biblatex), * cite engines such as natbib and biblatex),
* we distinguish between: * we distinguish between:
* 1. The LyX name as output in the LyX file * 1. The style that features this command
* 2. Possible aliases that might fall back to * 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 * the given LyX name in the current engine
* 3. The actual LaTeX command that is output * 4. The actual LaTeX command that is output
* (2) and (3) are optional. * (1), (3) and (4) are optional.
* Also, the GUI string for the starred version can * Also, the GUI string for the starred version can
* be changed * be changed
* The syntax is: * The syntax is:
* LyXName|alias,nextalias*<!stardesc!stardesctooltip>[][]=latexcmd * style@LyXName|alias,nextalias*<!stardesc!stardesctooltip>[][]=latexcmd
*/ */
enum ScanMode { enum ScanMode {
LyXName, LyXName,
@ -1192,6 +1193,7 @@ bool TextClass::readCiteEngine(Lexer & lexrc, ReadType rt, bool const add)
string alias; string alias;
string latex_cmd; string latex_cmd;
string stardesc; string stardesc;
string style;
size_t const n = def.size(); size_t const n = def.size();
for (size_t i = 0; i != n; ++i) { for (size_t i = 0; i != n; ++i) {
ichar = def[i]; ichar = def[i];
@ -1223,6 +1225,11 @@ bool TextClass::readCiteEngine(Lexer & lexrc, ReadType rt, bool const add)
lyx_cmd += ichar; 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.name = lyx_cmd;
cs.cmd = latex_cmd.empty() ? lyx_cmd : latex_cmd; cs.cmd = latex_cmd.empty() ? lyx_cmd : latex_cmd;
if (!alias.empty()) { if (!alias.empty()) {

View File

@ -1749,6 +1749,8 @@ 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];
if (!ccs.style.empty() && ccs.style != bp.biblatex_citestyle)
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,6 +380,13 @@ 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) {
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; cs = *it;
break; break;
} }