[LyX/master] Add support for biblatex-apa's \nptextcite
Juergen Spitzmueller
spitz at lyx.org
Thu Jul 11 08:29:19 UTC 2024
commit 2dac89aca0c1ceed7d029c148aa2a502648cfbb0
Author: Juergen Spitzmueller <spitz at lyx.org>
Date: Thu Jul 11 10:28:38 2024 +0200
Add support for biblatex-apa's \nptextcite
---
lib/citeengines/biblatex-chicago.citeengine | 5 ++-
lib/citeengines/biblatex-natbib.citeengine | 11 ++++-
lib/citeengines/biblatex.citeengine | 11 ++++-
lib/lyx2lyx/lyx_2_5.py | 62 ++++++++++++++++++++++++++++-
src/tex2lyx/text.cpp | 2 +-
src/version.h | 4 +-
6 files changed, 85 insertions(+), 10 deletions(-)
diff --git a/lib/citeengines/biblatex-chicago.citeengine b/lib/citeengines/biblatex-chicago.citeengine
index dbfc2802eb..2a5b8171a1 100644
--- a/lib/citeengines/biblatex-chicago.citeengine
+++ b/lib/citeengines/biblatex-chicago.citeengine
@@ -29,7 +29,8 @@ MaxCiteNames 3
# The syntax of the cite command definitions below is:
# style at 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:
diff --git a/lib/citeengines/biblatex-natbib.citeengine b/lib/citeengines/biblatex-natbib.citeengine
index 78d597ba0c..b0848f5108 100644
--- a/lib/citeengines/biblatex-natbib.citeengine
+++ b/lib/citeengines/biblatex-natbib.citeengine
@@ -33,7 +33,8 @@ MaxCiteNames 3
# The syntax of the cite command definitions below is:
# style at 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 at 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
diff --git a/lib/citeengines/biblatex.citeengine b/lib/citeengines/biblatex.citeengine
index 00b86691fd..c69806d153 100644
--- a/lib/citeengines/biblatex.citeengine
+++ b/lib/citeengines/biblatex.citeengine
@@ -29,7 +29,8 @@ MaxCiteNames 3
# The syntax of the cite command definitions below is:
# style at 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 at 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
diff --git a/lib/lyx2lyx/lyx_2_5.py b/lib/lyx2lyx/lyx_2_5.py
index 2c90d465d0..3550464cae 100644
--- a/lib/lyx2lyx/lyx_2_5.py
+++ b/lib/lyx2lyx/lyx_2_5.py
@@ -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]],
diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp
index 29d5ac73dc..c7c86ffef9 100644
--- a/src/tex2lyx/text.cpp
+++ b/src/tex2lyx/text.cpp
@@ -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.
diff --git a/src/version.h b/src/version.h
index 8cc6144718..5fea4b1464 100644
--- a/src/version.h
+++ b/src/version.h
@@ -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
More information about the lyx-cvs
mailing list