Add support for biblatex-apa's \nptextcite

This commit is contained in:
Juergen Spitzmueller 2024-07-11 10:28:38 +02:00
parent f7cc716861
commit 2dac89aca0
6 changed files with 85 additions and 10 deletions

View File

@ -29,7 +29,8 @@ MaxCiteNames 3
# The syntax of the cite command definitions below is:
# style@LyXName|alias*<!_stardesc!_stardesctooltip>[][]=latexcmd
#
# * style: (Optional) citestyle to which this command is specific.
# * style: A (comma-separated) list of citestyles 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
@ -40,7 +41,7 @@ MaxCiteNames 3
# This is a bit like "ObsoletedBy" in the layouts.
# * latexcmd: The actual LaTeX command that is output.
#
# Alias and latexcmd are optional. If no latexcmd is given, the
# Style, alias and latexcmd are optional. If no latexcmd is given, the
# LyXName will be output to LaTeX.
#
# Note further:

View File

@ -33,7 +33,8 @@ MaxCiteNames 3
# The syntax of the cite command definitions below is:
# style@LyXName|alias*<!_stardesc!_stardesctooltip>[][]=latexcmd
#
# * style: (Optional) citestyle to which this command is specific.
# * style: A (comma-separated) list of citestyles 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
@ -44,7 +45,7 @@ MaxCiteNames 3
# This is a bit like "ObsoletedBy" in the layouts.
# * latexcmd: The actual LaTeX command that is output.
#
# Alias and latexcmd are optional. If no latexcmd is given, the
# Style, alias and latexcmd are optional. If no latexcmd is given, the
# LyXName will be output to LaTeX.
#
# Note further:
@ -81,6 +82,7 @@ MaxCiteNames 3
CiteEngine authoryear
Citet|textcite*[][]
Citep|parencite*[][]
apa,apa6@nptextcite$[][]
Citealt|cite*[][]
Citealp*[][]
Citeauthor*[][]
@ -299,6 +301,11 @@ CiteFormat authoryear
# Fallback style: "Author A (cf. Year),[ and] Author B (Year, p. xx)"
cite %!makecitet%%!textafter%%!close%
# Style-specifics
# 1. APA
# "cf. Author A Year; Author B Year, p. xx"
nptextcite %!textbefore%%!makepcite%%!textafter%
End
CiteFormat numerical

View File

@ -29,7 +29,8 @@ MaxCiteNames 3
# The syntax of the cite command definitions below is:
# style@LyXName|alias*<!_stardesc!_stardesctooltip>[][]=latexcmd
#
# * style: (Optional) citestyle to which this command is specific.
# * style: A (comma-separated) list of citestyles 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
@ -40,7 +41,7 @@ MaxCiteNames 3
# This is a bit like "ObsoletedBy" in the layouts.
# * latexcmd: The actual LaTeX command that is output.
#
# Alias and latexcmd are optional. If no latexcmd is given, the
# Style, alias and latexcmd are optional. If no latexcmd is given, the
# LyXName will be output to LaTeX.
#
# Note further:
@ -75,6 +76,7 @@ CiteEngine authoryear
Cite$|citealt,citealp[][]
Citet$[][]=textcite
Citep$[][]=parencite
apa,apa6@nptextcite$[][]
Citeauthor*<!_citeauthorstar!_citeauthorstartooltip>[][]
citeyearpar[][]=parencite*
citeyear[][]=cite*
@ -285,6 +287,11 @@ CiteFormat authoryear
footcite {%dialog%[[%_footnote%]][[%_foot%]]}: %!textbefore%%!makecite%%!textafter%.
# "Auto: (cf. Author A Year; Author B Year, p. xx)"
autocite {%dialog%[[%_autocite%]][[%_auto%]]}: %!open%%!textbefore%%!makepcite%%!textafter%%!close%
# Style-specifics
# 1. APA
# "cf. Author A Year; Author B Year, p. xx"
nptextcite %!textbefore%%!makepcite%%!textafter%
End
CiteFormat numerical

View File

@ -377,6 +377,64 @@ def revert_biblatex_chicago(document):
document.body[i : j + 1] = put_cmd_in_ert([res])
i = j + 1
def revert_nptextcite(document):
"""Revert \\nptextcite to ERT"""
# 1. Get cite engine
engine = "basic"
i = find_token(document.header, "\\cite_engine", 0)
if i == -1:
document.warning("Malformed document! Missing \\cite_engine")
else:
engine = get_value(document.header, "\\cite_engine", i)
# 2. Do we use biblatex?
if engine != "biblatex" and engine != "biblatex-natbib":
return
# 3. and APA?
cetype = "authoryear"
i = find_token(document.header, "\\biblatex_citestyle", 0)
if i == -1:
return
# 4. Convert \nptextcite to ERT
i = 0
while True:
i = find_token(document.body, "\\begin_inset CommandInset citation", i)
if i == -1:
break
j = find_end_of_inset(document.body, i)
if j == -1:
document.warning("Can't find end of citation inset at line %d!!" % (i))
i += 1
continue
k = find_token(document.body, "LatexCommand", i, j)
if k == -1:
document.warning("Can't find LatexCommand for citation inset at line %d!" % (i))
i = j + 1
continue
cmd = get_value(document.body, "LatexCommand", k)
if cmd == "nptextcite":
pre = get_quoted_value(document.body, "before", i, j)
post = get_quoted_value(document.body, "after", i, j)
key = get_quoted_value(document.body, "key", i, j)
if not key:
document.warning("Citation inset at line %d does not have a key!" % (i))
key = "???"
# Replace known new commands with ERT
res = "\\nptextcite"
if pre:
res += "[" + pre + "]"
if post:
res += "[" + post + "]"
elif pre:
res += "[]"
res += "{" + key + "}"
document.body[i : j + 1] = put_cmd_in_ert([res])
i = j + 1
##
# Conversion hub
#
@ -386,11 +444,13 @@ convert = [
[621, [convert_url_escapes, convert_url_escapes2]],
[622, []],
[623, [convert_he_letter]],
[624, [convert_biblatex_chicago]]
[624, [convert_biblatex_chicago]],
[625, []]
]
revert = [
[624, [revert_nptextcite]],
[623, [revert_biblatex_chicago]],
[622, []],
[621, [revert_glue_parskip]],

View File

@ -215,7 +215,7 @@ char const * const known_biblatex_commands[] = { "cite", "Cite", "textcite", "Te
"parencite", "Parencite", "citeauthor", "Citeauthor", "citeyear", "smartcite", "Smartcite",
"footcite", "Footcite", "autocite", "Autocite", "citetitle", "fullcite", "footfullcite",
"supercite", "cites", "Cites", "textcites", "Textcites", "parencites", "Parencites",
"smartcites", "Smartcites", "autocites", "Autocites", 0 };
"smartcites", "Smartcites", "autocites", "Autocites", "nptextcite", 0 };
/*!
* biblatex-chicago commands.

View File

@ -32,8 +32,8 @@ extern char const * const lyx_version_info;
// Do not remove the comment below, so we get merge conflict in
// independent branches. Instead add your own.
#define LYX_FORMAT_LYX 624 // spitz: support biblatex-chicago
#define LYX_FORMAT_TEX2LYX 624
#define LYX_FORMAT_LYX 625 // spitz: \nptextcite (APA)
#define LYX_FORMAT_TEX2LYX 625
#if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
#ifndef _MSC_VER